summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/blob.rb1
-rw-r--r--app/models/blob_viewer/csv.rb21
-rw-r--r--app/views/projects/blob/viewers/_csv.html.haml8
3 files changed, 30 insertions, 0 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb
index 19ad110db58..3e4e62f96f9 100644
--- a/app/models/blob.rb
+++ b/app/models/blob.rb
@@ -20,6 +20,7 @@ class Blob < SimpleDelegator
# type. LFS pointers to `.stl` files are assumed to always be the binary kind,
# and use the `BinarySTL` viewer.
RICH_VIEWERS = [
+ BlobViewer::CSV,
BlobViewer::Markup,
BlobViewer::Notebook,
BlobViewer::SVG,
diff --git a/app/models/blob_viewer/csv.rb b/app/models/blob_viewer/csv.rb
new file mode 100644
index 00000000000..c26900c4d35
--- /dev/null
+++ b/app/models/blob_viewer/csv.rb
@@ -0,0 +1,21 @@
+require 'csv'
+
+module BlobViewer
+ class CSV < Base
+ include ServerSide
+
+ self.binary = false
+ self.extensions = %w(csv)
+ self.partial_name = 'csv'
+ self.switcher_icon = 'file-excel-o'
+ self.type = :rich
+
+ def parse(&block)
+ begin
+ ::CSV.parse(blob.data).each_with_index(&block)
+ rescue ::CSV::MalformedCSVError => ex
+ # TODO (rspeicher): How do we want to handle this?
+ end
+ end
+ end
+end
diff --git a/app/views/projects/blob/viewers/_csv.html.haml b/app/views/projects/blob/viewers/_csv.html.haml
new file mode 100644
index 00000000000..400f2cccc3d
--- /dev/null
+++ b/app/views/projects/blob/viewers/_csv.html.haml
@@ -0,0 +1,8 @@
+%table.table-striped.table-bordered
+ - viewer.parse do |row, index|
+ %tr
+ - row.each do |column|
+ - if index == 0
+ %th= column
+ - else
+ %td= column