Module: GeoblacklightHelper
- Defined in:
- app/helpers/geoblacklight_helper.rb
Instance Method Summary collapse
- #document_available?(document = @document) ⇒ Boolean
- #first_metadata?(document, metadata) ⇒ Boolean deprecated Deprecated.
-
#formatted_name_reference(reference) ⇒ String
Looks up formatted names for references.
- #geoblacklight_basemap ⇒ String deprecated Deprecated.
-
#geoblacklight_icon(name, **args) ⇒ SVG or HTML tag
Returns an SVG icon or empty HTML span element.
- #leaflet_options ⇒ Object deprecated Deprecated.
- #relations_icon(document, icon) ⇒ Object deprecated Deprecated.
-
#render_references_url(args) ⇒ Object
Renders a reference url for a document.
- #render_transformed_metadata(metadata) ⇒ String deprecated Deprecated.
- #render_value_as_truncate_abstract(args) ⇒ Object deprecated Deprecated.
-
#results_js_map_selector(controller_name) ⇒ Object
Returns the data-page attribute value used as the JS map selector.
- #snippit(args) ⇒ String deprecated Deprecated.
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
89 90 91 |
# File 'app/helpers/geoblacklight_helper.rb', line 89 def (document, ) document.references..first.type == .type end |
#formatted_name_reference(reference) ⇒ String
Looks up formatted names for references
35 36 37 |
# File 'app/helpers/geoblacklight_helper.rb', line 35 def formatted_name_reference(reference) t "geoblacklight.references.#{reference}" end |
#geoblacklight_basemap ⇒ String
Selects the basemap used for map displays
55 56 57 |
# File 'app/helpers/geoblacklight_helper.rb', line 55 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
20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/geoblacklight_helper.rb', line 20 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
63 64 65 |
# File 'app/helpers/geoblacklight_helper.rb', line 63 def Settings.LEAFLET end |
#relations_icon(document, icon) ⇒ Object
Returns the icon used based off a Settings strategy
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/geoblacklight_helper.rb', line 106 def relations_icon(document, icon) # If configured to use geometry type for relations icon if Settings.USE_GEOM_FOR_RELATIONS_ICON Geoblacklight.deprecation.warn("USE_GEOM_FOR_RELATIONS_ICON is deprecated and will be removed in GeoBlacklight 6") icon_html = render Geoblacklight::HeaderIconsComponent.new( document: document, fields: [Settings.FIELDS.GEOM_TYPE] ) # Use geometry-based icon if it's valid (not missing) return icon_html unless icon_html.include?("icon-missing") end # Fall back to the default icon geoblacklight_icon(icon) end |
#render_references_url(args) ⇒ Object
Renders a reference url for a document
96 97 98 99 100 101 102 |
# File 'app/helpers/geoblacklight_helper.rb', line 96 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)
73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/geoblacklight_helper.rb', line 73 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
45 46 47 48 49 |
# File 'app/helpers/geoblacklight_helper.rb', line 45 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
124 125 126 127 128 129 130 131 |
# File 'app/helpers/geoblacklight_helper.rb', line 124 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
13 14 15 |
# File 'app/helpers/geoblacklight_helper.rb', line 13 def snippit(args) truncate(Array(args[:value]).flatten.join(" "), length: 150) end |