Module: WithFilters::ActionViewExtension
- Defined in:
- lib/with_filters/action_view_extension.rb
Instance Method Summary collapse
-
#filter_form_for(records, options = {}) {|filter_form| ... } ⇒ Object
Create a filter form.
- #with_filters_action_tag(action) ⇒ Object
-
#with_filters_hidden(hidden_filters) ⇒ Object
Create hidden inputs.
-
#with_filters_input(filter) ⇒ Object
Create an input based on the type of
filterprovided. -
#with_filters_label(filter) ⇒ Object
Create a
labeltag for individual fields or adivtag in its place in the case of fields where thelabeltags are used for individual items. -
#with_filters_label_tag(filter) ⇒ Object
Create a
labeltag based on thefilter. -
#with_filters_select_tag(filter) ⇒ Object
Create a
selecttag based on thefilter. -
#with_filters_text_field_tag(filter) ⇒ Object
Create an text like
inputtag based on thefilter.
Instance Method Details
#filter_form_for(records, options = {}) {|filter_form| ... } ⇒ Object
Create a filter form.
20 21 22 23 24 25 |
# File 'lib/with_filters/action_view_extension.rb', line 20 def filter_form_for(records, = {}) filter_form = WithFilters::FilterForm.new(records, self.extract_hash_value(params, records.with_filters_data[:param_namespace]) || {}, ) yield(filter_form) render(partial: filter_form.to_partial_path, locals: {filter_form: filter_form}) end |
#with_filters_action_tag(action) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/with_filters/action_view_extension.rb', line 101 def with_filters_action_tag(action) case action.type when :submit submit_tag(action.attrs.delete(:value), action.attrs) when :reset (action.attrs.delete(:value) || 'Reset', action.attrs) end end |
#with_filters_hidden(hidden_filters) ⇒ Object
Create hidden inputs.
32 33 34 35 36 |
# File 'lib/with_filters/action_view_extension.rb', line 32 def with_filters_hidden(hidden_filters) hidden_filters.map{|hidden_filter| hidden_field_tag(hidden_filter.field_name, hidden_filter.value, hidden_filter.attrs) }.join("\n").html_safe end |
#with_filters_input(filter) ⇒ Object
Create an input based on the type of filter provided.
43 44 45 |
# File 'lib/with_filters/action_view_extension.rb', line 43 def with_filters_input(filter) render(partial: filter.to_partial_path, locals: {filter: filter}) end |
#with_filters_label(filter) ⇒ Object
Create a label tag for individual fields or a div tag in its place in
the case of fields where the label tags are used for individual items.
71 72 73 74 75 76 77 |
# File 'lib/with_filters/action_view_extension.rb', line 71 def with_filters_label(filter) if [WithFilters::Filter::Radio, WithFilters::Filter::CheckBox].include?(filter.class) and filter.collection.any? content_tag(:div, filter.label, filter.label_attrs) else with_filters_label_tag(filter) end end |
#with_filters_label_tag(filter) ⇒ Object
Create a label tag based on the filter.
61 62 63 |
# File 'lib/with_filters/action_view_extension.rb', line 61 def with_filters_label_tag(filter) label_tag(filter.field_name, filter.label, filter.label_attrs) end |
#with_filters_select_tag(filter) ⇒ Object
Create a select tag based on the filter.
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/with_filters/action_view_extension.rb', line 84 def with_filters_select_tag(filter) collection = filter.collection unless filter.collection.is_a?(String) collection = filter.collection.map do |choice| html_attributes = choice.attrs.length > 0 ? ' ' + choice.attrs.map {|k, v| %(#{k.to_s}="#{v}")}.join(' ') : '' selected_attribute = choice.selected? ? ' selected="selected"' : '' %(<option value="#{ERB::Util.html_escape(choice.value)}"#{selected_attribute}#{html_attributes}>#{ERB::Util.html_escape(choice.label)}</option>) end.join("\n") end select_tag(filter.field_name, collection.html_safe, filter.attrs) end |
#with_filters_text_field_tag(filter) ⇒ Object
Create an text like input tag based on the filter.
52 53 54 |
# File 'lib/with_filters/action_view_extension.rb', line 52 def with_filters_text_field_tag(filter) text_field_tag(filter.field_name, filter.value, filter.attrs) end |