Module: Spotlight::ApplicationHelper

Includes:
CrudLinkHelpers, JcropHelper, TitleHelper
Defined in:
app/helpers/spotlight/application_helper.rb

Overview

General spotlight application helpers

Instance Method Summary collapse

Methods included from JcropHelper

#default_masthead_jcrop_options, #default_site_thumbnail_jcrop_options, #default_thumbnail_jcrop_options

Methods included from TitleHelper

#configuration_page_title, #curation_page_title, #page_title, #set_html_page_title

Methods included from CrudLinkHelpers

#action_label, #cancel_link, #create_link, #delete_link, #edit_link, #exhibit_create_link, #exhibit_delete_link, #exhibit_edit_link, #exhibit_view_link, #view_link

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Can search for named routes directly in the main app, omitting the “main_app.” prefix



24
25
26
27
28
29
30
# File 'app/helpers/spotlight/application_helper.rb', line 24

def method_missing(method, *args, &block)
  if main_app_url_helper?(method)
    main_app.send(method, *args)
  else
    super
  end
end

Instance Method Details

#add_exhibit_twitter_card_contentObject



117
118
119
120
121
122
123
124
# File 'app/helpers/spotlight/application_helper.rb', line 117

def add_exhibit_twitter_card_content
  twitter_card('summary') do |card|
    card.url exhibit_root_url(current_exhibit)
    card.title current_exhibit.title
    card.description current_exhibit.subtitle
    card.image carrierwave_url(current_exhibit.thumbnail.image.thumb) if current_exhibit.thumbnail
  end
end

#application_nameObject

Give the application name a chance to include the exhibit title



11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/spotlight/application_helper.rb', line 11

def application_name
  name = current_site.title if current_site.title.present?
  name ||= super

  if current_exhibit
    t :'spotlight.application_name', exhibit: current_exhibit.title, application_name: name
  else
    name
  end
end

#available_view_fieldsObject



147
148
149
# File 'app/helpers/spotlight/application_helper.rb', line 147

def available_view_fields
  current_exhibit.blacklight_configuration.default_blacklight_config.view.to_h.reject { |_k, v| v.if == false }
end

#blacklight_view_config_for_search_block(block) ⇒ Object

Return a copy of the blacklight configuration that only includes views conifgured by our block



81
82
83
84
85
86
# File 'app/helpers/spotlight/application_helper.rb', line 81

def blacklight_view_config_for_search_block(block)
  # Reject any views that aren't configured to display for this block
  blacklight_config.view.select do |view, _|
    block.view.include? view.to_s
  end
end

#block_document_index_view_type(block) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'app/helpers/spotlight/application_helper.rb', line 88

def block_document_index_view_type(block)
  views = blacklight_view_config_for_search_block(block)

  if views.key? document_index_view_type
    document_index_view_type
  else
    views.keys.first
  end
end

#carrierwave_url(upload) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
# File 'app/helpers/spotlight/application_helper.rb', line 126

def carrierwave_url(upload)
  # Carrierwave's #url returns either a full url (if asset path was configured)
  # or just the path to the image. We'll try to normalize it to a url.
  url = upload.url

  if url.nil? || url.starts_with?('http')
    url
  else
    (URI.parse(Rails.application.config.asset_host || root_url) + url).to_s
  end
end

#document_action_path(action_opts, url_opts = nil) ⇒ Object

Override Blacklight’s #document_action_path helper to add the current exhibit context



52
53
54
55
56
57
58
59
# File 'app/helpers/spotlight/application_helper.rb', line 52

def document_action_path(action_opts, url_opts = nil)
  if current_exhibit
    model_name = current_exhibit.blacklight_config.document_model.model_name
    spotlight.send(action_opts.path || "#{action_opts.key}_exhibit_#{model_name.collection}_path", url_opts)
  else
    super
  end
end

#render_document_class(document = @document) ⇒ Object

Override Blacklight’s #render_document_class to inject a private class



73
74
75
76
77
# File 'app/helpers/spotlight/application_helper.rb', line 73

def render_document_class(document = @document)
  types = super || ''
  types << " #{document_class_prefix}private" if document.private?(current_exhibit)
  types
end

#respond_to_missing?(method, *args) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/helpers/spotlight/application_helper.rb', line 32

def respond_to_missing?(method, *args)
  main_app_url_helper?(method) || super
end

#select_deselect_buttonObject



105
106
107
108
109
110
111
112
113
114
115
# File 'app/helpers/spotlight/application_helper.rb', line 105

def select_deselect_button
  button_tag(
    t(:".deselect_all"),
    class: 'btn btn-default btn-xs metadata-select',
    data: {
      behavior: 'metadata-select',
      'deselect-text' => t(:".deselect_all"),
      'select-text' => t(:".select_all")
    }
  )
end

#selected_search_block_views(block) ⇒ Object

Return the list of views that are configured to display for a block



99
100
101
102
103
# File 'app/helpers/spotlight/application_helper.rb', line 99

def selected_search_block_views(block)
  block.as_json[:data].select do |_key, value|
    value == 'on'
  end.keys.map(&:to_s)
end

#uploaded_field_label(config) ⇒ Object



138
139
140
141
# File 'app/helpers/spotlight/application_helper.rb', line 138

def uploaded_field_label(config)
  solr_field = Array(config.solr_field || config.field_name).first.to_s
  config.label || blacklight_config.index_fields[solr_field].try(:label) || t(".#{solr_field}")
end

#url_for_document(document) ⇒ Object

Override the Blacklight #url_for_document helper to add the current exhibit context



39
40
41
42
43
44
45
46
47
# File 'app/helpers/spotlight/application_helper.rb', line 39

def url_for_document(document)
  return nil if document.nil?

  if current_exhibit
    [spotlight, current_exhibit, document]
  else
    document
  end
end

#url_to_tag_facet(tag) ⇒ Object

Helper to turn tag data into facets



63
64
65
66
67
68
69
# File 'app/helpers/spotlight/application_helper.rb', line 63

def url_to_tag_facet(tag)
  if current_exhibit
    search_action_url(search_state.reset.add_facet_params(blacklight_config.document_model.solr_field_for_tagger(current_exhibit), tag))
  else
    search_action_url(q: tag)
  end
end

#view_label(view) ⇒ Object



143
144
145
# File 'app/helpers/spotlight/application_helper.rb', line 143

def view_label(view)
  t(:"blacklight.search.view.#{view}", default: blacklight_config.view[view].title || view.to_s)
end