Class: Blacklight::SearchBarPresenter

Inherits:
Object
  • Object
show all
Extended by:
Deprecation
Defined in:
app/presenters/blacklight/search_bar_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, configuration = view_context.blacklight_config) ⇒ SearchBarPresenter

Returns a new instance of SearchBarPresenter.



12
13
14
15
16
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 12

def initialize(controller, configuration = view_context.blacklight_config)
  @controller = controller
  @view_context = controller.view_context
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



6
7
8
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 6

def configuration
  @configuration
end

#controllerObject (readonly)

Returns the value of attribute controller.



6
7
8
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 6

def controller
  @controller
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



6
7
8
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 6

def view_context
  @view_context
end

Instance Method Details

#advanced_search_enabled?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 43

def advanced_search_enabled?
  configuration.advanced_search.enabled
end

#autocomplete_enabled?Boolean

Returns should autocomplete be enabled in the UI.

Returns:

  • (Boolean)

    should autocomplete be enabled in the UI



25
26
27
28
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 25

def autocomplete_enabled?
  configuration.autocomplete_enabled.present? &&
    configuration.autocomplete_path.present?
end

#autofocus?Boolean

If no search parameters have been given, we should auto-focus the user’s cursor into the searchbox

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 35

def autofocus?
  configuration.enable_search_bar_autofocus.present? &&
    configuration.enable_search_bar_autofocus &&
    controller.is_a?(Blacklight::Catalog) &&
    controller.action_name == "index" &&
    !controller.has_search_parameters?
end

#renderObject



18
19
20
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 18

def render
  view_context.render partial, presenter: self
end