Module: Formation::Form::ClassMethods
- Defined in:
- lib/formation/form.rb
Instance Method Summary collapse
- #elements ⇒ Object
- #field(name, options = {}) ⇒ Object
- #fields ⇒ Object
- #fieldset(name, options = {}) ⇒ Object
- #fieldsets ⇒ Object
- #resource(resource) ⇒ Object
- #resources ⇒ Object
- #validates_with_method(method_name) ⇒ Object
- #validators ⇒ Object
Instance Method Details
#elements ⇒ Object
5 6 7 |
# File 'lib/formation/form.rb', line 5 def elements @elements ||= [] end |
#field(name, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/formation/form.rb', line 9 def field(name, = {}) @_current_resource ||= nil @_current_fieldset ||= nil if @_current_resource name = "#{@_current_resource}[#{name}]" else name = name.to_s end fields[name] = Formation::Field.new(name, { :fieldset => @_current_fieldset }.merge()) elements << fields[name] unless @_current_fieldset end |
#fields ⇒ Object
21 22 23 |
# File 'lib/formation/form.rb', line 21 def fields @fields ||= {} end |
#fieldset(name, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/formation/form.rb', line 25 def fieldset(name, = {}) if name.is_a? Hash = name name = Formation::Util.underscore([:legend]) end @_current_fieldset = (fieldsets[name] ||= Formation::Fieldset.new(name, )) elements << @_current_fieldset yield @_current_fieldset = nil end |
#fieldsets ⇒ Object
36 37 38 |
# File 'lib/formation/form.rb', line 36 def fieldsets @fieldsets ||= {} end |
#resource(resource) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/formation/form.rb', line 40 def resource(resource) resources << resource class_eval <<-RUBY attr_accessor :#{resource} RUBY if block_given? @_current_resource = resource yield @_current_resource = nil end end |
#resources ⇒ Object
52 53 54 |
# File 'lib/formation/form.rb', line 52 def resources @resources ||= [] end |
#validates_with_method(method_name) ⇒ Object
56 57 58 59 |
# File 'lib/formation/form.rb', line 56 def validates_with_method(method_name) method_name = method_name.to_sym validators << method_name end |
#validators ⇒ Object
61 62 63 |
# File 'lib/formation/form.rb', line 61 def validators @validators ||= [] end |