Class: HTML::Tag
- Defined in:
- lib/web/htmltools/tags.rb,
lib/web/htmltools/tags.rb
Overview
This block initializes the tag lookup table.
Class Method Summary collapse
-
.add_tag(name, is_block, is_inline, is_empty, can_omit) ⇒ Object
Add the given tag to the tag lookup table.
-
.named(tagname) ⇒ Object
Return an Tag with the given name, or raise a NoSuchHTMLTagError.
Instance Method Summary collapse
-
#can_contain(tag, parent) ⇒ Object
Return true if I can contain
tag
if my parent is of typeparent
. -
#can_ignore_whitespace ⇒ Object
Return true if whitespace within me can be omitted (ignoring browser bugs).
-
#can_omit_end_tag ⇒ Object
Return true if my end tag can be omitted.
-
#initialize(tag_name, can_omit) ⇒ Tag
constructor
- tag_name
- a String, the name of the tag can_omit
-
a Boolean, true if end tag is optional.
-
#is_block_element ⇒ Object
Return true if I am a block element.
-
#is_empty_element ⇒ Object
Return true if I am an empty element.
-
#is_inline_element ⇒ Object
Return true if I am an inline element.
-
#name ⇒ Object
Return my tag name.
Constructor Details
#initialize(tag_name, can_omit) ⇒ Tag
- tag_name
-
a String, the name of the tag
- can_omit
-
a Boolean, true if end tag is optional
20 21 22 23 |
# File 'lib/web/htmltools/tags.rb', line 20 def initialize(tag_name, can_omit) @name = tag_name.downcase @can_omit_end = can_omit end |
Class Method Details
.add_tag(name, is_block, is_inline, is_empty, can_omit) ⇒ Object
Add the given tag to the tag lookup table.
This can be called by user code to add otherwise unknown tags to the table.
- name
-
the tag name, a String.
- is_block
-
true if I am a block element.
- is_inline
-
true if I am an inline element.
- is_empty
-
true if I am an empty element.
- can_omit
-
true if my end tag can be omitted.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/web/htmltools/tags.rb', line 104 def Tag.add_tag(name, is_block, is_inline, is_empty, can_omit) @table[ name.upcase ] = @table[ name.downcase ] = \ if is_empty EmptyTag.new(name, true) elsif is_block if is_inline BlockOrInlineTag.new(name, can_omit) else BlockTag.new(name, can_omit) end else InlineTag.new(name, can_omit) end end |
.named(tagname) ⇒ Object
Return an Tag with the given name, or raise a NoSuchHTMLTagError.
121 122 123 |
# File 'lib/web/htmltools/tags.rb', line 121 def Tag.named(tagname) @table[ tagname ] || raise(NoSuchHTMLTagError.exception(tagname)) end |
Instance Method Details
#can_contain(tag, parent) ⇒ Object
Return true if I can contain tag
if my parent is of type parent
.
- tag
-
tag name, a String
- parent
-
parent tag name, a String.
43 |
# File 'lib/web/htmltools/tags.rb', line 43 def can_contain(tag, parent); false; end |
#can_ignore_whitespace ⇒ Object
Return true if whitespace within me can be omitted (ignoring browser bugs)
47 |
# File 'lib/web/htmltools/tags.rb', line 47 def can_ignore_whitespace; true; end |
#can_omit_end_tag ⇒ Object
Return true if my end tag can be omitted.
29 |
# File 'lib/web/htmltools/tags.rb', line 29 def can_omit_end_tag; @can_omit_end; end |
#is_block_element ⇒ Object
Return true if I am a block element.
32 |
# File 'lib/web/htmltools/tags.rb', line 32 def is_block_element; false; end |
#is_empty_element ⇒ Object
Return true if I am an empty element.
38 |
# File 'lib/web/htmltools/tags.rb', line 38 def is_empty_element; false; end |
#is_inline_element ⇒ Object
Return true if I am an inline element.
35 |
# File 'lib/web/htmltools/tags.rb', line 35 def is_inline_element; false; end |
#name ⇒ Object
Return my tag name.
26 |
# File 'lib/web/htmltools/tags.rb', line 26 def name; @name; end |