Class: TblForm::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- TblForm::FormBuilder
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/tbl_form/form_builder.rb
Instance Method Summary collapse
- #back(method = '', options = {}) ⇒ Object
-
#button(type, *args, &block) ⇒ Object
Creates a button:.
- #calendar_field(method, options = {}) ⇒ Object
- #check_box(method, options = {}) ⇒ Object
- #date_select(method, options = {}) ⇒ Object
- #display(method, options = {}) ⇒ Object
- #file_field(method, options = {}) ⇒ Object
- #front(method = '', options = {}) ⇒ Object
-
#label(method, options = {}) ⇒ Object
Generates a label.
- #password_field(method, options = {}) ⇒ Object
- #radio_button(method, tag_value, options = {}) ⇒ Object
- #select(method, choices, options = {}, html_options = {}) ⇒ Object
- #submit(value = "Submit", options = {}) ⇒ Object
- #text_area(method, options = {}) ⇒ Object
- #text_field(method, options = {}) ⇒ Object
- #value(method, options = {}) ⇒ Object
Instance Method Details
#back(method = '', options = {}) ⇒ Object
126 127 128 |
# File 'lib/tbl_form/form_builder.rb', line 126 def back method = '', = {} "</td></tr>".html_safe end |
#button(type, *args, &block) ⇒ Object
Creates a button:
form_for @user do |f|
f. :submit
end
It just acts as a proxy to method name given.
14 15 16 17 18 19 20 |
# File 'lib/tbl_form/form_builder.rb', line 14 def (type, *args, &block) if respond_to?(:"#{type}_button") send(:"#{type}_button", *args, &block) else send(type, *args, &block) end end |
#calendar_field(method, options = {}) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/tbl_form/form_builder.rb', line 101 def calendar_field method, = {} . expired = .delete(:expired) || false if not expired; .merge!(:class => 'calendar'); else; .merge!(:disabled => true); end text_field method, end |
#check_box(method, options = {}) ⇒ Object
88 89 90 91 |
# File 'lib/tbl_form/form_builder.rb', line 88 def check_box method, = {} . front(method, ) + super + back(method, ) end |
#date_select(method, options = {}) ⇒ Object
108 109 110 111 |
# File 'lib/tbl_form/form_builder.rb', line 108 def date_select method, = {} . front(method, ) + super + back(method, ) end |
#display(method, options = {}) ⇒ Object
53 54 55 56 |
# File 'lib/tbl_form/form_builder.rb', line 53 def display(method, = {}) . front(method, ) + ("<span class=\"ms_field_content\">#{method.is_a?(String) ? method.to_s : @object[method.to_s]}</span>").html_safe + back(method, ) end |
#file_field(method, options = {}) ⇒ Object
78 79 80 81 |
# File 'lib/tbl_form/form_builder.rb', line 78 def file_field method, = {} . front(method, ) + super + back(method, ) end |
#front(method = '', options = {}) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/tbl_form/form_builder.rb', line 119 def front method = '', = {} fieldstyle = .delete(:fieldstyle) || "" fieldstyle += " width: #{.delete(:fieldwidth) || "100%"};" fieldextra = .delete(:fieldextra) || "" "<tr class=\"tbl_field\", style=\"#{fieldstyle}\"><th class=\"tbl_field_label\">#{fieldextra}#{label(method, )}</th><td>".html_safe end |
#label(method, options = {}) ⇒ Object
Generates a label
If options
includes :for, that is used as the :for of the label. Otherwise, “#form’s object name_#method” is used.
If options
includes :label, that value is used for the text of the label. Otherwise, “#titleized: ” is used.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tbl_form/form_builder.rb', line 31 def label method, = {} text = .delete(:label) || "#{method.to_s.titleize}: " hint = .delete(:hint) || "" text = text + " <span class=\"ms_hint\">#{hint}</span>" unless hint.blank? if [:for] "<label class=\"ms_label\" for='#{.delete(:for)}'>#{text}</label>" else #need to use InstanceTag to build the correct ID for :for ActionView::Helpers::InstanceTag.new(@object_name, method, self, @object).to_label_tag(text, {:class=>"ms_label"}) end end |
#password_field(method, options = {}) ⇒ Object
73 74 75 76 |
# File 'lib/tbl_form/form_builder.rb', line 73 def password_field method, = {} . front(method, ) + super + back(method, ) end |
#radio_button(method, tag_value, options = {}) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/tbl_form/form_builder.rb', line 93 def method, tag_value, = {} . fieldstyle = .delete(:fieldstyle) || "" fieldstyle += " width: #{.delete(:fieldwidth) || "100%"};" fieldextra = .delete(:fieldextra) || "" front(method, ) + super + back(method, ) end |
#select(method, choices, options = {}, html_options = {}) ⇒ Object
58 59 60 61 |
# File 'lib/tbl_form/form_builder.rb', line 58 def select method, choices, = {}, = {} . front(method, ) + super + back(method, ) end |
#submit(value = "Submit", options = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/tbl_form/form_builder.rb', line 43 def submit(value = "Submit", = {}) text = .delete(:label) || value tag_str = tag( :input, { "type" => "submit", "name" => "commit", "value" => text }.update(.stringify_keys) ) output = "<br /><div class=\"button_bar\">#{ tag_str }</div>".html_safe end |
#text_area(method, options = {}) ⇒ Object
83 84 85 86 |
# File 'lib/tbl_form/form_builder.rb', line 83 def text_area method, = {} . front(method, ) + super + back(method, ) end |
#text_field(method, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/tbl_form/form_builder.rb', line 63 def text_field method, = {} . naked = .delete(:naked) || false if naked super else front(method, ) + super + back(method, ) end end |
#value(method, options = {}) ⇒ Object
49 50 51 |
# File 'lib/tbl_form/form_builder.rb', line 49 def value(method, = {}) @object[method.to_s] end |