app/helpers/spotlight/application_helper.rb in blacklight-spotlight-0.2.0 vs app/helpers/spotlight/application_helper.rb in blacklight-spotlight-0.3.0

- old
+ new

@@ -1,9 +1,10 @@ module Spotlight module ApplicationHelper include CrudLinkHelpers include TitleHelper + include JcropHelper def application_name name = super if current_exhibit @@ -29,11 +30,11 @@ def url_for_document document return nil if document.nil? if current_exhibit - spotlight.exhibit_catalog_path(current_exhibit, document) + [spotlight, current_exhibit, document] else document end end @@ -59,16 +60,10 @@ types = super || "" types << " #{document_class_prefix}private" if document.private?(current_exhibit) types end - ## - # Override Blacklight (5.2+) so we use our own presenter - def presenter_class - Spotlight::DocumentPresenter - end - # Return a copy of the blacklight configuration # that only includes views conifgured by our block 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,_| @@ -91,28 +86,50 @@ block.as_json[:data].select do |key, value| value == "on" end.keys.map { |x| x.to_s } end - def render_save_search - render('save_search') if render_save_this_search? - end - - def render_save_this_search? - (current_exhibit and can?( :curate, current_exhibit)) && - (params[:controller] != "spotlight_catalog_controller" && params[:action] != "admin") - end - 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 + + 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.featured_image) if current_exhibit.featured_image + end + end + + 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? or url.starts_with? "http" + url + else + (Rails.application.config.asset_host || root_url).sub(/\/$/, "") + url + end + end + + def render_save_this_search? + (current_exhibit and can?( :curate, current_exhibit)) && + !(params[:controller] == "spotlight/catalog" && params[:action] == "admin") + end + + 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 private def main_app_url_helper?(method)