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.
-
#leaflet_options ⇒ Object
Returns a hash of the leaflet plugin settings to pass to the viewer.
-
#relations_icon(document, icon) ⇒ Object
Returns the icon used based off a Settings strategy.
-
#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
83 84 85 |
# File 'app/helpers/geoblacklight_helper.rb', line 83 def (document, ) document.references..first.type == .type end |
#formatted_name_reference(reference) ⇒ String
Looks up formatted names for references
34 35 36 |
# File 'app/helpers/geoblacklight_helper.rb', line 34 def formatted_name_reference(reference) t "geoblacklight.references.#{reference}" end |
#geoblacklight_basemap ⇒ String
Selects the basemap used for map displays
52 53 54 |
# File 'app/helpers/geoblacklight_helper.rb', line 52 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 28 |
# File 'app/helpers/geoblacklight_helper.rb', line 19 def geoblacklight_icon(name, **args) icon_name = name ? name.to_s.parameterize : "none" icon_name = Settings.ICON_MAPPING && Settings.ICON_MAPPING[icon_name] || icon_name 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 |
#leaflet_options ⇒ Object
Returns a hash of the leaflet plugin settings to pass to the viewer. @return
59 60 61 |
# File 'app/helpers/geoblacklight_helper.rb', line 59 def Settings.LEAFLET end |
#relations_icon(document, icon) ⇒ Object
Returns the icon used based off a Settings strategy
99 100 101 102 103 |
# File 'app/helpers/geoblacklight_helper.rb', line 99 def relations_icon(document, icon) icon_html = render Geoblacklight::HeaderIconsComponent.new(document: document, fields: [Settings.FIELDS.GEOM_TYPE]) if Settings.USE_GEOM_FOR_RELATIONS_ICON return icon_html unless !Settings.USE_GEOM_FOR_RELATIONS_ICON || icon_html.include?("icon-missing") geoblacklight_icon(icon, **{}) end |
#render_references_url(args) ⇒ Object
Renders a reference url for a document
90 91 92 93 94 95 96 |
# File 'app/helpers/geoblacklight_helper.rb', line 90 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)
68 69 70 71 72 73 74 75 76 |
# File 'app/helpers/geoblacklight_helper.rb', line 68 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
43 44 45 46 47 |
# File 'app/helpers/geoblacklight_helper.rb', line 43 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
106 107 108 109 110 111 112 113 |
# File 'app/helpers/geoblacklight_helper.rb', line 106 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 |