Module: Rocketeer::Helpers::Form
- Defined in:
- lib/rocketeer/helpers/form.rb
Instance Method Summary collapse
-
#checkbox(name, options = {}) ⇒ String
Checkbox.
-
#email_field(name, options = {}) ⇒ Object
Email field builder.
-
#input_field(name, options = {}) ⇒ Object
Input field builder.
-
#label(text, options = {}) ⇒ String
Label tag builder.
-
#password_field(name, options = {}) ⇒ Object
Password field builder.
-
#radio_button(name, options = {}) ⇒ String
Radio button.
-
#select_box(name, rows, selected = nil) ⇒ Object
Select box builder.
-
#submit_button(text, options = {}) ⇒ String
Creates a submit button (using <button>).
-
#text_field(name, options = {}) ⇒ Object
Text field builder.
-
#textarea(name, options = {}) ⇒ Object
Text area builder.
Instance Method Details
#checkbox(name, options = {}) ⇒ String
Checkbox
153 154 155 156 157 158 |
# File 'lib/rocketeer/helpers/form.rb', line 153 def checkbox(name, = {}) if .key?(:checked) .delete(:checked) if ![:checked] end input_field name, .merge({ :type => 'checkbox' }) end |
#email_field(name, options = {}) ⇒ Object
Email field builder
@example:
email_field :my_field, :class => 'text', :value => 'my value'
110 111 112 |
# File 'lib/rocketeer/helpers/form.rb', line 110 def email_field(name, = {}) input_field name, .merge({:type => 'email'}) end |
#input_field(name, options = {}) ⇒ Object
Input field builder
@example:
input_field :my_field, :type => 'text'
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rocketeer/helpers/form.rb', line 53 def input_field(name, = {}) = { :name => _name(name).to_s }.merge() # If the ID is not set, use the field name if !.key? :id [:id] = _id(name).to_s end # Remove the ID if it's false .delete(:id) if [:id] === false "<input#{HTML.attributes()}>" end |
#label(text, options = {}) ⇒ String
Label tag builder
@author: Jack Polgar @example:
label 'Username', :for => :username
37 38 39 40 |
# File 'lib/rocketeer/helpers/form.rb', line 37 def label(text, = {}) [:for] = _id([:for]) if [:for] "<label#{HTML.attributes()}>#{text}</label>" end |
#password_field(name, options = {}) ⇒ Object
Password field builder
@example:
pasword_field :my_field, :class => 'text', :value => 'my value'
95 96 97 |
# File 'lib/rocketeer/helpers/form.rb', line 95 def password_field(name, = {}) input_field name, .merge({:type => 'password'}) end |
#radio_button(name, options = {}) ⇒ String
Radio button
170 171 172 |
# File 'lib/rocketeer/helpers/form.rb', line 170 def (name, = {}) input_field name, .merge({ :type => 'radio', :id => false }) end |
#select_box(name, rows, selected = nil) ⇒ Object
Select box builder
@example:
select_box :my_field, [['Hello', 1], ['World', 2]], 2
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rocketeer/helpers/form.rb', line 126 def select_box(name, rows, selected = nil) name = _name(name) html = ["<select name=\"#{name.to_s}\" id=\"#{_id(name).to_s}\">"] rows.each do |row| if row[1] == selected selected_html = ' selected' else selected_html = '' end html.push " <option value=\"#{row[1]}\"#{selected_html}>#{row[0]}</option>" end html.push "</select>\n" return html.join("\n") end |
#submit_button(text, options = {}) ⇒ String
Creates a submit button (using <button>)
212 213 214 |
# File 'lib/rocketeer/helpers/form.rb', line 212 def (text, = {}) "<button type=\"submit\"#{HTML.attributes()}>#{text}</button>" end |
#text_field(name, options = {}) ⇒ Object
Text field builder
@example:
text_field :my_field, :class => 'text', :value => 'my value'
80 81 82 |
# File 'lib/rocketeer/helpers/form.rb', line 80 def text_field(name, = {}) input_field name, .merge({:type => 'text'}) end |
#textarea(name, options = {}) ⇒ Object
Text area builder
@example:
textarea :my_field, :class => 'text', :value => 'my value'
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/rocketeer/helpers/form.rb', line 185 def textarea(name, = {}) = { :id => _id(name).to_s, :name => _name(name).to_s }.merge() if [:value] value = [:value] [:value] = nil else value = '' end "<textarea#{HTML.attributes()}>#{value}</textarea>" end |