Module: GeoblacklightHelper
- Defined in:
- app/helpers/geoblacklight_helper.rb
Instance Method Summary collapse
- #document_available?(document = @document) ⇒ Boolean
-
#first_metadata?(document, metadata) ⇒ Boolean
Determines whether or not the metadata is the first within the array of References.
-
#formatted_name_reference(reference) ⇒ String
Looks up formatted names for references.
-
#geoblacklight_basemap ⇒ String
Selects the basemap used for map displays.
-
#geoblacklight_icon(name, **args) ⇒ SVG or HTML tag
Returns an SVG icon or empty HTML span element.
-
#render_references_url(args) ⇒ Object
Renders a reference url for a document.
-
#render_transformed_metadata(metadata) ⇒ String
Renders the transformed metadata (Renders a partial when the metadata isn’t available).
-
#render_value_as_truncate_abstract(args) ⇒ Object
Render value for a document’s field as a truncate abstract div.
-
#results_js_map_selector(controller_name) ⇒ Object
Returns the data-page attribute value used as the JS map selector.
-
#snippit(args) ⇒ String
Blacklight catalog controller helper method to truncate field value to 150 chars.
Instance Method Details
#document_available?(document = @document) ⇒ Boolean
4 5 6 |
# File 'app/helpers/geoblacklight_helper.rb', line 4 def document_available?(document = @document) document.public? || (document.same_institution? && user_signed_in?) end |
#first_metadata?(document, metadata) ⇒ Boolean
Determines whether or not the metadata is the first within the array of References
75 76 77 |
# File 'app/helpers/geoblacklight_helper.rb', line 75 def (document, ) document.references..first.type == .type end |
#formatted_name_reference(reference) ⇒ String
Looks up formatted names for references
33 34 35 |
# File 'app/helpers/geoblacklight_helper.rb', line 33 def formatted_name_reference(reference) t "geoblacklight.references.#{reference}" end |
#geoblacklight_basemap ⇒ String
Selects the basemap used for map displays
51 52 53 |
# File 'app/helpers/geoblacklight_helper.rb', line 51 def geoblacklight_basemap blacklight_config.basemap_provider || "positron" end |
#geoblacklight_icon(name, **args) ⇒ SVG or HTML tag
Returns an SVG icon or empty HTML span element
19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/geoblacklight_helper.rb', line 19 def geoblacklight_icon(name, **args) icon_name = name ? name.to_s.parameterize : "none" camel_icon = icon_name.tr("-", "_").camelize.delete(" ") begin render "Blacklight::Icons::#{camel_icon}Component".constantize.new(name: icon_name, **args) rescue NameError tag.span class: "icon-missing geoblacklight-none" end end |
#render_references_url(args) ⇒ Object
Renders a reference url for a document
82 83 84 85 86 87 88 |
# File 'app/helpers/geoblacklight_helper.rb', line 82 def render_references_url(args) return unless args[:document]&.references&.url link_to( args[:document].references.url.endpoint, args[:document].references.url.endpoint ) end |
#render_transformed_metadata(metadata) ⇒ String
Renders the transformed metadata (Renders a partial when the metadata isn’t available)
60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/geoblacklight_helper.rb', line 60 def () render partial: "catalog/metadata/content", locals: {content: .transform.html_safe} rescue Geoblacklight::MetadataTransformer::TransformError => transform_err Geoblacklight.logger.warn transform_err. render partial: "catalog/metadata/markup", locals: {content: .to_xml} rescue => err Geoblacklight.logger.warn err. render partial: "catalog/metadata/missing" end |
#render_value_as_truncate_abstract(args) ⇒ Object
Render value for a document’s field as a truncate abstract div. Arguments come from Blacklight::DocumentPresenter’s get_field_values method
42 43 44 45 46 |
# File 'app/helpers/geoblacklight_helper.rb', line 42 def render_value_as_truncate_abstract(args) tag.div class: "truncate-abstract" do Array(args[:value]).flatten.join(" ") end end |
#results_js_map_selector(controller_name) ⇒ Object
Returns the data-page attribute value used as the JS map selector
91 92 93 94 95 96 97 98 |
# File 'app/helpers/geoblacklight_helper.rb', line 91 def results_js_map_selector(controller_name) case controller_name when "bookmarks" "bookmarks" else "index" end end |
#snippit(args) ⇒ String
Blacklight catalog controller helper method to truncate field value to 150 chars
12 13 14 |
# File 'app/helpers/geoblacklight_helper.rb', line 12 def snippit(args) truncate(Array(args[:value]).flatten.join(" "), length: 150) end |