Module: ViewHelper
- Defined in:
- public/app/helpers/view_helper.rb
Instance Method Summary collapse
-
#accession_base_url(result) ⇒ Object
-
#agent_base_url(result) ⇒ Object
-
#all_inherited?(items) ⇒ Boolean
-
#archival_object_base_url(result) ⇒ Object
-
#classification_base_url(result) ⇒ Object
-
#digital_object_base_url(result) ⇒ Object
-
#display_component_id(record, infinite_item) ⇒ Object
-
#display_date_type(type, value) ⇒ Object
-
#display_date_type?(type) ⇒ Boolean
-
#display_used_language(language) ⇒ Object
-
#find_dates_for(result) ⇒ Object
-
#inherited?(item) ⇒ Boolean
-
#nl2ws(text) ⇒ Object
-
#repository_base_url(result) ⇒ Object
returns repo URL via slug if defined, via ID it not.
-
#representative_link_to_digital_materials?(record) ⇒ Boolean
-
#resource_base_url(result) ⇒ Object
-
#show_agents_sidebar?(agent) ⇒ Boolean
-
#snac_identifiers(identifiers) ⇒ Object
-
#subject_base_url(result) ⇒ Object
-
#uri?(uri_candidate) ⇒ Boolean
Instance Method Details
#accession_base_url(result) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'public/app/helpers/view_helper.rb', line 123 def accession_base_url(result) if result.json['slug'] && AppConfig[:use_human_readable_urls] if AppConfig[:repo_name_in_slugs] if result.resolved_repository["slug"] url = "repositories/#{result.resolved_repository["slug"]}/accessions/" + result.json['slug'] else url = result['uri'] end # otherwise, generate URL without repo slug else url = "accessions/" + result.json['slug'] end else url = result['uri'] end return url end |
#agent_base_url(result) ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'public/app/helpers/view_helper.rb', line 173 def agent_base_url(result) if result.json['slug'] && AppConfig[:use_human_readable_urls] url = "agents/" + result.json['slug'] else url = result['uri'] end return url end |
#all_inherited?(items) ⇒ Boolean
13 14 15 |
# File 'public/app/helpers/view_helper.rb', line 13 def all_inherited?(items) items.all? { |item| inherited?(item) } end |
#archival_object_base_url(result) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'public/app/helpers/view_helper.rb', line 183 def archival_object_base_url(result) if result.json['slug'] && AppConfig[:use_human_readable_urls] if AppConfig[:repo_name_in_slugs] if result.resolved_repository["slug"] url = "repositories/#{result.resolved_repository["slug"]}/archival_objects/" + result.json['slug'] else url = result['uri'] end # otherwise, generate URL without repo slug else url = "archival_objects/" + result.json['slug'] end else url = result['uri'] end return url end |
#classification_base_url(result) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'public/app/helpers/view_helper.rb', line 153 def classification_base_url(result) if result.json['slug'] && AppConfig[:use_human_readable_urls] if AppConfig[:repo_name_in_slugs] if result.resolved_repository["slug"] url = "repositories/#{result.resolved_repository["slug"]}/classifications/" + result.json['slug'] else url = result['uri'] end # otherwise, generate URL without repo slug else url = "classifications/" + result.json['slug'] end else url = result['uri'] end return url end |
#digital_object_base_url(result) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'public/app/helpers/view_helper.rb', line 103 def digital_object_base_url(result) if result.json['slug'] && AppConfig[:use_human_readable_urls] if AppConfig[:repo_name_in_slugs] if result.resolved_repository["slug"] url = "repositories/#{result.resolved_repository["slug"]}/digital_objects/" + result.json['slug'] else url = result['uri'] end # otherwise, generate URL without repo slug else url = "digital_objects/" + result.json['slug'] end else url = result['uri'] end return url end |
#display_component_id(record, infinite_item) ⇒ Object
17 18 19 20 21 |
# File 'public/app/helpers/view_helper.rb', line 17 def display_component_id(record, infinite_item) return nil if record.identifier.blank? || (infinite_item && record.json.key?('component_id_inherited')) record.identifier end |
#display_date_type(type, value) ⇒ Object
36 37 38 |
# File 'public/app/helpers/view_helper.rb', line 36 def display_date_type(type, value) "(" + I18n.t("enumerations.#{type}.#{value}") + ")" end |
#display_date_type?(type) ⇒ Boolean
32 33 34 |
# File 'public/app/helpers/view_helper.rb', line 32 def display_date_type?(type) type && type != 'standard' end |
#display_used_language(language) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'public/app/helpers/view_helper.rb', line 53 def display_used_language(language) lang = '' lang.concat("<b>#{I18n.t('language_and_script.language')}:</b> ") if language['language'] && language['script'] lang.concat("#{I18n.t("enumerations.language_iso639_2.#{language['language']}")}") if language['language'] return sanitize(lang) unless language['script'] lang.concat('. ') if language['language'] # separator lang.concat("<b>#{I18n.t('language_and_script.script')}:</b> ") lang.concat(I18n.t("enumerations.script_iso15924.#{language['script']}")) sanitize(lang) end |
#find_dates_for(result) ⇒ Object
27 28 29 30 |
# File 'public/app/helpers/view_helper.rb', line 27 def find_dates_for(result) dates = result.json.fetch('dates_of_existence', []) dates + result.json['names'].map {|names| names['use_dates']}.flatten end |
#inherited?(item) ⇒ Boolean
9 10 11 |
# File 'public/app/helpers/view_helper.rb', line 9 def inherited?(item) (item.key?('_inherited') && item['_inherited']) || (item.key?('is_inherited') && item['is_inherited']) end |
#nl2ws(text) ⇒ Object
44 45 46 47 |
# File 'public/app/helpers/view_helper.rb', line 44 def nl2ws(text) text = text.join(' ') if text.respond_to? :each sanitize(text).gsub(/\n/, ' ').html_safe end |
#repository_base_url(result) ⇒ Object
returns repo URL via slug if defined, via ID it not.
68 69 70 71 72 73 74 75 76 |
# File 'public/app/helpers/view_helper.rb', line 68 def repository_base_url(result) if result['slug'] && AppConfig[:use_human_readable_urls] url = "repositories/" + result['slug'] else url = result['uri'] end return url end |
#representative_link_to_digital_materials?(record) ⇒ Boolean
40 41 42 |
# File 'public/app/helpers/view_helper.rb', line 40 def representative_link_to_digital_materials?(record) record.primary_type == 'resource' end |
#resource_base_url(result) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'public/app/helpers/view_helper.rb', line 78 def resource_base_url(result) if result.json['slug'] && AppConfig[:use_human_readable_urls] # Generate URLs with repo slugs if turned on if AppConfig[:repo_name_in_slugs] if result.resolved_repository["slug"] url = "repositories/#{result.resolved_repository["slug"]}/resources/" + result.json['slug'] # just use ids if repo has no slug else url = result['uri'] end # otherwise, generate URL without repo slug else url = "resources/" + result.json['slug'] end # object has no slug else url = result['uri'] end return url end |
#show_agents_sidebar?(agent) ⇒ Boolean
2 3 4 5 6 7 |
# File 'public/app/helpers/view_helper.rb', line 2 def (agent) agent.json['names'].length > 1 || (agent.respond_to?(:related_agents) && ASUtils.wrap(agent.).any?) || (agent.respond_to?(:external_documents) && ASUtils.wrap(agent.external_documents).any?) || (agent.json['agent_resources'] && ASUtils.wrap(agent.json['agent_resources']).any?) end |
#snac_identifiers(identifiers) ⇒ Object
23 24 25 |
# File 'public/app/helpers/view_helper.rb', line 23 def snac_identifiers(identifiers) identifiers.select { |id| id['source'] == 'snac' } end |
#subject_base_url(result) ⇒ Object
143 144 145 146 147 148 149 150 151 |
# File 'public/app/helpers/view_helper.rb', line 143 def subject_base_url(result) if result.json['slug'] && AppConfig[:use_human_readable_urls] url = "subjects/" + result.json['slug'] else url = result['uri'] end return url end |
#uri?(uri_candidate) ⇒ Boolean
49 50 51 |
# File 'public/app/helpers/view_helper.rb', line 49 def uri?(uri_candidate) uri_candidate =~ /^#{URI::DEFAULT_PARSER.make_regexp}$/ end |