Class: Arclight::Viewers::OEmbed

Inherits:
Object
  • Object
show all
Defined in:
lib/arclight/viewers/oembed.rb

Overview

A class to represent and render an oEmbed viewer. This defines a partial to be rendered and can apply any required logic to help map necessary document attributes for viewer instantiation

This viewer assumes that the resource itself is requestable according the CORS policy of the site. This is because we fetch the resource and look for a link with a type=“application/json+oembed”. Th oEmbed endpoint described with that link tag should be an oEmbed RICH type, and return the viewer HTML in the html key of the JSON response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ OEmbed

Returns a new instance of OEmbed.



20
21
22
# File 'lib/arclight/viewers/oembed.rb', line 20

def initialize(document)
  @document = document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



18
19
20
# File 'lib/arclight/viewers/oembed.rb', line 18

def document
  @document
end

Instance Method Details

#attributes_for(resource) ⇒ Object



32
33
34
35
# File 'lib/arclight/viewers/oembed.rb', line 32

def attributes_for(resource)
  return {} unless embeddable?(resource)
  { class: 'al-oembed-viewer', 'data-arclight-oembed': true, 'data-arclight-oembed-url': resource.href }
end

#embeddable?(resource) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/arclight/viewers/oembed.rb', line 28

def embeddable?(resource)
  resource == resources.first && embeddable_resources.include?(resource)
end

#resourcesObject



24
25
26
# File 'lib/arclight/viewers/oembed.rb', line 24

def resources
  document.digital_objects
end

#to_partial_pathObject



37
38
39
# File 'lib/arclight/viewers/oembed.rb', line 37

def to_partial_path
  'arclight/viewers/_oembed'
end