Skip to content

Digital Object Viewers

Jessie Keck edited this page May 26, 2017 · 5 revisions

Arclight provides the ability for a downstream application to configure their own digital object viewer to be displayed on record pages.

Default Viewer

The default/reference implementation is a simple oEmbed based viewer. This viewer works by checking for link[rel="alternate"] tags in the document with a type of type of application/json+oembed [1]. The url referenced in that link will then be requested, and the html described in the oEmbed rich-type response will be injected into the document page. The oEmbed implementation that ships with Arclight can be configured to exclude certain url patterns that will be known to not contain oEmbed responses (e.g. PDF or PowerPoint) [2].

Configuring Your Own Viewer

A downstream application can configure their own class to handle a local viewer implementation. This can be accomplished by changing the Arclight::Engine.config.viewer_class in an initializer.

The Viewer Configuration

# config/initializers/configure_arclight_viewer.rb

Arclight::Engine.config.viewer_class = MyApplicationViewer

The Viewer Class

This class will be initialized with the SolrDocument and must implement to_partial_path that references the path to a partial to render for that object.

class MyApplicationViewer
  def initialize(document)
    @document = document
  end

  def to_partial_path
    'viewers/_my_viewer'
  end
end

This is where you can add logic about how to get at the necessary data from your document to render a viewer. A very simple example would be if you parsed out an image url that was defined in the EAD into a solr field in your indexing logic [3]. You could add a method to your viewer like:

class MyApplicationViewer
  ...
  def images
    @document.fetch(:image_urls_ssim, [])
  end
  ...
end

The Partial

The partial will receive an instance of viewer class as a local so any accessors/methods you add to your viewer class will available to your view.

<% # app/views/viewers/_my_viewer.html.erb %>
<% viewer.images.each do |image| %>
  <%= image_tag(image) %>
<% end %>
Notes
  1. This requires that the resource has CORS enabled.
  2. All resources that are not CORS enabled will fail the pre-flight check, and won't have the full contents requested either.
  3. Arclight provides a digital_objects method on the SolrDocument model that already gathers the dao data for you that will most likely be used in place of fetching fields directly out of the index as is in this example.