Module: RenderConstraintsHelper
- Included in:
- ApplicationHelper
- Defined in:
- vendor/plugins/blacklight/app/helpers/render_constraints_helper.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 contraints graphically on the search results page (render_constraints(_*)), and also for rendering more textually on Search History page (render_search_to_s(_*))
Instance Method Summary (collapse)
-
- (Object) render_constraint_element(label, value, options = {})
Render a label/value constraint on the screen.
-
- (Object) render_constraints(localized_params = params)
Render actual constraints, not including header or footer info.
- - (Object) render_constraints_filters(localized_params = params)
- - (Object) render_constraints_query(localized_params = params)
-
- (Object) render_search_to_s(params)
Simpler textual version of constraints, used on Search History page.
-
- (Object) render_search_to_s_element(key, value, options = {})
value can be Array, in which case elements are joined with ‘and’.
- - (Object) render_search_to_s_filters(params)
- - (Object) render_search_to_s_q(params)
Instance Method Details
- (Object) render_constraint_element(label, value, options = {})
Render a label/value constraint on the screen. Can be called by plugins and such to get application-defined rendering.
Can be over-ridden locally to render differently if desired, although in most cases you can just change CSS instead.
Can pass in nil label if desired.
options:
- :remove
url to execute for a ‘remove’ action
- :classes
can be an array of classes to add to container span for constraint.
- :escape_label
default true, HTML escape.
- :escape_value
default true, HTML escape.
69 70 71 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 69 def render_constraint_element(label, value, = {}) render(:partial => "catalog/constraints_element", :locals => {:label => label, :value => value, :options => }) end |
- (Object) render_constraints(localized_params = params)
Render actual constraints, not including header or footer info.
13 14 15 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 13 def render_constraints(localized_params = params) render_constraints_query(localized_params) + render_constraints_filters(localized_params) end |
- (Object) render_constraints_filters(localized_params = params)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 36 def render_constraints_filters(localized_params = params) return "" unless localized_params[:f] content = "" localized_params[:f].each_pair do |facet,values| values.each do |val| content << render_constraint_element( facet_field_labels[facet], val, :remove => catalog_index_path(remove_facet_params(facet, val, localized_params)), :classes => ["filter", "filter-" + facet.parameterize] ) + "\n" end end return content end |
- (Object) render_constraints_query(localized_params = params)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 17 def render_constraints_query(localized_params = params) # So simple don't need a view template, we can just do it here. if (!localized_params[:q].blank?) label = if (params[:search_field] == Blacklight.default_search_field[:key] or params[:search_field].blank? ) nil else Blacklight.label_for_search_field(params[:search_field]) end render_constraint_element(label, localized_params[:q], :classes => ["query"], :remove => catalog_index_path(localized_params.merge(:q=>nil, :action=>'index'))) else "" end end |
- (Object) render_search_to_s(params)
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.
78 79 80 81 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 78 def render_search_to_s(params) render_search_to_s_q(params) + render_search_to_s_filters(params) end |
- (Object) render_search_to_s_element(key, value, options = {})
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.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 108 def render_search_to_s_element(key, value, = {}) [:escape_value] = true unless .has_key?(:escape_value) [:escape_key] = true unless .has_key?(:escape_key) key = h(key) if [:escape_key] value = h(value) if [:escape_value] "<span class='constraint'>" + (key.blank? ? "" : "<span class='filterName'>#{key}:</span>") + "<span class='filterValue'>#{value}</span></span>" end |
- (Object) render_search_to_s_filters(params)
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 92 def render_search_to_s_filters(params) return "" unless params[:f] params[:f].collect do |facet_field, value_list| render_search_to_s_element(Blacklight.config[:facet][:labels][facet_field], value_list.collect do |value| "<span class='filterValue'>#{h(value)}</span>" end.join(" <span class='label'>and</span> "), :escape_value => false ) end.join(" \n ") end |
- (Object) render_search_to_s_q(params)
83 84 85 86 87 88 89 90 91 |
# File 'vendor/plugins/blacklight/app/helpers/render_constraints_helper.rb', line 83 def render_search_to_s_q(params) return "" if params[:q].blank? label = (params[:search_field] == Blacklight.default_search_field[:key]) ? nil : Blacklight.label_for_search_field(params[:search_field]) render_search_to_s_element(label , params[:q] ) end |