Class: Arclight::Viewers::OEmbed
- Inherits:
-
Object
- Object
- Arclight::Viewers::OEmbed
- 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
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
- #attributes_for(resource) ⇒ Object
- #embeddable?(resource) ⇒ Boolean
-
#initialize(document) ⇒ OEmbed
constructor
A new instance of OEmbed.
- #resources ⇒ Object
- #to_partial_path ⇒ Object
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
#document ⇒ Object (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 (resource) { class: 'al-oembed-viewer', 'data-arclight-oembed': true, 'data-arclight-oembed-url': resource.href } end |
#embeddable?(resource) ⇒ Boolean
28 29 30 |
# File 'lib/arclight/viewers/oembed.rb', line 28 def (resource) resource == resources.first && .include?(resource) end |
#resources ⇒ Object
24 25 26 |
# File 'lib/arclight/viewers/oembed.rb', line 24 def resources document.digital_objects end |
#to_partial_path ⇒ Object
37 38 39 |
# File 'lib/arclight/viewers/oembed.rb', line 37 def to_partial_path 'arclight/viewers/_oembed' end |