-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathembed_component.rb
More file actions
43 lines (34 loc) · 924 Bytes
/
embed_component.rb
File metadata and controls
43 lines (34 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true
module Arclight
# Render digital object links for a document
class EmbedComponent < ViewComponent::Base
def initialize(presenter:, document_counter: nil, **kwargs) # rubocop:disable Lint/UnusedMethodArgument
super()
@document = presenter.document
@presenter = presenter
end
def render?
resources.any?
end
def embeddable_resources
resources.first(1).select { |object| embeddable?(object) }
end
def linked_resources
resources - embeddable_resources
end
def resources
@resources ||= @document.digital_objects || []
end
def depth
@document.parents.length || 0
end
def embeddable?(object)
exclude_patterns.none? do |pattern|
object.href =~ pattern
end
end
def exclude_patterns
Arclight::Engine.config.oembed_resource_exclude_patterns
end
end
end