Class: Input::Form
- Inherits:
-
Object
- Object
- Input::Form
- Defined in:
- lib/input.rb
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
The object related to the form, if any.
-
#output ⇒ Object
the final output of the form being built.
Class Method Summary collapse
-
.begin(obj, attributes = {}, &block) ⇒ Object
Create a form object and yeild to block.
Instance Method Summary collapse
-
#build(tag) {|_self| ... } ⇒ Object
Create input tag, build it, and yield to block if needed.
-
#initialize(obj) ⇒ Form
constructor
Create a new instance tied to an object and initialize output.
-
#input(type, attributes = {}, &block) ⇒ Object
Create input tag, build it, and yield to block if needed.
-
#tag(type, attributes = {}, &block) ⇒ Object
Create a tag, build it, and yield to block if needed.
Constructor Details
#initialize(obj) ⇒ Form
Create a new instance tied to an object and initialize output.
25 26 27 28 |
# File 'lib/input.rb', line 25 def initialize(obj) @obj = obj @output = '' end |
Instance Attribute Details
#obj ⇒ Object (readonly)
The object related to the form, if any.
12 13 14 |
# File 'lib/input.rb', line 12 def obj @obj end |
#output ⇒ Object
the final output of the form being built
15 16 17 |
# File 'lib/input.rb', line 15 def output @output end |
Class Method Details
.begin(obj, attributes = {}, &block) ⇒ Object
Create a form object and yeild to block
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/input.rb', line 37 def self.begin(obj, attributes={}, &block) # build form object form = new(obj) # construct form form.build(Tag.new(self, :form, attributes), &block) # return final output form.output end |
Instance Method Details
#build(tag) {|_self| ... } ⇒ Object
Create input tag, build it, and yield to block if needed
70 71 72 73 74 |
# File 'lib/input.rb', line 70 def build(tag, &block) @output << tag.open yield self if block_given? @output << tag.close end |
#input(type, attributes = {}, &block) ⇒ Object
Create input tag, build it, and yield to block if needed
61 62 63 64 |
# File 'lib/input.rb', line 61 def input(type, attributes={}, &block) tag = Input.new(self, type, attributes) build(tag, &block) end |
#tag(type, attributes = {}, &block) ⇒ Object
Create a tag, build it, and yield to block if needed
52 53 54 55 |
# File 'lib/input.rb', line 52 def tag(type, attributes={}, &block) tag = Tag.new(self, type, attributes) build(tag, &block) end |