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

#adjust_foreign_attributes, #adjust_mathml_attributes, #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



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/html5/html5parser/in_select_phase.rb', line 51

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



43
44
45
46
47
48
49
# File 'lib/html5/html5parser/in_select_phase.rb', line 43

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



86
87
88
# File 'lib/html5/html5parser/in_select_phase.rb', line 86

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

#endTagSelect(name) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/html5/html5parser/in_select_phase.rb', line 66

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



77
78
79
80
81
82
83
84
# File 'lib/html5/html5parser/in_select_phase.rb', line 77

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

#startTagInput(name, attributes) ⇒ Object



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

def startTagInput(name, attributes)
  @parser.parse_error("unexpected-input-in-select")
  endTagSelect("select")
  @parser.phase.processStartTag(name, attributes)
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



39
40
41
# File 'lib/html5/html5parser/in_select_phase.rb', line 39

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