Skip to content

Commit

Permalink
Allow for exhibit specific manifest URL patterns to be used for our o…
Browse files Browse the repository at this point in the history
…embed tag.

This allows us to configure, on a per exhibit basis, to use a different oEmbed environment.
  • Loading branch information
jkeck authored and camillevilla committed Jan 13, 2018
1 parent 3ef2401 commit 38bae93
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Added support for highlighting matching query terms from full-text content in search results #1030
- Adds Stanford-specific helptext to the add admin/curator form #1040
- Added support for using the exhibit specific manifest URL configuration to configure the SUL Embed environment to be used #1042
### Changed
### Deprecated
### Removed
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/application_helper.rb
Expand Up @@ -45,7 +45,8 @@ def render_viewer_in_context(document, block)
# @param [SolrDocument] document
# @param [Integer] canvas_index
def custom_render_oembed_tag_async(document, canvas_index)
url = document.first(blacklight_config.show.oembed_field)
url = document.exhibit_specific_manifest(current_exhibit.required_viewer.custom_manifest_pattern)
url ||= document.first(blacklight_config.show.oembed_field)

content_tag :div, '', data: { embed_url: blacklight_oembed_engine.embed_url(url: url, canvas_index: canvas_index) }
end
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/oembed_providers.rb
Expand Up @@ -6,4 +6,9 @@
purl_provider << 'http://purl.stanford.edu/*'
purl_provider << 'https://purl.stanford.edu/*'
purl_provider << 'http://searchworks.stanford.edu/*'

purl_uat_provider = OEmbed::Provider.new('http://sul-purl-uat.stanford.edu/embed.{format}?&hide_title=true')
purl_uat_provider << 'https://sul-purl-uat.stanford.edu/*'

OEmbed::Providers.register(purl_provider)
OEmbed::Providers.register(purl_uat_provider)
41 changes: 35 additions & 6 deletions spec/helpers/application_helper_spec.rb
Expand Up @@ -20,13 +20,42 @@
end

describe '#custom_render_oembed_tag_async' do
let(:document) { SolrDocument.new(url_fulltext: ['http://example.com/stuff']) }
context 'when no custom viewer pattern is set' do
let(:document) { SolrDocument.new(url_fulltext: ['http://example.com/stuff']) }

it 'renders a div with embed attribute and canvas index param' do
expect(helper).to receive_messages(blacklight_config: CatalogController.blacklight_config)
rendered = helper.custom_render_oembed_tag_async(document, 3)
expect(rendered).to have_css '[data-embed-url="http://test.host/oembed/e'\
'mbed?canvas_index=3&url=http%3A%2F%2Fexample.com%2Fstuff"]'
it 'renders a div with embed attribute and canvas index param' do
expect(helper).to receive_messages(
blacklight_config: CatalogController.blacklight_config,
current_exhibit: create(:exhibit)
)
rendered = helper.custom_render_oembed_tag_async(document, 3)
expect(rendered).to have_css '[data-embed-url="http://test.host/oembed/e'\
'mbed?canvas_index=3&url=http%3A%2F%2Fexample.com%2Fstuff"]'
end
end

context 'when a custom viewer pattern is provided' do
let(:document) do
SolrDocument.new(
id: 'abc123',
url_fulltext: ['http://example.com/stuff'],
content_metadata_type_ssm: ['image'],
iiif_manifest_url_ssi: 'htts://example.com/info.json'
)
end

it 'uses a custom manifest pattern if set' do
expect(helper).to receive_messages(
current_exhibit: create(
:exhibit,
viewer: create(:viewer, custom_manifest_pattern: 'https://embed-example.com/{id}')
)
)
rendered = helper.custom_render_oembed_tag_async(document, 1)

expect(rendered).to have_css '[data-embed-url="http://test.host/oembed/e'\
'mbed?canvas_index=1&url=https%3A%2F%2Fembed-example.com%2Fabc123"]'
end
end
end

Expand Down

0 comments on commit 38bae93

Please sign in to comment.