Class: HTML5::InSelectPhase

Inherits:
Phase
  • Object
show all
Defined in:
lib/html5/html5parser/in_select_phase.rb

Instance Method Summary collapse

Methods inherited from Phase

#assert, end_tag_handlers, handle_end, handle_start, #in_scope?, #initialize, #processComment, #processDoctype, #processEndTag, #processSpaceCharacters, #processStartTag, #process_eof, #remove_open_elements_until, #startTagHtml, start_tag_handlers, tag_handlers

Constructor Details

This class inherits a constructor from HTML5::Phase

Instance Method Details

#endTagOptgroup(name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/html5/html5parser/in_select_phase.rb', line 45

def endTagOptgroup(name)
  # </optgroup> implicitly closes <option>
  if @tree.open_elements.last.name == 'option' and @tree.open_elements[-2].name == 'optgroup'
    @tree.open_elements.pop
  end
  # It also closes </optgroup>
  if @tree.open_elements.last.name == 'optgroup'
    @tree.open_elements.pop
  # But nothing else
  else
    parse_error("unexpected-end-tag-in-select",
            {"name" => "optgroup"})
  end
end

#endTagOption(name) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/html5/html5parser/in_select_phase.rb', line 37

def endTagOption(name)
  if @tree.open_elements.last.name == 'option'
    @tree.open_elements.pop
  else
    parse_error("unexpected-end-tag-in-select", {"name" => "option"})
  end
end

#endTagOther(name) ⇒ Object



80
81
82
# File 'lib/html5/html5parser/in_select_phase.rb', line 80

def endTagOther(name)
  parse_error("unexpected-end-tag-in-select", {"name" => name})
end

#endTagSelect(name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/html5/html5parser/in_select_phase.rb', line 60

def endTagSelect(name)
  if in_scope?('select', true)
    remove_open_elements_until('select')

    @parser.reset_insertion_mode
  else
    # inner_html case
    parse_error
  end
end

#endTagTableElements(name) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/html5/html5parser/in_select_phase.rb', line 71

def endTagTableElements(name)
  parse_error("unexpected-end-tag-in-select", {"name" => name})

  if in_scope?(name, true)
    endTagSelect('select')
    @parser.phase.processEndTag(name)
  end
end

#processCharacters(data) ⇒ Object



12
13
14
# File 'lib/html5/html5parser/in_select_phase.rb', line 12

def processCharacters(data)
  @tree.insertText(data)
end

#startTagOptgroup(name, attributes) ⇒ Object



22
23
24
25
26
# File 'lib/html5/html5parser/in_select_phase.rb', line 22

def startTagOptgroup(name, attributes)
  @tree.open_elements.pop if @tree.open_elements.last.name == 'option'
  @tree.open_elements.pop if @tree.open_elements.last.name == 'optgroup'
  @tree.insert_element(name, attributes)
end

#startTagOption(name, attributes) ⇒ Object



16
17
18
19
20
# File 'lib/html5/html5parser/in_select_phase.rb', line 16

def startTagOption(name, attributes)
  # We need to imply </option> if <option> is the current node.
  @tree.open_elements.pop if @tree.open_elements.last.name == 'option'
  @tree.insert_element(name, attributes)
end

#startTagOther(name, attributes) ⇒ Object



33
34
35
# File 'lib/html5/html5parser/in_select_phase.rb', line 33

def startTagOther(name, attributes)
  parse_error("unexpected-start-tag-in-select", {"name" => name})
end

#startTagSelect(name, attributes) ⇒ Object



28
29
30
31
# File 'lib/html5/html5parser/in_select_phase.rb', line 28

def startTagSelect(name, attributes)
  parse_error("unexpected-select-in-select")
  endTagSelect('select')
end