Design a generic interface for specialized blob rendering
There are several types of blobs for which we want to have specialized rendering. For example:
- CSV files can be viewed as a table or as raw (unhighlighted) text - https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7325
- GeoJSON files can be viewed as a map or as raw (highlighted) JSON - https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5126
- Markdown files should be viewable as rendered HTML and as highlighted text
- PDF files should be previewable: https://gitlab.com/gitlab-org/gitlab-ce/issues/19360
We need a generic way to handle these specialized renderings, and also a UI element for switching between the two. It should be simple to add new specialized handlers.
There are cases where we don't render "both" views (such as PDFs) so it should account for that as well.
Rough idea of specialized handlers:
class GeoJsonBlob
def rendered_view?
true
end
def rendered_line_numbers?
false
end
def raw_view?
true
end
def raw_line_numbers?
true
end
def rendered_view(blob)
# Read the blob content and pass it to Leaflet.js or whatever
end
def raw_view(blob)
# Highlight the blob content as JSON
end
end
class CsvBlob
def rendered_view?
true
end
def rendered_line_numbers?
true
end
def raw_view?
true
end
def raw_line_numbers?
true
end
def rendered_view(blob)
# Read the blob content and parse it as CSV
# Render it as a table... somehow.
end
def raw_view(blob)
# Return the blob content
end
end
Obviously we'd want some common ancestor or interface. It could possibly even be the Blob
model.