Class: Reformed::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Reformed::FormBuilder
- Includes:
- ActionView::Helpers::OutputSafetyHelper
- Defined in:
- lib/reformed/form_builder.rb
Constant Summary collapse
- @@html5 =
true
- @@input_wrapper =
lambda { |controls, | "<div class=\"input-control\">#{controls[:label]} #{controls[:input]} #{controls[:error]} #{controls[:hint]}</div>" }
- @@label_wrapper =
lambda { |controls, | "<span>#{controls[:label]}</span>" }
- @@hint_wrapper =
lambda { |, | "<span class=\"hint\">#{}</span>" }
- @@error_wrapper =
lambda { |, | "<span class=\"error\">#{}</span>" }
Instance Method Summary collapse
- #error_wrap(str, options, &block) ⇒ Object
- #hint_wrap(str, options, &block) ⇒ Object
- #html5? ⇒ Boolean
- #input(method, options = {}, &block) ⇒ Object
- #input_wrap(method, options, &block) ⇒ Object
- #label_wrap(method, options = {}, &block) ⇒ Object
- #reform_fields_for(record_or_name_or_array, *args, &block) ⇒ Object
Instance Method Details
#error_wrap(str, options, &block) ⇒ Object
80 81 82 |
# File 'lib/reformed/form_builder.rb', line 80 def error_wrap(str, , &block) @@error_wrapper.call(str, ) end |
#hint_wrap(str, options, &block) ⇒ Object
76 77 78 |
# File 'lib/reformed/form_builder.rb', line 76 def hint_wrap(str, , &block) @@hint_wrapper.call(str, ) end |
#html5? ⇒ Boolean
90 91 92 |
# File 'lib/reformed/form_builder.rb', line 90 def html5? @@html5 end |
#input(method, options = {}, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/reformed/form_builder.rb', line 25 def input(method, = {}, &block) controls = {} if [:hint] controls[:hint] = hint_wrap(.delete(:hint), ()) end if [:error] controls[:error] = error_wrap(.delete(:error), ()) end controls[:label] = label_wrap(method, (.merge(method: method), :label)) controls[:input] = input_wrap(method, ()) raw @@input_wrapper.call(controls, ) end |
#input_wrap(method, options, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/reformed/form_builder.rb', line 43 def input_wrap(method, , &block) whatami = [:as] || as(method) .delete(:as) case whatami when :string then text_field method, when :text then text_area method, when :file then file_field method, when :string then text_field method, when :password then password_field method, when :radio then method, [:choices], when :boolean then check_box method, when :url then url_field method, when :email then email_field method, when :phone then phone_field method, when :number then number_field method, when :date then date_select method, , .delete(:html) || {} when :time then time_select method, , .delete(:html) || {} when :datetime then datetime_select method, , .delete(:html) || {} when :select then select method, [:choices], , .delete(:html) || {} when :hidden then hidden_field method, end end |
#label_wrap(method, options = {}, &block) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/reformed/form_builder.rb', line 67 def label_wrap(method, = {}, &block) label_text = .delete(:label) if [:label] if label_text @@label_wrapper.call({label: label(method, label_text, , &block)}, ) else @@label_wrapper.call({label: label(method, [:label], &block)}, ) end end |
#reform_fields_for(record_or_name_or_array, *args, &block) ⇒ Object
84 85 86 87 88 |
# File 'lib/reformed/form_builder.rb', line 84 def reform_fields_for(record_or_name_or_array, *args, &block) = args. [:builder] ||= self.class fields_for(record_or_name_or_array, *(args << ), &block) end |