Module: DataMapper::Form::Tag
- Included in:
- Base
- Defined in:
- lib/dm-forms/tag.rb
Constant Summary collapse
- BOOL_ATTRIBUTES =
– Borrowed / adapted from Merb ++
:selected, :checked, :multiple
Instance Method Summary collapse
-
#close_tag(name) ⇒ Object
Creates a closing tag.
-
#open_tag(name, attrs = {}) ⇒ Object
Creates the opening tag with attributes for the provided
nameattrs is a hash where all members will be mapped to key=“value”. -
#self_closing_tag(name, attrs = {}) ⇒ Object
Creates a self closing tag.
-
#tag(name, contents = nil, attrs = {}, &block) ⇒ Object
Creates a generic tag.
Instance Method Details
#close_tag(name) ⇒ Object
Creates a closing tag
57 58 59 |
# File 'lib/dm-forms/tag.rb', line 57 def close_tag name "</#{name}>\n" end |
#open_tag(name, attrs = {}) ⇒ Object
Creates the opening tag with attributes for the provided name attrs is a hash where all members will be mapped to key=“value”
Note: This tag will need to be closed
50 51 52 |
# File 'lib/dm-forms/tag.rb', line 50 def open_tag name, attrs = {} "<#{name}#{optional_attrs(attrs)}>" end |
#self_closing_tag(name, attrs = {}) ⇒ Object
Creates a self closing tag. Like <br/> or <img src=“…”/>
name : the name of the tag to create attrs : a hash where all members will be mapped to key=“value”
67 68 69 |
# File 'lib/dm-forms/tag.rb', line 67 def self_closing_tag name, attrs = {} "<#{name}#{optional_attrs(attrs)}/>\n" end |
#tag(name, contents = nil, attrs = {}, &block) ⇒ Object
Creates a generic tag. You can invoke it a variety of ways.
tag :div
# <div></div>
tag :div, 'content'
# <div>content</div>
tag :div, :class => 'class'
# <div class="class"></div>
tag :div, 'content', :class => 'class'
# <div class="class">content</div>
tag :div do
'content'
end
# <div>content</div>
tag :div, :class => 'class' do
'content'
end
# <div class="class">content</div>
38 39 40 41 42 |
# File 'lib/dm-forms/tag.rb', line 38 def tag name, contents = nil, attrs = {}, &block attrs, contents = contents, nil if contents.is_a? Hash contents = yield if block_given? open_tag(name, attrs) + contents.to_s + close_tag(name) end |