Class: BlockHTML::Form::Tag

Inherits:
Tag show all
Defined in:
lib/block-html/form.rb

Instance Attribute Summary

Attributes inherited from Tag

#attrs

Attributes inherited from BlockHTML

#parent

Instance Method Summary collapse

Methods inherited from Tag

#render

Methods inherited from BlockHTML

#<<, #_p, #doctype, #each, #empty?, #escaped_text, #form, #method_missing, #p, #path, #render, #root, #text, #to_s, #xml

Constructor Details

#initialize(model, name, attrs = {}, env_instance = nil, &block) ⇒ Tag

Returns a new instance of Tag.



12
13
14
15
# File 'lib/block-html/form.rb', line 12

def initialize(model, name, attrs={}, env_instance=nil, &block)
  @model = model
  super(name, attrs, env_instance, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BlockHTML

Instance Method Details

#checkbox(name, attrs = {}) ⇒ Object



73
74
75
76
77
78
# File 'lib/block-html/form.rb', line 73

def checkbox(name, attrs={})
  self << Element::Checkbox.new(
    @model,
    attrs.merge(:name => name, :type => :checkbox)
  )
end

#edit(name, attrs = {}) ⇒ Object



37
38
39
40
41
42
# File 'lib/block-html/form.rb', line 37

def edit(name, attrs={})
  self << Element::Input.new(
    @model,
    attrs.merge(:name => name, :type => :text)
  )
end

#errors(name, params = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/block-html/form.rb', line 27

def errors(name, params={})
  return if @model.nil? || @model.errors[name].empty?

  tag(:div, params) {
    @model.errors.on(name).each do |val|
      tag(:p).text(val)
    end
  }
end

#model(model, &block) ⇒ Object



21
22
23
24
25
# File 'lib/block-html/form.rb', line 21

def model(model, &block)
  @model = model
  block.call(self)
  @model = nil
end

#password(name, attrs = {}) ⇒ Object



44
45
46
47
48
49
# File 'lib/block-html/form.rb', line 44

def password(name, attrs={})
  self << Element::Password.new(
    @model,
    attrs.merge(:name => name, :type => :password)
  )
end

#tag(tag, attrs = {}, &block) ⇒ Object



17
18
19
# File 'lib/block-html/form.rb', line 17

def tag(tag, attrs={}, &block)
  self << Tag.new(@model, tag, attrs, @env_instance, &block)
end