Module: Spotlight::ApplicationHelper
- Includes:
- CropHelper, CrudLinkHelpers, LanguagesHelper, MetaHelper, TitleHelper
- Defined in:
- app/helpers/spotlight/application_helper.rb
Overview
General spotlight application helpers
Instance Method Summary collapse
-
#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
- #current_exhibit_theme ⇒ Object
-
#document_action_path(action_opts, url_opts = nil) ⇒ Object
Override Blacklight’s #document_action_path helper to add the current exhibit context.
- #exhibit_stylesheet_link_tag(tag) ⇒ Object
-
#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.
- #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.
- #site_title ⇒ Object
- #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.
Methods included from LanguagesHelper
#add_exhibit_language_dropdown_options, #default_language?, #locale_selecter_dropown_options
Methods included from CropHelper
#form_prefix, #iiif_cropper_tag, #iiif_cropper_tags, #iiif_upload_tag
Methods included from MetaHelper
#add_browse_meta_content, #add_document_meta_content, #add_exhibit_meta_content, #add_page_meta_content, #browse_opengraph_content, #browse_twitter_card_content, #document_opengraph_content, #document_twitter_card_content, #exhibit_opengraph_content, #exhibit_twitter_card_content, #meta_image, #page_opengraph_content, #page_twitter_card_content
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
30 31 32 33 34 35 36 |
# File 'app/helpers/spotlight/application_helper.rb', line 30 def method_missing(method, *args, &block) if main_app_url_helper?(method) main_app.send(method, *args) else super end end |
Instance Method Details
#application_name ⇒ Object
Give the application name a chance to include the exhibit title
13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/spotlight/application_helper.rb', line 13 def application_name name = site_title name ||= super if current_exhibit t :'spotlight.application_name', exhibit: current_exhibit.title, application_name: name else name end end |
#available_view_fields ⇒ Object
132 133 134 |
# File 'app/helpers/spotlight/application_helper.rb', line 132 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
87 88 89 90 91 92 93 94 |
# File 'app/helpers/spotlight/application_helper.rb', line 87 def blacklight_view_config_for_search_block(block) return {} unless block.view.present? # 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
96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/helpers/spotlight/application_helper.rb', line 96 def block_document_index_view_type(block) views = blacklight_view_config_for_search_block(block) selected_view = if views.key? document_index_view_type document_index_view_type else views.keys.first end selected_view || default_document_index_view_type end |
#current_exhibit_theme ⇒ Object
145 146 147 |
# File 'app/helpers/spotlight/application_helper.rb', line 145 def current_exhibit_theme current_exhibit.theme if current_exhibit && current_exhibit.theme.present? && Spotlight::Engine.config.exhibit_themes.include?(current_exhibit.theme) end |
#document_action_path(action_opts, url_opts = nil) ⇒ Object
Override Blacklight’s #document_action_path helper to add the current exhibit context
58 59 60 61 62 63 64 65 |
# File 'app/helpers/spotlight/application_helper.rb', line 58 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 |
#exhibit_stylesheet_link_tag(tag) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'app/helpers/spotlight/application_helper.rb', line 136 def exhibit_stylesheet_link_tag(tag) if current_exhibit_theme && current_exhibit.theme != 'default' stylesheet_link_tag "#{tag}_#{current_exhibit_theme}" else Rails.logger.warn "Exhibit theme '#{current_exhibit_theme}' not in white-list of available themes: #{Spotlight::Engine.config.exhibit_themes}" stylesheet_link_tag(tag) end end |
#render_document_class(document = @document) ⇒ Object
Override Blacklight’s #render_document_class to inject a private class
79 80 81 82 83 |
# File 'app/helpers/spotlight/application_helper.rb', line 79 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
38 39 40 |
# File 'app/helpers/spotlight/application_helper.rb', line 38 def respond_to_missing?(method, *args) main_app_url_helper?(method) || super end |
#select_deselect_button ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/helpers/spotlight/application_helper.rb', line 115 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
109 110 111 112 113 |
# File 'app/helpers/spotlight/application_helper.rb', line 109 def selected_search_block_views(block) block.as_json[:data].select do |_key, value| value == 'on' end.keys.map(&:to_s) end |
#site_title ⇒ Object
24 25 26 |
# File 'app/helpers/spotlight/application_helper.rb', line 24 def site_title current_site.title if current_site.title.present? end |
#uploaded_field_label(config) ⇒ Object
127 128 129 130 |
# File 'app/helpers/spotlight/application_helper.rb', line 127 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
45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/spotlight/application_helper.rb', line 45 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
69 70 71 72 73 74 75 |
# File 'app/helpers/spotlight/application_helper.rb', line 69 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 |