Class: Gammo::Parser::InSelect

Inherits:
InsertionMode show all
Defined in:
lib/gammo/parser/insertion_mode/in_select.rb

Overview

Section 12.2.6.4.16.

Instance Attribute Summary

Attributes inherited from InsertionMode

#parser

Instance Method Summary collapse

Methods inherited from InsertionMode

#initialize, #process

Constructor Details

This class inherits a constructor from Gammo::Parser::InsertionMode

Instance Method Details

#character_token(token) ⇒ Object



5
6
7
# File 'lib/gammo/parser/insertion_mode/in_select.rb', line 5

def character_token(token)
  parser.add_text token.data.gsub("\x00",'')
end

#comment_token(token) ⇒ Object



59
60
61
# File 'lib/gammo/parser/insertion_mode/in_select.rb', line 59

def comment_token(token)
  parser.add_child(Node::Comment.new(data: token.data))
end

#default(_) ⇒ Object



72
73
74
# File 'lib/gammo/parser/insertion_mode/in_select.rb', line 72

def default(_)
  halt true
end

#doctype_token(_) ⇒ Object



63
64
65
66
# File 'lib/gammo/parser/insertion_mode/in_select.rb', line 63

def doctype_token(_)
  # ignore the token.
  halt true
end

#end_tag_token(token) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gammo/parser/insertion_mode/in_select.rb', line 37

def end_tag_token(token)
  case token.tag
  when Tags::Option
    parser.open_elements.pop if parser.top.tag == Tags::Option
    nil
  when Tags::Optgroup
    i = parser.open_elements.length - 1
    i -= 1 if parser.open_elements[i].tag == Tags::Option
    if parser.open_elements[i].tag == Tags::Optgroup
      parser.open_elements = parser.open_elements.slice(0, i)
    end
    nil
  when Tags::Select
    # ignore the token
    halt true unless parser.pop_until(SELECT_SCOPE, Tags::Select)
    parser.reset_insertion_mode
    nil
  when Tags::Template
    halt InHead.new(parser).process
  end
end

#error_token(_) ⇒ Object



68
69
70
# File 'lib/gammo/parser/insertion_mode/in_select.rb', line 68

def error_token(_)
  halt InBody.new(parser).process
end

#start_tag_token(token) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gammo/parser/insertion_mode/in_select.rb', line 9

def start_tag_token(token)
  case token.tag
  when Tags::Html
    halt InBody.new(parser).process
  when Tags::Option
    parser.open_elements.pop if parser.top.tag == Tags::Option
    parser.add_element
  when Tags::Optgroup
    parser.open_elements.pop if parser.top.tag == Tags::Option
    parser.open_elements.pop if parser.top.tag == Tags::Optgroup
    parser.add_element
  when Tags::Select
    # ignore the token
    halt true unless parser.pop_until(SELECT_SCOPE, Tags::Select)
    parser.reset_insertion_mode
  when Tags::Input, Tags::Keygen, Tags::Textarea
    if parser.element_in_scope?(SELECT_SCOPE, Tags::Select)
      parser.parse_implied_token(Tokenizer::EndTagToken, Tags::Select, Tags::Select.to_s)
      halt false
    end
    parser.tokenizer.next_is_not_raw_text!
    # ignore the token
    halt true
  when Tags::Script, Tags::Template
    halt InHead.new(parser).process
  end
end