Module: GeoblacklightHelper

Defined in:
app/helpers/geoblacklight_helper.rb

Instance Method Summary collapse

Instance Method Details

#document_available?(document = @document) ⇒ Boolean

Returns:

  • (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

Parameters:

Returns:

  • (Boolean)


87
88
89
# File 'app/helpers/geoblacklight_helper.rb', line 87

def first_metadata?(document, )
  document.references..first.type == .type
end

#formatted_name_reference(reference) ⇒ String

Looks up formatted names for references

Parameters:

  • reference (String, Symbol)

Returns:

  • (String)


38
39
40
# File 'app/helpers/geoblacklight_helper.rb', line 38

def formatted_name_reference(reference)
  t "geoblacklight.references.#{reference}"
end

#geoblacklight_basemapString

Selects the basemap used for map displays

Returns:

  • (String)


56
57
58
# File 'app/helpers/geoblacklight_helper.rb', line 56

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

Returns:

  • (SVG or HTML tag)


23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/geoblacklight_helper.rb', line 23

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

#iiif_jpg_urlObject



8
9
10
# File 'app/helpers/geoblacklight_helper.rb', line 8

def iiif_jpg_url
  @document.references.iiif.endpoint.sub! "info.json", "full/full/0/default.jpg"
end

#leaflet_optionsObject

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 leaflet_options
  Settings.LEAFLET
end

#relations_icon(document, icon) ⇒ Object

Returns the icon used based off a Settings strategy



103
104
105
106
107
# File 'app/helpers/geoblacklight_helper.rb', line 103

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

Parameters:

  • document, (Hash)

    field_name



94
95
96
97
98
99
100
# File 'app/helpers/geoblacklight_helper.rb', line 94

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)

Parameters:

Returns:

  • (String)


72
73
74
75
76
77
78
79
80
# File 'app/helpers/geoblacklight_helper.rb', line 72

def ()
  render partial: "catalog/metadata/content", locals: {content: .transform.html_safe}
rescue Geoblacklight::MetadataTransformer::TransformError => transform_err
  Geoblacklight.logger.warn transform_err.message
  render partial: "catalog/metadata/markup", locals: {content: .to_xml}
rescue => err
  Geoblacklight.logger.warn err.message
  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

Parameters:

  • args (Hash)

    from get_field_values



47
48
49
50
51
# File 'app/helpers/geoblacklight_helper.rb', line 47

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



110
111
112
113
114
115
116
117
# File 'app/helpers/geoblacklight_helper.rb', line 110

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

Parameters:

  • args (SolrDocument)

Returns:

  • (String)


16
17
18
# File 'app/helpers/geoblacklight_helper.rb', line 16

def snippit(args)
  truncate(Array(args[:value]).flatten.join(" "), length: 150)
end