Module: Blacklight::SearchHistoryConstraintsHelperBehavior

Extended by:
Deprecation
Included in:
CatalogHelperBehavior
Defined in:
app/helpers/blacklight/search_history_constraints_helper_behavior.rb

Overview

All methods in here are 'api' that may be over-ridden by plugins and local code, so method signatures and semantics should not be changed casually. implementations can be of course.

Includes methods for rendering more textually on Search History page (render_search_to_s(_*))

Instance Method Summary collapse

Instance Method Details

#render_filter_name(name) ⇒ Object

Render the name of the facet



65
66
67
68
69
70
71
# File 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb', line 65

def render_filter_name name
  Deprecation.warn(Blacklight::SearchHistoryConstraintsHelperBehavior, '#render_filter_name is deprecated without replacement')
  return "".html_safe if name.blank?

  tag.span(t('blacklight.search.filters.label', label: name),
           class: 'filter-name')
end

#render_filter_value(value, key = nil) ⇒ Object

Render the value of the facet



75
76
77
78
79
80
81
82
83
# File 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb', line 75

def render_filter_value value, key = nil
  Deprecation.warn(Blacklight::SearchHistoryConstraintsHelperBehavior, '#render_filter_value is deprecated without replacement')
  display_value = value
  Deprecation.silence(Blacklight::FacetsHelperBehavior) do
    display_value = facet_display_value(key, value) if key
  end
  tag.span(h(display_value),
           class: 'filter-value')
end

#render_search_to_s(params) ⇒ Object

Simpler textual version of constraints, used on Search History page. Theoretically can may be DRY'd up with results page render_constraints, maybe even using the very same HTML with different CSS? But too tricky for now, too many changes to existing CSS. TODO.



16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb', line 16

def render_search_to_s(params)
  return render(Blacklight::ConstraintsComponent.for_search_history(search_state: convert_to_search_state(params))) unless overridden_search_history_constraints_helper_methods?

  Deprecation.warn(Blacklight::SearchHistoryConstraintsHelperBehavior, 'Calling out to potentially overridden helpers for backwards compatibility.')

  Deprecation.silence(Blacklight::SearchHistoryConstraintsHelperBehavior) do
    render_search_to_s_q(params) +
    render_search_to_s_filters(params)
  end
end

#render_search_to_s_element(key, value, _options = {}) ⇒ Object

value can be Array, in which case elements are joined with 'and'. Pass in option :escape_value => false to pass in pre-rendered html for value. key with escape_key if needed.



57
58
59
60
61
# File 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb', line 57

def render_search_to_s_element(key, value, _options = {})
  Deprecation.warn(Blacklight::SearchHistoryConstraintsHelperBehavior, '#render_search_to_s_element is deprecated without replacement')
  tag.span(render_filter_name(key) + tag.span(value, class: 'filter-values'),
           class: 'constraint')
end

#render_search_to_s_filters(params) ⇒ Object

Render the search facet constraints



41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb', line 41

def render_search_to_s_filters(params)
  Deprecation.warn(Blacklight::SearchHistoryConstraintsHelperBehavior, '#render_search_to_s_filters is deprecated without replacement')
  return "".html_safe unless params[:f]

  safe_join(params[:f].collect do |facet_field, value_list|
    render_search_to_s_element(facet_field_label(facet_field),
                               safe_join(value_list.collect do |value|
                                 render_filter_value(value, facet_field)
                               end,
                                         tag.span(" #{t('blacklight.and')} ", class: 'filter-separator')))
  end, " \n ")
end

#render_search_to_s_q(params) ⇒ Object

Render the search query constraint



30
31
32
33
34
35
36
37
# File 'app/helpers/blacklight/search_history_constraints_helper_behavior.rb', line 30

def render_search_to_s_q(params)
  Deprecation.warn(Blacklight::SearchHistoryConstraintsHelperBehavior, '#render_search_to_s_q is deprecated without replacement')
  return "".html_safe if params['q'].blank?

  label = label_for_search_field(params[:search_field]) unless default_search_field?(params[:search_field])

  render_search_to_s_element(label, render_filter_value(params['q']))
end