Class: Kin::Form::Builder
- Inherits:
-
Merb::Helpers::Form::Builder::ResourcefulFormWithErrors
- Object
- Merb::Helpers::Form::Builder::ResourcefulFormWithErrors
- Kin::Form::Builder
- Defined in:
- lib/kin/form_builder.rb
Instance Method Summary collapse
-
#bound_date_field(method, attrs = {}) ⇒ Object
Creates a field for entering a date.
-
#bound_datetime_field(method, attrs = {}) ⇒ Object
Creates a field for entering both a date and time.
-
#bound_time_field(method, attrs = {}) ⇒ Object
Creates a field for entering both a time.
-
#label(contents, attrs = {}) ⇒ Object
A simple wrapper around the built-in label helper.
- #unbound_date_field(attrs) ⇒ Object
- #unbound_datetime_field(attrs) ⇒ Object
- #unbound_time_field(attrs) ⇒ Object
Instance Method Details
#bound_date_field(method, attrs = {}) ⇒ Object
Creates a field for entering a date.
- DD
- MM
- YYYY
27 28 29 30 31 32 |
# File 'lib/kin/form_builder.rb', line 27 def bound_date_field(method, attrs = {}) update_bound_controls(method, attrs, 'date') attrs[:value] = @obj.send(method) attrs[:name] ||= control_name(method) unbound_date_field(attrs) end |
#bound_datetime_field(method, attrs = {}) ⇒ Object
Creates a field for entering both a date and time.
- DD
- MM
- YYYY
-
at [HH]:
71 72 73 74 75 76 |
# File 'lib/kin/form_builder.rb', line 71 def bound_datetime_field(method, attrs = {}) update_bound_controls(method, attrs, 'datetime') attrs[:value] = @obj.send(method) attrs[:name] ||= control_name(method) unbound_datetime_field(attrs) end |
#bound_time_field(method, attrs = {}) ⇒ Object
Creates a field for entering both a time.
- HH]:[MM
49 50 51 52 53 54 |
# File 'lib/kin/form_builder.rb', line 49 def bound_time_field(method, attrs = {}) update_bound_controls(method, attrs, 'time') attrs[:value] = @obj.send(method) attrs[:name] ||= control_name(method) unbound_time_field(attrs) end |
#label(contents, attrs = {}) ⇒ Object
A simple wrapper around the built-in label helper. If the label content ends with an asterisk, it will be wrapped in a span such that it appears in red. Similarly, if the note ends with text in parenthesis, the text within will be wrapped in a .note span.
111 112 113 114 115 116 117 118 |
# File 'lib/kin/form_builder.rb', line 111 def label(contents, attrs = {}) if contents contents.sub!(/\*/, '<span class="req">*</span>') contents.sub!(/\((.*)\)/, '<span class="note">\1</span>') end super end |
#unbound_date_field(attrs) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kin/form_builder.rb', line 34 def unbound_date_field(attrs) datetime_label = create_datetime_label(attrs) field_opts = (attrs) %(#{ datetime_label } #{ generic_datetime_field(:day, field_opts[:day]) } #{ generic_datetime_field(:month, field_opts[:month]) } #{ generic_datetime_field(:year, field_opts[:year]) } #{ date_picker(attrs) }) end |
#unbound_datetime_field(attrs) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kin/form_builder.rb', line 78 def unbound_datetime_field(attrs) datetime_label = create_datetime_label(attrs) field_opts = (attrs) %(#{ datetime_label } #{ generic_datetime_field(:day, field_opts[:day]) } #{ generic_datetime_field(:month, field_opts[:month]) } #{ generic_datetime_field(:year, field_opts[:year]) } <span class="field at">at</span> #{ generic_datetime_field(:hour, field_opts[:hour]) } <span class="field timesep">:</span> #{ generic_datetime_field(:minute, field_opts[:minute]) } #{ date_picker(attrs) }) end |
#unbound_time_field(attrs) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/kin/form_builder.rb', line 56 def unbound_time_field(attrs) datetime_label = create_datetime_label(attrs, 'hour') field_opts = (attrs) %(#{ datetime_label } #{ generic_datetime_field(:hour, field_opts[:hour]) } <span class="field timesep">:</span> #{ generic_datetime_field(:minute, field_opts[:minute]) } #{ date_picker(attrs) }) end |