Class: Spotlight::PageConfigurations

Inherits:
Object
  • Object
show all
Defined in:
app/models/spotlight/page_configurations.rb

Overview

PageConfigurations is a simple class to gather and return all configurations needed for the various SirTrevor widgets. A downstream application (or gem) can inject its own data through the Spotlight’s engine config like so Spotlight::Engine.config.page_configurations =

'my-key': 'my_val'

You can also pass anything that responds to #call (eg. a lambda or custom ruby class) as the value and it will be evaluted within the PageConfiguration context (which has access to the view context). Spotlight::Engine.config.page_configurations = {

'exhibit-path': ->(context) { context.spotlight.exhibit_path(context.current_exhibit) }

}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, page:) ⇒ PageConfigurations

Returns a new instance of PageConfigurations.



28
29
30
31
# File 'app/models/spotlight/page_configurations.rb', line 28

def initialize(context:, page:)
  @context = context
  @page = page
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



27
28
29
# File 'app/models/spotlight/page_configurations.rb', line 27

def context
  @context
end

#pageObject (readonly)

Returns the value of attribute page.



27
28
29
# File 'app/models/spotlight/page_configurations.rb', line 27

def page
  @page
end

Instance Method Details

#as_jsonObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/spotlight/page_configurations.rb', line 33

def as_json(*)
  {
    'blacklight-configuration-index-fields': available_index_fields,
    'blacklight-configuration-search-views': available_view_configs,
    'attachment-endpoint': attachment_endpoint,
    'autocomplete-exhibit-catalog-path': exhibit_autocomplete_endpoint,
    'autocomplete-exhibit-pages-path': page_autocomplete_endpoint,
    'autocomplete-exhibit-searches-path': search_autocomplete_endpoint,
    'preview-url': page_preview_url
  }.merge(downstream_parameters)
end