Module: ModsDisplay::RecordHelper
- Defined in:
- app/helpers/mods_display/record_helper.rb
Defined Under Namespace
Classes: MetadataScrubber
Instance Method Summary
collapse
-
#format_mods_html(val, tags: %w[a dl dd dt i b em strong cite br],, field: nil) ⇒ Object
-
#link_mods_genres(genre, &block) ⇒ Object
-
#link_mods_subjects(subjects, &block) ⇒ Object
-
#link_to_mods_subject(subject, buffer = []) ⇒ Object
-
#link_urls_and_email(val, tags: %w[a dl dd dt i b em strong cite br])) ⇒ Object
@private, but used in PURL currently.
-
#mods_display_content(values, delimiter = nil) ⇒ Object
-
#mods_display_label(label) ⇒ Object
-
#mods_display_name(values, &block) ⇒ Object
-
#mods_genre_field(field, &block) ⇒ Object
-
#mods_name_field(field) ⇒ Object
this returns a role’s label and the display names for ModsDisplay:Name:Person.
-
#mods_record_field(field, delimiter = nil, component: ModsDisplay::FieldComponent, &block) ⇒ Object
-
#mods_subject_field(field, &block) ⇒ Object
-
#sanitize_mods_name_label(label) ⇒ Object
We need this to remove the ending “:” from the role labels only in data from mods_display.
Instance Method Details
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/helpers/mods_display/record_helper.rb', line 83
def format_mods_html(val, tags: %w[a dl dd dt i b em strong cite br], field: nil)
scrubber = MetadataScrubber.new
scrubber.tags = tags
formatted_val = Loofah.fragment(val).scrub!(scrubber).to_s
formatted_val = auto_link(formatted_val) unless formatted_val =~ /<a/
simple_formatted_fields = [ModsDisplay::Abstract, ModsDisplay::Contents, ModsDisplay::Note, ModsDisplay::AccessCondition]
if simple_formatted_fields.any? { |klass| field&.field.is_a? klass } && formatted_val.include?("\n")
simple_format(formatted_val, {}, sanitize: false)
else
formatted_val.html_safe
end
end
|
#link_mods_genres(genre, &block) ⇒ Object
51
52
53
54
|
# File 'app/helpers/mods_display/record_helper.rb', line 51
def link_mods_genres(genre, &block)
link_buffer = []
link_to_mods_subject(genre, link_buffer, &block)
end
|
#link_mods_subjects(subjects, &block) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'app/helpers/mods_display/record_helper.rb', line 57
def link_mods_subjects(subjects, &block)
link_buffer = []
linked_subjects = []
subjects.each do |subject|
linked_subjects << link_to_mods_subject(subject, link_buffer, &block) if subject.present?
end
linked_subjects
end
|
#link_to_mods_subject(subject, buffer = []) ⇒ Object
67
68
69
70
71
72
73
|
# File 'app/helpers/mods_display/record_helper.rb', line 67
def link_to_mods_subject(subject, buffer = [])
subject_text = subject.respond_to?(:name) ? subject.name : subject
link = block_given? ? capture { yield(subject_text, buffer) } : subject_text
buffer << subject_text.strip
link << " (#{subject.roles.join(', ')})" if subject.respond_to?(:roles) && subject.roles.present?
link
end
|
#link_urls_and_email(val, tags: %w[a dl dd dt i b em strong cite br])) ⇒ Object
@private, but used in PURL currently
108
109
110
|
# File 'app/helpers/mods_display/record_helper.rb', line 108
def link_urls_and_email(val, tags: %w[a dl dd dt i b em strong cite br])
format_mods_html(val, tags: tags)
end
|
#mods_display_content(values, delimiter = nil) ⇒ Object
12
13
14
|
# File 'app/helpers/mods_display/record_helper.rb', line 12
def mods_display_content(values, delimiter = nil)
mods_record_field ModsDisplay::Values.new(values: Array(values)), delimiter
end
|
#mods_display_label(label) ⇒ Object
7
8
9
|
# File 'app/helpers/mods_display/record_helper.rb', line 7
def mods_display_label(label)
content_tag(:dt, label.delete(':')) + "\n".html_safe
end
|
#mods_display_name(values, &block) ⇒ Object
27
28
29
|
# File 'app/helpers/mods_display/record_helper.rb', line 27
def mods_display_name(values, &block)
mods_name_field(ModsDisplay::Values.new(values: Array(values)), &block)
end
|
#mods_genre_field(field, &block) ⇒ Object
44
45
46
47
48
|
# File 'app/helpers/mods_display/record_helper.rb', line 44
def mods_genre_field(field, &block)
mods_record_field(field) do |genre_line|
link_to_mods_subject(genre_line, &block)
end
end
|
#mods_name_field(field) ⇒ Object
this returns a role’s label and the display names for ModsDisplay:Name:Person
21
22
23
24
25
|
# File 'app/helpers/mods_display/record_helper.rb', line 21
def mods_name_field(field)
mods_record_field(field) do |name|
block_given? ? capture { yield(name.name) } : name.name
end
end
|
#mods_record_field(field, delimiter = nil, component: ModsDisplay::FieldComponent, &block) ⇒ Object
16
17
18
|
# File 'app/helpers/mods_display/record_helper.rb', line 16
def mods_record_field(field, delimiter = nil, component: ModsDisplay::FieldComponent, &block)
render component.new(field: field, delimiter: delimiter, value_transformer: block)
end
|
#mods_subject_field(field, &block) ⇒ Object
38
39
40
41
42
|
# File 'app/helpers/mods_display/record_helper.rb', line 38
def mods_subject_field(field, &block)
mods_record_field(field) do |subject_line|
safe_join(link_mods_subjects(subject_line, &block), ' > ')
end
end
|
#sanitize_mods_name_label(label) ⇒ Object
We need this to remove the ending “:” from the role labels only in data from mods_display
34
35
36
|
# File 'app/helpers/mods_display/record_helper.rb', line 34
def sanitize_mods_name_label(label)
label.sub(/:$/, '')
end
|