[go: up one dir, main page]

Design a generic interface for specialized blob rendering

There are several types of blobs for which we want to have specialized rendering. For example:

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.

cc @DouweM @jschatz1