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.



30
31
32
33
# File 'app/models/spotlight/page_configurations.rb', line 30

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

Instance Method Details

#as_jsonObject



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

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