blacklight-oembed 1.1.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +15 -7
- data/.solr_wrapper.yml +6 -0
- data/app/assets/javascripts/blacklight_oembed/oembed.js +31 -0
- data/app/components/blacklight/oembed/document_oembed_component.html.erb +3 -0
- data/app/components/blacklight/oembed/document_oembed_component.rb +60 -0
- data/app/controllers/blacklight/oembed/embed_controller.rb +1 -1
- data/app/helpers/blacklight/oembed/oembed_helper.rb +15 -12
- data/app/views/catalog/_oembed_default.html.erb +1 -5
- data/blacklight-oembed.gemspec +1 -1
- data/lib/blacklight/oembed/engine.rb +3 -3
- data/lib/blacklight/oembed/version.rb +1 -1
- data/lib/blacklight/oembed.rb +5 -1
- data/lib/generators/blacklight_oembed/install_generator.rb +13 -4
- data/lib/generators/blacklight_oembed/templates/blacklight_oembed.js +3 -3
- data/package.json +23 -0
- data/spec/controllers/embed_controller_spec.rb +1 -2
- data/spec/features/embed_spec.rb +17 -0
- metadata +12 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca622e6493231613d2e1e8709cd59bdd5b092102e8add584aa8729cc62dafd92
|
4
|
+
data.tar.gz: 71350e1b92d7bda34dbd15a9da041c6320d1fe722920e29d72517f3e58774fc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e275f3324443f7120656aba199c6da9ee87d175ac00248122a3b75938a1152a22cdc371c30e31fc38f1ab548c376d17b795d5dc62c2ee73065937a23fe460d4a
|
7
|
+
data.tar.gz: 6b5d7d3b20aaa33894e1e30830032e25565e78004af528e09f6ee7ba60f0652a255e7d60125840f79354563a79b13d865755ce8980a96f7beedad136669c2c9d
|
data/.github/workflows/ruby.yml
CHANGED
@@ -9,20 +9,28 @@ on:
|
|
9
9
|
jobs:
|
10
10
|
test:
|
11
11
|
runs-on: ubuntu-latest
|
12
|
+
name: test (ruby ${{ matrix.ruby }} / rails ${{ matrix.rails_version }} / blacklight ${{ matrix.blacklight_version }} ${{ matrix.additional_name }})
|
12
13
|
strategy:
|
13
14
|
matrix:
|
14
|
-
ruby: [
|
15
|
-
rails_version: ['
|
15
|
+
ruby: ['3.3']
|
16
|
+
rails_version: ['7.1.4', '7.2.1']
|
16
17
|
blacklight_version: ['~> 7.0']
|
18
|
+
additional_name: ['']
|
19
|
+
legacy_config: ['']
|
17
20
|
include:
|
18
|
-
- ruby: '3.
|
19
|
-
rails_version: '7.
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
- ruby: '3.3'
|
22
|
+
rails_version: '7.2.1'
|
23
|
+
blacklight_version: '~> 8.0'
|
24
|
+
additional_name: ''
|
25
|
+
- ruby: '3.3'
|
26
|
+
rails_version: '7.2.1'
|
27
|
+
blacklight_version: '~> 8.0'
|
28
|
+
additional_name: 'with legacy partial config'
|
29
|
+
legacy_config: 'true'
|
23
30
|
env:
|
24
31
|
RAILS_VERSION: ${{ matrix.rails_version }}
|
25
32
|
BLACKLIGHT_VERSION: ${{ matrix.blacklight_version }}
|
33
|
+
CI_TEST_LEGACY_CONFIGURATION: ${{ matrix.legacy_config }}
|
26
34
|
steps:
|
27
35
|
- uses: actions/checkout@v2
|
28
36
|
- name: Set up Ruby ${{ matrix.ruby }}
|
data/.solr_wrapper.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
export default function oEmbed(elements) {
|
2
|
+
if (!elements) return;
|
3
|
+
|
4
|
+
// Ensure elements is an array-like collection
|
5
|
+
elements = elements instanceof NodeList ? Array.from(elements) : [elements];
|
6
|
+
|
7
|
+
elements.forEach(function(embedViewer) {
|
8
|
+
const embedURL = embedViewer.dataset.embedUrl; // Get the embed URL from the data attribute
|
9
|
+
|
10
|
+
if (!embedURL) return;
|
11
|
+
|
12
|
+
// Fetch JSON data from the embed URL
|
13
|
+
fetch(embedURL)
|
14
|
+
.then(response => {
|
15
|
+
if (!response.ok) {
|
16
|
+
throw new Error('Network response was not ok');
|
17
|
+
}
|
18
|
+
return response.json();
|
19
|
+
})
|
20
|
+
.then(data => {
|
21
|
+
if (data === null) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
// Set the inner HTML of the element
|
25
|
+
embedViewer.innerHTML = data.html;
|
26
|
+
})
|
27
|
+
.catch(error => {
|
28
|
+
console.error('Error fetching embed data:', error);
|
29
|
+
});
|
30
|
+
});
|
31
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Blacklight
|
2
|
+
module Oembed
|
3
|
+
class DocumentOembedComponent < Blacklight::Component
|
4
|
+
attr_reader :document, :presenter, :classes
|
5
|
+
|
6
|
+
def initialize(document:, presenter:, classes: ['oembed-widget'], **kwargs)
|
7
|
+
super
|
8
|
+
|
9
|
+
@document = document
|
10
|
+
@presenter = presenter
|
11
|
+
@classes = classes
|
12
|
+
end
|
13
|
+
|
14
|
+
def embed
|
15
|
+
return if embed_url.blank?
|
16
|
+
|
17
|
+
@embed ||= if Blacklight::Oembed::Engine.config.render_helper != :render_oembed_tag_async && Blacklight::Oembed::Engine.config.render_helper != :render_oembed_tag_embed
|
18
|
+
legacy_helper_method_embed_markup
|
19
|
+
elsif view_config.render_oembed_using_async_javascript || Blacklight::Oembed::Engine.config.render_helper == :render_oembed_tag_async
|
20
|
+
async_embed_markup
|
21
|
+
else
|
22
|
+
inline_embed_markup
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def render?
|
27
|
+
embed.present?
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def view_config
|
33
|
+
presenter.view_config
|
34
|
+
end
|
35
|
+
|
36
|
+
def embed_url
|
37
|
+
document.first(view_config.oembed_field)
|
38
|
+
end
|
39
|
+
|
40
|
+
def async_embed_url(**kwargs)
|
41
|
+
helpers.blacklight_oembed_engine.embed_url(**kwargs)
|
42
|
+
end
|
43
|
+
|
44
|
+
def async_embed_markup
|
45
|
+
content_tag :div, '', data: { async_embed_url: async_embed_url(url: embed_url) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def inline_embed_markup
|
49
|
+
OEmbed::Providers.get(embed_url).html.html_safe
|
50
|
+
rescue OEmbed::NotFound
|
51
|
+
link_to t(:'blacklight_oembed.catalog.view'), embed_url
|
52
|
+
end
|
53
|
+
|
54
|
+
def legacy_helper_method_embed_markup
|
55
|
+
Blacklight::Oembed.deprecator.warn('Subclass Blacklight::Oembed::DocumentOembedComponent instead of using the blacklight-oembed render_helper config')
|
56
|
+
helpers.call(Blacklight::Oembed::Engine.config.render_helper, url)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -7,7 +7,7 @@ module Blacklight::Oembed
|
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
|
10
|
+
def get_embed_content(url, add_params = {})
|
11
11
|
begin
|
12
12
|
OEmbed::Providers.get(url, add_params.transform_values { |v| CGI.escape(v) }).html.html_safe
|
13
13
|
rescue OEmbed::NotFound
|
@@ -1,28 +1,31 @@
|
|
1
1
|
module Blacklight::Oembed
|
2
2
|
module OembedHelper
|
3
|
-
|
4
|
-
def render_oembed_solr_document_tag
|
3
|
+
# @deprecated
|
4
|
+
def render_oembed_solr_document_tag(document)
|
5
5
|
url = document.first(blacklight_config.show.oembed_field)
|
6
6
|
return if url.blank?
|
7
7
|
|
8
8
|
render_oembed_tag url
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
# @deprecated
|
12
|
+
def render_oembed_tag(url)
|
12
13
|
send Blacklight::Oembed::Engine.config.render_helper, url
|
13
14
|
end
|
15
|
+
Blacklight::Oembed.deprecator.deprecate_methods Blacklight::Oembed::OembedHelper,
|
16
|
+
:render_oembed_solr_document_tag, :render_oembed_tag,
|
17
|
+
'Use Blacklight::Oembed::DocumentOembedComponent instead'
|
14
18
|
|
15
19
|
private
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
20
|
+
|
21
|
+
def render_oembed_tag_embed(url)
|
22
|
+
OEmbed::Providers.get(url).html.html_safe
|
23
|
+
rescue OEmbed::NotFound
|
24
|
+
link_to t(:'blacklight_oembed.catalog.view'), url
|
22
25
|
end
|
23
26
|
|
24
|
-
def render_oembed_tag_async
|
25
|
-
content_tag :div,
|
27
|
+
def render_oembed_tag_async(url)
|
28
|
+
content_tag :div, '', data: { embed_url: blacklight_oembed_engine.embed_url(url: url) }
|
26
29
|
end
|
27
30
|
end
|
28
|
-
end
|
31
|
+
end
|
data/blacklight-oembed.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
20
|
spec.add_dependency "rails"
|
21
|
-
spec.add_dependency 'blacklight', '>= 7.
|
21
|
+
spec.add_dependency 'blacklight', '>= 7.25', '< 9'
|
22
22
|
spec.add_dependency "ruby-oembed"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", ">= 1.5"
|
@@ -3,13 +3,13 @@ require 'blacklight'
|
|
3
3
|
module Blacklight
|
4
4
|
module Oembed
|
5
5
|
class Engine < Rails::Engine
|
6
|
+
# @deprecated
|
7
|
+
config.render_helper = :render_oembed_tag_async
|
6
8
|
|
7
|
-
Blacklight::Oembed::Engine.config.render_helper = :render_oembed_tag_async
|
8
9
|
##
|
9
10
|
# Allows an adopter to pass additional parameters through to an OEmbed
|
10
11
|
# service. Examples of this could include `:canvas_index`, or `:max_width`
|
11
|
-
|
12
|
-
|
12
|
+
config.additional_params = []
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/blacklight/oembed.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'blacklight/oembed/version'
|
2
2
|
require 'oembed'
|
3
3
|
module Blacklight
|
4
4
|
module Oembed
|
5
|
+
def self.deprecator
|
6
|
+
@deprecator ||= ActiveSupport::Deprecation.new('2.0.0', 'blacklight-oembed')
|
7
|
+
end
|
8
|
+
|
5
9
|
require 'blacklight/oembed/engine'
|
6
10
|
end
|
7
11
|
end
|
@@ -19,12 +19,21 @@ module BlacklightOembed
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def configuration
|
22
|
-
inject_into_file 'app/controllers/catalog_controller.rb', after:
|
23
|
-
|
22
|
+
inject_into_file 'app/controllers/catalog_controller.rb', after: 'configure_blacklight do |config|' do
|
23
|
+
if ENV['CI_TEST_LEGACY_CONFIGURATION'].present? || Gem::Version.new(Blacklight::VERSION) < Gem::Version.new('8.0')
|
24
|
+
<<-EOF
|
25
|
+
|
26
|
+
config.show.oembed_field = :oembed_url_ssm
|
27
|
+
config.show.partials.insert(1, :oembed)
|
28
|
+
EOF
|
29
|
+
else
|
30
|
+
<<-EOF
|
24
31
|
|
25
32
|
config.show.oembed_field = :oembed_url_ssm
|
26
|
-
config.show.
|
27
|
-
|
33
|
+
config.show.render_oembed_using_async_javascript = true
|
34
|
+
config.show.embed_component = Blacklight::Oembed::DocumentOembedComponent
|
35
|
+
EOF
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
end
|
data/package.json
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"name": "blacklight-oembed",
|
3
|
+
"version": "1.3.0",
|
4
|
+
"description": "Oembed behavior for Blacklight",
|
5
|
+
"main": "app/assets/javascripts/blacklight_oembed/oembed.js",
|
6
|
+
"files": [
|
7
|
+
"app/assets/javascripts/blacklight_oembed/*.js"
|
8
|
+
],
|
9
|
+
"scripts": {
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
11
|
+
},
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "git+https://github.com/projectblacklight/blacklight-oembed.git"
|
15
|
+
},
|
16
|
+
"author": "Chris Beer, Justin Coyne, et al.",
|
17
|
+
"license": "Apache-2.0",
|
18
|
+
"bugs": {
|
19
|
+
"url": "https://github.com/projectblacklight/blacklight-oembed/issues"
|
20
|
+
},
|
21
|
+
"homepage": "https://github.com/projectblacklight/blacklight-oembed#readme",
|
22
|
+
"dependencies": {}
|
23
|
+
}
|
@@ -7,8 +7,7 @@ describe Blacklight::Oembed::EmbedController do
|
|
7
7
|
render_views
|
8
8
|
|
9
9
|
before do
|
10
|
-
Blacklight::Oembed::Engine.config.
|
11
|
-
Blacklight::Oembed::Engine.config.additional_params = [:canvas_index, :suggested_search]
|
10
|
+
Blacklight::Oembed::Engine.config.additional_params = %i[canvas_index suggested_search]
|
12
11
|
end
|
13
12
|
|
14
13
|
let :oembed_obj do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Embed', type: :feature do
|
4
|
+
before do
|
5
|
+
CatalogController.blacklight_config.show.oembed_field = :id
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'embeds the widget on the show page' do
|
9
|
+
visit '/catalog/2007020969'
|
10
|
+
|
11
|
+
expect(page).to have_css '.oembed-widget'
|
12
|
+
|
13
|
+
embed_div = find('.oembed-widget div')
|
14
|
+
|
15
|
+
expect(embed_div['data-async-embed-url']).to include '/oembed/embed?url=2007020969'
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight-oembed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '7.
|
33
|
+
version: '7.25'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '9'
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '7.
|
43
|
+
version: '7.25'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '9'
|
@@ -207,11 +207,15 @@ extra_rdoc_files: []
|
|
207
207
|
files:
|
208
208
|
- ".github/workflows/ruby.yml"
|
209
209
|
- ".gitignore"
|
210
|
+
- ".solr_wrapper.yml"
|
210
211
|
- Gemfile
|
211
212
|
- LICENSE
|
212
213
|
- README.md
|
213
214
|
- Rakefile
|
214
215
|
- app/assets/javascripts/blacklight_oembed/jquery.oembed.js
|
216
|
+
- app/assets/javascripts/blacklight_oembed/oembed.js
|
217
|
+
- app/components/blacklight/oembed/document_oembed_component.html.erb
|
218
|
+
- app/components/blacklight/oembed/document_oembed_component.rb
|
215
219
|
- app/controllers/blacklight/oembed/embed_controller.rb
|
216
220
|
- app/helpers/blacklight/oembed/oembed_helper.rb
|
217
221
|
- app/views/catalog/_oembed_default.html.erb
|
@@ -227,6 +231,7 @@ files:
|
|
227
231
|
- lib/generators/blacklight_oembed/templates/blacklight_oembed.css.scss
|
228
232
|
- lib/generators/blacklight_oembed/templates/blacklight_oembed.js
|
229
233
|
- lib/generators/blacklight_oembed/templates/oembed_providers.rb
|
234
|
+
- package.json
|
230
235
|
- solr/conf/_rest_managed.json
|
231
236
|
- solr/conf/admin-extra.html
|
232
237
|
- solr/conf/elevate.xml
|
@@ -245,6 +250,7 @@ files:
|
|
245
250
|
- solr/conf/xslt/luke.xsl
|
246
251
|
- solr/sample_solr_documents.yml
|
247
252
|
- spec/controllers/embed_controller_spec.rb
|
253
|
+
- spec/features/embed_spec.rb
|
248
254
|
- spec/helpers/oembed_helper_spec.rb
|
249
255
|
- spec/spec_helper.rb
|
250
256
|
- spec/test_app_templates/Gemfile.extra
|
@@ -268,12 +274,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
274
|
- !ruby/object:Gem::Version
|
269
275
|
version: '0'
|
270
276
|
requirements: []
|
271
|
-
rubygems_version: 3.
|
277
|
+
rubygems_version: 3.5.23
|
272
278
|
signing_key:
|
273
279
|
specification_version: 4
|
274
280
|
summary: Oembed display for Blacklight
|
275
281
|
test_files:
|
276
282
|
- spec/controllers/embed_controller_spec.rb
|
283
|
+
- spec/features/embed_spec.rb
|
277
284
|
- spec/helpers/oembed_helper_spec.rb
|
278
285
|
- spec/spec_helper.rb
|
279
286
|
- spec/test_app_templates/Gemfile.extra
|