Class: Megatron::Form
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Megatron::Form
- Defined in:
- lib/megatron/form.rb
Instance Attribute Summary collapse
-
#style ⇒ Object
Returns the value of attribute style.
Instance Method Summary collapse
-
#initialize(object_name, object, template, options) ⇒ Form
constructor
A new instance of Form.
- #method_missing(method, *args, &block) ⇒ Object
- #password_field(method, options = {}) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
- #stacked_form(&block) ⇒ Object
- #submit(btn_text, args = {}) ⇒ Object
- #table_form(&block) ⇒ Object
- #text_area(method, options = {}) ⇒ Object
- #text_field(method, options = {}) ⇒ Object
Constructor Details
#initialize(object_name, object, template, options) ⇒ Form
Returns a new instance of Form.
6 7 8 9 |
# File 'lib/megatron/form.rb', line 6 def initialize(object_name, object, template, ) super @style = .delete(:style) || "table" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
65 66 67 |
# File 'lib/megatron/form.rb', line 65 def method_missing(method, *args, &block) @template.send(method, *args, &block) end |
Instance Attribute Details
#style ⇒ Object
Returns the value of attribute style.
4 5 6 |
# File 'lib/megatron/form.rb', line 4 def style @style end |
Instance Method Details
#password_field(method, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/megatron/form.rb', line 28 def password_field(method, = {}) if errors_on?(method) [:class] ||= "" [:class] += " error" end wrapper method, .delete(:label) || method.to_s.humanize, super(method, ) end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/megatron/form.rb', line 46 def select(method, choices = nil, = {}, = {}, &block) if errors_on?(method) [:class] ||= "" [:class] += " error" end field = content_tag(:div, class: 'select_box') { super(method, choices, , , &block) } wrapper method, .delete(:label) || method.to_s.humanize, field end |
#stacked_form(&block) ⇒ Object
11 12 13 |
# File 'lib/megatron/form.rb', line 11 def stacked_form(&block) content_tag :div, class: 'stacked-form', &block end |
#submit(btn_text, args = {}) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/megatron/form.rb', line 57 def submit(btn_text, args = {}) text = "<footer class='form-footer'>".html_safe text << (btn_text, {class: "primary-btn"}.merge(args)) text << "</footer>".html_safe text end |
#table_form(&block) ⇒ Object
15 16 17 |
# File 'lib/megatron/form.rb', line 15 def table_form(&block) content_tag :div, class: ['table', 'table-form'], &block end |
#text_area(method, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/megatron/form.rb', line 37 def text_area(method, = {}) if errors_on?(method) [:class] ||= "" [:class] += " error" end wrapper method, .delete(:label) || method.to_s.humanize, super(method, ) end |
#text_field(method, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/megatron/form.rb', line 19 def text_field(method, = {}) if errors_on?(method) [:class] ||= "" [:class] += " error" end wrapper method, .delete(:label) || method.to_s.humanize, super(method, ) end |