Module: Spotlight::Controller

Extended by:
ActiveSupport::Concern
Includes:
Blacklight::Controller, Config
Included in:
Spotlight::Concerns::ApplicationController
Defined in:
app/controllers/concerns/spotlight/controller.rb

Overview

Spotlight controller helpers

Instance Method Summary collapse

Methods included from Config

#exhibit_specific_blacklight_config

Instance Method Details

#blacklight_configObject

overwrites Blacklight::Controller#blacklight_config



62
63
64
65
66
67
68
# File 'app/controllers/concerns/spotlight/controller.rb', line 62

def blacklight_config
  if current_exhibit
    exhibit_specific_blacklight_config
  else
    default_catalog_controller.blacklight_config
  end
end

#current_exhibitObject



24
25
26
# File 'app/controllers/concerns/spotlight/controller.rb', line 24

def current_exhibit
  @exhibit || (Spotlight::Exhibit.find(params[:exhibit_id]) if params[:exhibit_id].present?)
end

#current_mastheadObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/concerns/spotlight/controller.rb', line 28

def current_masthead
  @masthead ||= if resource_masthead?
                  # TODO: is there a way to get this generically, instead of requiring controllers
                  #  to override #current_masthead or set it explicitly?. In the meantime, `nil` is
                  #  hopefully less confusing than a wrong value.
                  nil
                elsif current_exhibit
                  current_exhibit.masthead if exhibit_masthead?
                elsif current_site.masthead&.display?
                  current_site.masthead
                end
end

#current_masthead=(masthead) ⇒ Object



41
42
43
# File 'app/controllers/concerns/spotlight/controller.rb', line 41

def current_masthead=(masthead)
  @masthead = masthead
end

#current_siteObject



20
21
22
# File 'app/controllers/concerns/spotlight/controller.rb', line 20

def current_site
  @current_site ||= Spotlight::Site.instance
end

#default_url_optionsObject



57
58
59
# File 'app/controllers/concerns/spotlight/controller.rb', line 57

def default_url_options
  super.merge(locale: (I18n.locale if I18n.locale != I18n.default_locale))
end

#exhibit_masthead?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/controllers/concerns/spotlight/controller.rb', line 49

def exhibit_masthead?
  current_exhibit&.masthead && current_exhibit.masthead.display?
end

#exhibit_search_action_url(*args, **kwargs) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/concerns/spotlight/controller.rb', line 86

def exhibit_search_action_url(*args, **kwargs)
  options = args.extract_options!
  options = options.merge(kwargs)
  only_path = options[:only_path]
  options.except! :exhibit_id, :only_path

  if only_path
    spotlight.search_exhibit_catalog_path(current_exhibit, *args, **options)
  else
    spotlight.search_exhibit_catalog_url(current_exhibit, *args, **options)
  end
end

#exhibit_search_facet_path(*args, **kwargs) ⇒ Object



99
100
101
102
103
# File 'app/controllers/concerns/spotlight/controller.rb', line 99

def exhibit_search_facet_path(*args, **kwargs)
  options = args.extract_options!
  options = Blacklight::Parameters.sanitize(params.to_unsafe_h.with_indifferent_access).merge(options).merge(kwargs).except(:exhibit_id, :only_path)
  spotlight.facet_exhibit_catalog_url(current_exhibit, *args, **options&.symbolize_keys)
end

#resource_masthead?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/controllers/concerns/spotlight/controller.rb', line 45

def resource_masthead?
  false
end

#search_action_url(*args, **kwargs) ⇒ Object



70
71
72
73
74
75
76
# File 'app/controllers/concerns/spotlight/controller.rb', line 70

def search_action_url(*args, **kwargs)
  if current_exhibit
    exhibit_search_action_url(*args, **kwargs)
  else
    main_app.search_catalog_url(*args, **kwargs)
  end
end

#search_facet_path(*args, **kwargs) ⇒ Object



78
79
80
81
82
83
84
# File 'app/controllers/concerns/spotlight/controller.rb', line 78

def search_facet_path(*args, **kwargs)
  if current_exhibit
    exhibit_search_facet_path(*args, **kwargs)
  else
    main_app.catalog_facet_url(*args, **kwargs)
  end
end

#set_exhibit_locale_scopeObject



16
17
18
# File 'app/controllers/concerns/spotlight/controller.rb', line 16

def set_exhibit_locale_scope
  Translation.current_exhibit = current_exhibit
end

#set_localeObject



53
54
55
# File 'app/controllers/concerns/spotlight/controller.rb', line 53

def set_locale
  I18n.locale = params[:locale] || I18n.default_locale
end