Class: HTML::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/html/tags.rb,
lib/html/tags.rb

Overview

This block initializes the tag lookup table.

Direct Known Subclasses

BlockTag, EmptyTag, InlineTag

Class Method Summary collapse

Instance Method Summary collapse

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



21
22
23
24
# File 'lib/html/tags.rb', line 21

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.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/html/tags.rb', line 105

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.



122
123
124
# File 'lib/html/tags.rb', line 122

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.



44
# File 'lib/html/tags.rb', line 44

def can_contain(tag, parent); false; end

#can_ignore_whitespaceObject

Return true if whitespace within me can be omitted (ignoring browser bugs)



48
# File 'lib/html/tags.rb', line 48

def can_ignore_whitespace; true; end

#can_omit_end_tagObject

Return true if my end tag can be omitted.



30
# File 'lib/html/tags.rb', line 30

def can_omit_end_tag; @can_omit_end; end

#is_block_elementObject

Return true if I am a block element.



33
# File 'lib/html/tags.rb', line 33

def is_block_element; false; end

#is_empty_elementObject

Return true if I am an empty element.



39
# File 'lib/html/tags.rb', line 39

def is_empty_element; false; end

#is_inline_elementObject

Return true if I am an inline element.



36
# File 'lib/html/tags.rb', line 36

def is_inline_element; false; end

#nameObject

Return my tag name.



27
# File 'lib/html/tags.rb', line 27

def name; @name; end