Class: Filtrate::FilterBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::FormTagHelper
Defined in:
lib/filtrate/filter_builder.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



35
36
# File 'lib/filtrate/filter_builder.rb', line 35

def method_missing(method, *args)
end

Instance Method Details

#date_field(type, attr, value, opts) ⇒ Object



27
28
29
# File 'lib/filtrate/filter_builder.rb', line 27

def date_field(type, attr, value, opts)
  text_field_tag("filters[#{attr}][#{type}]", value, opts)
end

#date_field_set(type, attr, label_options = {}, value = "", text_field_opts = {}) ⇒ Object



19
20
21
# File 'lib/filtrate/filter_builder.rb', line 19

def date_field_set(type, attr, label_options={}, value="", text_field_opts={})
  date_label(type, attr, label_options) + date_field(type, attr, value, text_field_opts)
end

#date_label(type, attr, opts = {}) ⇒ Object



23
24
25
# File 'lib/filtrate/filter_builder.rb', line 23

def date_label(type, attr, opts={})
  label_tag("filters[#{attr}][#{type}]", "#{opts[:prefix]} #{opts[type].try(:humanize)}".strip)
end

#filter(attr, name = nil, value = "", text_field_opts = {}) ⇒ Object



7
8
9
# File 'lib/filtrate/filter_builder.rb', line 7

def filter(attr, name=nil, value="", text_field_opts={})
  label_tag("filters[#{attr}]", (name || attr.to_s.humanize)) + text_field_tag("filters[#{attr}]", value, text_field_opts)
end

#filter_date(attr, label_options = {}, value = "", text_field_options = {}) ⇒ Object

FIXME: Date field stuff is very messy.



12
13
14
15
16
17
# File 'lib/filtrate/filter_builder.rb', line 12

def filter_date(attr, label_options={}, value="", text_field_options={})
  label_options[:prefix] ||= nil
  label_options[:from] ||= "From"
  label_options[:to] ||= "To"
  [:to, :from].map {|type| date_field_set(type, attr, label_options, value, text_field_options) }.join('').html_safe
end

#submit(value = "Save changes", options = {}) ⇒ Object



31
32
33
# File 'lib/filtrate/filter_builder.rb', line 31

def submit(value="Save changes", options={})
  submit_tag(value, options)
end