arclight 1.0.0.beta1 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1145e9c396f3fb41357ffc7d8e4139e47973369de6d17bc71e2d8b17696bfbb9
4
- data.tar.gz: '0329f7cb492c8e02b4ce48417acaafc291a9db5d7413855e699f1c16d975ef98'
3
+ metadata.gz: e7013a9e0dc84a12fb9b6ed9e54e691c69153105e776dfadcc20c2f4aad877ec
4
+ data.tar.gz: a582750f5f80679ee4aaf7004bf0c30487f1f1c517c5738b509990597024636f
5
5
  SHA512:
6
- metadata.gz: dbad57d56b4272b94423f6d733d823f8644020d1c5144297a42866346e2b4e48a0c68691930fa6b949d4c6692fc98023b356428e9bae1957005b50f16999be47
7
- data.tar.gz: b8504eec100f970e296015c329536175be352dd369116310469a5e4bc4dc19cfe3eee2580e83a7206906d427dc5836b328efbeec8f13436f9f783464831acd5f
6
+ metadata.gz: 1934764433941e5bd519c1ac95646109b766fc36df6826fb273d285f0abbc6a3de6b3d58a2f7cd321c0edbbe402d03eef257f63dcf890508c2f1ac9a53104910
7
+ data.tar.gz: fca59f728f58b919dfabb27f37bf1190e6513680e29cb6ddd55ef5f9fe5c622b7d35657076a7e3beef5d0d1b8d3b828cce7411d6452745ae9560a14e3a142934
@@ -13,7 +13,7 @@ jobs:
13
13
  matrix:
14
14
  rails_version: [7.0.4]
15
15
  ruby: ['3.0', '3.1', '3.2']
16
- blacklight_version: [8.0.0.beta5]
16
+ blacklight_version: [8.0.0.beta7]
17
17
  env:
18
18
  RAILS_VERSION: ${{ matrix.rails_version }}
19
19
  steps:
@@ -1,4 +1,4 @@
1
- import 'arclight/oembed_viewer'
2
-
3
1
  import Truncate from 'arclight/truncate_controller'
4
2
  Stimulus.register('arclight-truncate', Truncate)
3
+ import Oembed from 'arclight/oembed_controller'
4
+ Stimulus.register('arclight-oembed', Oembed)
@@ -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', 'data-arclight-oembed': true, 'data-arclight-oembed-url': @resource.href) do %>
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
@@ -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/oembed_viewer.js'
39
+ app.config.assets.precompile << 'arclight/oembed_controller.js'
40
40
  app.config.assets.precompile << 'arclight/truncate_controller.js'
41
41
  end
42
42
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arclight
4
- VERSION = '1.0.0.beta1'
4
+ VERSION = '1.0.0.beta3'
5
5
  end
@@ -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/oembed_viewer", to: "arclight/oembed_viewer.js"
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
- inject_into_file 'app/javascript/application.js', after: 'import "blacklight"' do
124
- "\nimport \"arclight\""
125
- end
123
+ append_to_file 'app/javascript/application.js', "\nimport \"arclight\""
126
124
  end
127
125
  end
128
126
  end
@@ -1,4 +1,5 @@
1
1
  $breadcrumb-divider: quote("»");
2
+ $logo-image: image_url('arclight/logo.png') !default;
2
3
  @import 'bootstrap';
3
4
  @import 'blacklight/blacklight';
4
5
  @import 'arclight/application';
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arclight",
3
- "version": "1.0.0-beta1",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "The frontend for arclight",
5
5
  "main": "app/assets/javascript/arclight/arclight.js",
6
6
  "files": [
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.beta1
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-08 00:00:00.000000000 Z
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/oembed_viewer.js
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.7
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
- })