Class: Blacklight::SearchBarPresenter

Inherits:
Object
  • Object
show all
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.



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

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.



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

def configuration
  @configuration
end

#controllerObject (readonly)

Returns the value of attribute controller.



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

def controller
  @controller
end

#view_contextObject (readonly)

Returns the value of attribute view_context.



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

def view_context
  @view_context
end

Instance Method Details

#advanced_search_enabled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 41

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



23
24
25
26
# File 'app/presenters/blacklight/search_bar_presenter.rb', line 23

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)


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

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



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

def render
  view_context.render partial, presenter: self
end