summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/blob.rb1
-rw-r--r--app/models/blob_viewer/csv.rb21
2 files changed, 22 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