Commit 49adde69 authored by Robert Speicher's avatar Robert Speicher
Browse files

Add a CSV blob view handler

parent 5b880f0d
......@@ -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,
......
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
%table.table-striped.table-bordered
- viewer.parse do |row, index|
%tr
- row.each do |column|
- if index == 0
%th= column
- else
%td= column
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment