Module: Blacklight::RenderConstraintsHelperBehavior
- Included in:
- RenderConstraintsHelper
- Defined in:
- app/helpers/blacklight/render_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 contraints graphically on the search results page (render_constraints(_*))
Instance Method Summary (collapse)
- - (Boolean) query_has_constraints?(localized_params = params)
-
- (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_filter_element(facet, values, localized_params)
Instance Method Details
- (Boolean) query_has_constraints?(localized_params = params)
10 11 12 |
# File 'app/helpers/blacklight/render_constraints_helper_behavior.rb', line 10 def query_has_constraints?(localized_params = params) !(localized_params[:q].blank? and localized_params[:f].blank?) end |
- (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.
79 80 81 |
# File 'app/helpers/blacklight/render_constraints_helper_behavior.rb', line 79 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.
16 17 18 |
# File 'app/helpers/blacklight/render_constraints_helper_behavior.rb', line 16 def render_constraints(localized_params = params) (render_constraints_query(localized_params) + render_constraints_filters(localized_params)).html_safe end |
- (Object) render_constraints_filters(localized_params = params)
39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/blacklight/render_constraints_helper_behavior.rb', line 39 def render_constraints_filters(localized_params = params) return "".html_safe unless localized_params[:f] content = [] localized_params[:f].each_pair do |facet,values| content << render_filter_element(facet, values, localized_params) end return content.flatten.join("\n").html_safe end |
- (Object) render_constraints_query(localized_params = params)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/blacklight/render_constraints_helper_behavior.rb', line 20 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 (localized_params[:search_field].blank? || (default_search_field && localized_params[:search_field] == default_search_field[:key] ) ) nil else label_for_search_field(localized_params[:search_field]) end render_constraint_element(label, localized_params[:q], :classes => ["query"], :remove => url_for(localized_params.merge(:q=>nil, :action=>'index'))) else "".html_safe end end |
- (Object) render_filter_element(facet, values, localized_params)
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/helpers/blacklight/render_constraints_helper_behavior.rb', line 49 def render_filter_element(facet, values, localized_params) facet_config = facet_configuration_for_field(facet) values.map do |val| render_constraint_element( facet_field_labels[facet], facet_display_value(facet, val), :remove => url_for(remove_facet_params(facet, val, localized_params)), :classes => ["filter", "filter-" + facet.parameterize] ) + "\n" end end |