arclight 1.0.0.beta1 → 1.0.0.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/app/assets/javascripts/arclight/arclight.js +2 -2
- data/app/assets/javascripts/arclight/oembed_controller.js +55 -0
- data/app/components/arclight/oembed_viewer_component.html.erb +1 -1
- data/app/components/arclight/search_result_component.rb +0 -6
- data/lib/arclight/engine.rb +1 -1
- data/lib/arclight/version.rb +1 -1
- data/lib/generators/arclight/install_generator.rb +2 -4
- data/lib/generators/arclight/templates/arclight.scss +1 -0
- data/package.json +1 -1
- metadata +5 -5
- data/app/assets/javascripts/arclight/oembed_viewer.js +0 -71
- /data/app/assets/images/{blacklight → arclight}/logo.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7013a9e0dc84a12fb9b6ed9e54e691c69153105e776dfadcc20c2f4aad877ec
|
4
|
+
data.tar.gz: a582750f5f80679ee4aaf7004bf0c30487f1f1c517c5738b509990597024636f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1934764433941e5bd519c1ac95646109b766fc36df6826fb273d285f0abbc6a3de6b3d58a2f7cd321c0edbbe402d03eef257f63dcf890508c2f1ac9a53104910
|
7
|
+
data.tar.gz: fca59f728f58b919dfabb27f37bf1190e6513680e29cb6ddd55ef5f9fe5c622b7d35657076a7e3beef5d0d1b8d3b828cce7411d6452745ae9560a14e3a142934
|
data/.github/workflows/ruby.yml
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
2
|
+
|
3
|
+
export default class OembedController extends Controller {
|
4
|
+
static values = {
|
5
|
+
url: String
|
6
|
+
}
|
7
|
+
|
8
|
+
connect() {
|
9
|
+
const loadedAttr = this.element.getAttribute('loaded')
|
10
|
+
|
11
|
+
if (loadedAttr && loadedAttr === 'loaded') {
|
12
|
+
return
|
13
|
+
}
|
14
|
+
|
15
|
+
fetch(this.urlValue)
|
16
|
+
.then((response) => {
|
17
|
+
if (response.ok) return response.text()
|
18
|
+
throw new Error(`HTTP error, status = ${response.status}`)
|
19
|
+
})
|
20
|
+
.then((body) => {
|
21
|
+
const oEmbedEndPoint = OembedController.findOEmbedEndPoint(body)
|
22
|
+
if (!oEmbedEndPoint || oEmbedEndPoint.length === 0) {
|
23
|
+
console.warn(`No oEmbed endpoint found in <head> at ${this.urlValue}`)
|
24
|
+
return
|
25
|
+
}
|
26
|
+
this.loadEndPoint(oEmbedEndPoint)
|
27
|
+
}).catch(error => {
|
28
|
+
console.error(error)
|
29
|
+
})
|
30
|
+
}
|
31
|
+
|
32
|
+
static findOEmbedEndPoint(body, extraParams = {}) {
|
33
|
+
// Parse out link elements so image assets are not loaded
|
34
|
+
const template = document.createElement('template')
|
35
|
+
template.innerHTML = body.match(/<link .*>/g).join('')
|
36
|
+
|
37
|
+
// Look for a link element containing the oEmbed endpoint; bail out if none
|
38
|
+
const endpoint = template.content.querySelector('link[rel="alternate"][type="application/json+oembed"]')
|
39
|
+
?.getAttribute('href')
|
40
|
+
if (!endpoint) return ''
|
41
|
+
|
42
|
+
// Serialize any extra params and append them to the endpoint
|
43
|
+
const qs = new URLSearchParams(extraParams).toString()
|
44
|
+
return `${endpoint}&${qs}`
|
45
|
+
}
|
46
|
+
|
47
|
+
loadEndPoint(oEmbedEndPoint) {
|
48
|
+
fetch(oEmbedEndPoint)
|
49
|
+
.then((response) => response.json())
|
50
|
+
.then((json) => {
|
51
|
+
this.element.innerHTML = json.html
|
52
|
+
this.element.setAttribute('loaded', 'loaded')
|
53
|
+
})
|
54
|
+
}
|
55
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= tag.div(class: 'al-oembed-viewer',
|
1
|
+
<%= tag.div(class: 'al-oembed-viewer', data: { controller: 'arclight-oembed', arclight_oembed_url_value: @resource.href }) do %>
|
2
2
|
<div class="al-digital-object">
|
3
3
|
<%= link_to(@resource.label, @resource.href) %>
|
4
4
|
</div>
|
@@ -7,12 +7,6 @@ module Arclight
|
|
7
7
|
class SearchResultComponent < Blacklight::DocumentComponent
|
8
8
|
attr_reader :document
|
9
9
|
|
10
|
-
# We need to initialize the view component counter variable
|
11
|
-
# See https://viewcomponent.org/guide/collections.html#collection-counter
|
12
|
-
def initialize(search_result_counter: nil, **kwargs)
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
10
|
def compact?
|
17
11
|
presenter.view_config.key.to_s == 'compact'
|
18
12
|
end
|
data/lib/arclight/engine.rb
CHANGED
@@ -36,7 +36,7 @@ module Arclight
|
|
36
36
|
|
37
37
|
initializer 'arclight.assets', before: 'assets' do |app|
|
38
38
|
app.config.assets.precompile << 'arclight/arclight.js'
|
39
|
-
app.config.assets.precompile << 'arclight/
|
39
|
+
app.config.assets.precompile << 'arclight/oembed_controller.js'
|
40
40
|
app.config.assets.precompile << 'arclight/truncate_controller.js'
|
41
41
|
end
|
42
42
|
|
data/lib/arclight/version.rb
CHANGED
@@ -114,15 +114,13 @@ module Arclight
|
|
114
114
|
append_to_file 'config/importmap.rb', <<~RUBY
|
115
115
|
pin "arclight", to: "arclight/arclight.js"
|
116
116
|
# TODO: We may be able to move these to a single importmap for arclight.
|
117
|
-
pin "arclight/
|
117
|
+
pin "arclight/oembed_controller", to: "arclight/oembed_controller.js"
|
118
118
|
pin "arclight/truncate_controller", to: "arclight/truncate_controller.js"
|
119
119
|
RUBY
|
120
120
|
end
|
121
121
|
|
122
122
|
def import_arclight_javascript
|
123
|
-
|
124
|
-
"\nimport \"arclight\""
|
125
|
-
end
|
123
|
+
append_to_file 'app/javascript/application.js', "\nimport \"arclight\""
|
126
124
|
end
|
127
125
|
end
|
128
126
|
end
|
data/package.json
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arclight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darren Hardy
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2023-02-
|
14
|
+
date: 2023-02-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: blacklight
|
@@ -310,6 +310,7 @@ files:
|
|
310
310
|
- LICENSE.txt
|
311
311
|
- README.md
|
312
312
|
- Rakefile
|
313
|
+
- app/assets/images/arclight/logo.png
|
313
314
|
- app/assets/images/blacklight/bookmark.svg
|
314
315
|
- app/assets/images/blacklight/collection.svg
|
315
316
|
- app/assets/images/blacklight/compact.svg
|
@@ -318,14 +319,13 @@ files:
|
|
318
319
|
- app/assets/images/blacklight/file.svg
|
319
320
|
- app/assets/images/blacklight/folder.svg
|
320
321
|
- app/assets/images/blacklight/list.svg
|
321
|
-
- app/assets/images/blacklight/logo.png
|
322
322
|
- app/assets/images/blacklight/minus.svg
|
323
323
|
- app/assets/images/blacklight/online.svg
|
324
324
|
- app/assets/images/blacklight/pdf.svg
|
325
325
|
- app/assets/images/blacklight/plus.svg
|
326
326
|
- app/assets/images/blacklight/repository.svg
|
327
327
|
- app/assets/javascripts/arclight/arclight.js
|
328
|
-
- app/assets/javascripts/arclight/
|
328
|
+
- app/assets/javascripts/arclight/oembed_controller.js
|
329
329
|
- app/assets/javascripts/arclight/truncate_controller.js
|
330
330
|
- app/assets/stylesheets/arclight/application.scss
|
331
331
|
- app/assets/stylesheets/arclight/modules/collection_search.scss
|
@@ -512,7 +512,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
512
512
|
- !ruby/object:Gem::Version
|
513
513
|
version: 1.3.1
|
514
514
|
requirements: []
|
515
|
-
rubygems_version: 3.3.
|
515
|
+
rubygems_version: 3.3.26
|
516
516
|
signing_key:
|
517
517
|
specification_version: 4
|
518
518
|
summary: ''
|
@@ -1,71 +0,0 @@
|
|
1
|
-
class OembedLoader {
|
2
|
-
constructor(el) {
|
3
|
-
this.el = el
|
4
|
-
}
|
5
|
-
|
6
|
-
load() {
|
7
|
-
const loadedAttr = this.el.getAttribute('loaded')
|
8
|
-
const { arclightOembed, arclightOembedUrl, ...extraOembedParams } = this.el.dataset
|
9
|
-
const extraParams = OembedLoader.normalizeParams(extraOembedParams)
|
10
|
-
|
11
|
-
if (loadedAttr && loadedAttr === 'loaded') {
|
12
|
-
return
|
13
|
-
}
|
14
|
-
|
15
|
-
fetch(arclightOembedUrl)
|
16
|
-
.then((response) => response.text())
|
17
|
-
.then((body) => {
|
18
|
-
const oEmbedEndPoint = OembedLoader.findOEmbedEndPoint(body, extraParams)
|
19
|
-
if (!oEmbedEndPoint || oEmbedEndPoint.length === 0) {
|
20
|
-
console.warn(`No oEmbed endpoint found in <head> at ${arclightOembedUrl}`)
|
21
|
-
return
|
22
|
-
}
|
23
|
-
this.loadEndPoint(oEmbedEndPoint)
|
24
|
-
})
|
25
|
-
}
|
26
|
-
|
27
|
-
// Convert data-arclight-oembed-* attributes to URL parameters for the viewer
|
28
|
-
static normalizeParams(attributes) {
|
29
|
-
return Object.keys(attributes).reduce((acc, attribute) => {
|
30
|
-
// Reverse data attribute name conversion. See:
|
31
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset#name_conversion
|
32
|
-
const parameterName = attribute.replace('arclightOembed', '')
|
33
|
-
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
34
|
-
.toLowerCase()
|
35
|
-
|
36
|
-
acc[parameterName] = attributes[attribute]
|
37
|
-
return acc
|
38
|
-
}, {})
|
39
|
-
}
|
40
|
-
|
41
|
-
static findOEmbedEndPoint(body, extraParams = {}) {
|
42
|
-
// Parse out link elements so image assets are not loaded
|
43
|
-
const template = document.createElement('template')
|
44
|
-
template.innerHTML = body.match(/<link .*>/g).join('')
|
45
|
-
|
46
|
-
// Look for a link element containing the oEmbed endpoint; bail out if none
|
47
|
-
const endpoint = template.content.querySelector('link[rel="alternate"][type="application/json+oembed"]')
|
48
|
-
?.getAttribute('href')
|
49
|
-
if (!endpoint) return ''
|
50
|
-
|
51
|
-
// Serialize any extra params and append them to the endpoint
|
52
|
-
const qs = new URLSearchParams(extraParams).toString()
|
53
|
-
return `${endpoint}&${qs}`
|
54
|
-
}
|
55
|
-
|
56
|
-
loadEndPoint(oEmbedEndPoint) {
|
57
|
-
fetch(oEmbedEndPoint)
|
58
|
-
.then((response) => response.json())
|
59
|
-
.then((json) => {
|
60
|
-
this.el.innerHTML = json.html
|
61
|
-
this.el.setAttribute('loaded', 'loaded')
|
62
|
-
})
|
63
|
-
}
|
64
|
-
}
|
65
|
-
|
66
|
-
Blacklight.onLoad(function () {
|
67
|
-
document.querySelectorAll('[data-arclight-oembed="true"]').forEach((element) => {
|
68
|
-
const loader = new OembedLoader(element)
|
69
|
-
loader.load()
|
70
|
-
})
|
71
|
-
})
|
File without changes
|