Module: Spotlight::ApplicationHelper
- Includes:
- CrudLinkHelpers, JcropHelper, TitleHelper
- Defined in:
- app/helpers/spotlight/application_helper.rb
Overview
General spotlight application helpers
Instance Method Summary collapse
- #add_exhibit_twitter_card_content ⇒ Object
-
#application_name ⇒ Object
Give the application name a chance to include the exhibit title.
- #available_view_fields ⇒ Object
-
#blacklight_view_config_for_search_block(block) ⇒ Object
Return a copy of the blacklight configuration that only includes views conifgured by our block.
- #block_document_index_view_type(block) ⇒ Object
- #carrierwave_url(upload) ⇒ Object
-
#document_action_path(action_opts, url_opts = nil) ⇒ Object
Override Blacklight’s #document_action_path helper to add the current exhibit context.
-
#method_missing(method, *args, &block) ⇒ Object
Can search for named routes directly in the main app, omitting the “main_app.” prefix.
-
#render_document_class(document = @document) ⇒ Object
Override Blacklight’s #render_document_class to inject a private class.
- #render_save_this_search? ⇒ Boolean
- #respond_to_missing?(method, *args) ⇒ Boolean
- #select_deselect_button ⇒ Object
-
#selected_search_block_views(block) ⇒ Object
Return the list of views that are configured to display for a block.
- #uploaded_field_label(config) ⇒ Object
-
#url_for_document(document) ⇒ Object
Override the Blacklight #url_for_document helper to add the current exhibit context.
-
#url_to_tag_facet(tag) ⇒ Object
Helper to turn tag data into facets.
- #view_label(view) ⇒ Object
Methods included from JcropHelper
#default_masthead_jcrop_options, #default_thumbnail_jcrop_options
Methods included from TitleHelper
#administration_page_title, #curation_page_title, #header_with_count, #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
23 24 25 26 27 28 29 |
# File 'app/helpers/spotlight/application_helper.rb', line 23 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_content ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'app/helpers/spotlight/application_helper.rb', line 115 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_name ⇒ Object
Give the application name a chance to include the exhibit title
11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/spotlight/application_helper.rb', line 11 def application_name name = super if current_exhibit t :'spotlight.application_name', exhibit: current_exhibit.title, application_name: name else name end end |
#available_view_fields ⇒ Object
150 151 152 |
# File 'app/helpers/spotlight/application_helper.rb', line 150 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
79 80 81 82 83 84 |
# File 'app/helpers/spotlight/application_helper.rb', line 79 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
86 87 88 89 90 91 92 93 94 |
# File 'app/helpers/spotlight/application_helper.rb', line 86 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
124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/spotlight/application_helper.rb', line 124 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
51 52 53 54 55 56 57 |
# File 'app/helpers/spotlight/application_helper.rb', line 51 def document_action_path(action_opts, url_opts = nil) if current_exhibit spotlight.send(action_opts.path || "exhibit_#{action_opts.key}_#{controller_name}_path", url_opts) else super end end |
#render_document_class(document = @document) ⇒ Object
Override Blacklight’s #render_document_class to inject a private class
71 72 73 74 75 |
# File 'app/helpers/spotlight/application_helper.rb', line 71 def render_document_class(document = @document) types = super || '' types << " #{document_class_prefix}private" if document.private?(current_exhibit) types end |
#render_save_this_search? ⇒ Boolean
136 137 138 139 |
# File 'app/helpers/spotlight/application_helper.rb', line 136 def render_save_this_search? (current_exhibit && can?(:curate, current_exhibit)) && !(params[:controller] == 'spotlight/catalog' && params[:action] == 'admin') end |
#respond_to_missing?(method, *args) ⇒ Boolean
31 32 33 |
# File 'app/helpers/spotlight/application_helper.rb', line 31 def respond_to_missing?(method, *args) main_app_url_helper?(method) || super end |
#select_deselect_button ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/spotlight/application_helper.rb', line 103 def ( 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
97 98 99 100 101 |
# File 'app/helpers/spotlight/application_helper.rb', line 97 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
141 142 143 144 |
# File 'app/helpers/spotlight/application_helper.rb', line 141 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
38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/spotlight/application_helper.rb', line 38 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
61 62 63 64 65 66 67 |
# File 'app/helpers/spotlight/application_helper.rb', line 61 def url_to_tag_facet(tag) if current_exhibit search_action_url(add_facet_params(Spotlight::SolrDocument.solr_field_for_tagger(current_exhibit), tag, {})) else search_action_url(q: tag) end end |
#view_label(view) ⇒ Object
146 147 148 |
# File 'app/helpers/spotlight/application_helper.rb', line 146 def view_label(view) t(:"blacklight.search.view.#{view}", default: blacklight_config.view[view].title || view.to_s) end |