Class: DataMapper::Form::Base
- Inherits:
-
Object
- Object
- DataMapper::Form::Base
- Includes:
- Tag
- Defined in:
- lib/dm-forms/base.rb
Constant Summary collapse
- REGULAR_ELEMENTS =
:textarea, :select
- SELF_CLOSING_ELEMENTS =
:textfield, :submit, :file, :button, :hidden, :password, :radio, :checkbox
- DEFAULT_VALUE_ELEMENTS =
:textarea, :select, :textfield, :radio, :checkbox
Constants included from Tag
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
Instance Method Summary collapse
- #fieldset(attrs = {}, &block) ⇒ Object
- #form(attrs = {}, &block) ⇒ Object
-
#initialize(model = nil, origin = nil) ⇒ Base
constructor
A new instance of Base.
- #select_options(options, selected = nil, prompt = nil) ⇒ Object
- #unbound_select(attrs = {}) ⇒ Object
- #unbound_textarea(*args) ⇒ Object
Methods included from Tag
#close_tag, #open_tag, #self_closing_tag, #tag
Constructor Details
#initialize(model = nil, origin = nil) ⇒ Base
Returns a new instance of Base.
14 15 16 17 |
# File 'lib/dm-forms/base.rb', line 14 def initialize model = nil, origin = nil @model, @origin = model, origin @name = model.class.name.downcase.split('::').last end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
12 13 14 |
# File 'lib/dm-forms/base.rb', line 12 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/dm-forms/base.rb', line 12 def name @name end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
12 13 14 |
# File 'lib/dm-forms/base.rb', line 12 def origin @origin end |
Instance Method Details
#fieldset(attrs = {}, &block) ⇒ Object
26 27 28 29 |
# File 'lib/dm-forms/base.rb', line 26 def fieldset attrs = {}, &block legend_tag = (legend = attrs.delete(:legend)) ? tag(:legend, legend) : '' origin.buffer << tag(:fieldset, legend_tag + origin.capture(&block), attrs) end |
#form(attrs = {}, &block) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/dm-forms/base.rb', line 19 def form attrs = {}, &block origin.clear_buffer captured = origin.capture &block faux_method = process_form_attrs attrs tag :form, faux_method + captured, attrs end |
#select_options(options, selected = nil, prompt = nil) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dm-forms/base.rb', line 31 def , selected = nil, prompt = nil [''] = prompt unless prompt.nil? selected ||= prompt || nil .map do |value, contents| tag :option, contents, :value => value, :selected => (value == selected or contents == selected) end.join("\n") end |
#unbound_select(attrs = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/dm-forms/base.rb', line 45 def unbound_select attrs = {} = *attrs.extract!(:options, :selected, :prompt) process_unbound_element :select, attrs origin.buffer << tag(:select, , attrs) end |
#unbound_textarea(*args) ⇒ Object
39 40 41 42 43 |
# File 'lib/dm-forms/base.rb', line 39 def unbound_textarea *args contents, attrs = split_args *args process_unbound_element :textarea, attrs origin.buffer << tag(:textarea, element_value(attrs) || contents, attrs) end |