Class: Input::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/input.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Form

Create a new instance tied to an object and initialize output.

Parameters:

  • obj (Object)

    Sets the object for the form (if any)



25
26
27
28
# File 'lib/input.rb', line 25

def initialize(obj)
  @obj = obj
  @output = ''
end

Instance Attribute Details

#objObject (readonly)

The object related to the form, if any.



12
13
14
# File 'lib/input.rb', line 12

def obj
  @obj
end

#outputObject

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

Parameters:

  • obj (Object)

    Sets the object for the form (if any)



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

Yields:

  • (_self)

Yield Parameters:

  • _self (Input::Form)

    the object that the method was called on



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