Class: Gammo::Parser::InTemplate

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

Overview

Section 12.2.6.4.18.

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

#comment_token(token) ⇒ Object



9
10
11
# File 'lib/gammo/parser/insertion_mode/in_template.rb', line 9

def comment_token(token)
  halt InBody.new(parser).process
end

#default(_) ⇒ Object



75
76
77
# File 'lib/gammo/parser/insertion_mode/in_template.rb', line 75

def default(_)
  halt false
end

#doctype_token(token) ⇒ Object



13
14
15
# File 'lib/gammo/parser/insertion_mode/in_template.rb', line 13

def doctype_token(token)
  halt InBody.new(parser).process
end

#end_tag_token(token) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/gammo/parser/insertion_mode/in_template.rb', line 49

def end_tag_token(token)
  case token.tag
  when Tags::Template
    halt InHead.new(parser).process
  else
    # ignore the token
    halt true
  end
end

#error_token(token) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gammo/parser/insertion_mode/in_template.rb', line 59

def error_token(token)
  halt true unless parser.open_elements.any? {|elm| elm.tag == Tags::Template }
  # remove this divergence from the html5 spec
  parser.generate_implied_end_tags
  parser.open_elements.reverse_each_with_index do |elm, index|
    if !elm.namespace && elm.tag == Tags::Template
      parser.open_elements = parser.open_elements.slice(0, index)
      break
    end
  end
  parser.clear_active_formatting_elements
  parser.template_stack.pop
  parser.reset_insertion_mode
  halt false
end

#start_tag_token(token) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gammo/parser/insertion_mode/in_template.rb', line 17

def start_tag_token(token)
  case token.tag
  when Tags::Base, Tags::Basefont, Tags::Bgsound, Tags::Link, Tags::Meta, Tags::Noframes, Tags::Script, Tags::Style, Tags::Template, Tags::Title
    halt InHead.new(parser).process
  when Tags::Caption, Tags::Colgroup, Tags::Tbody, Tags::Tfoot, Tags::Thead
    parser.template_stack.pop
    parser.template_stack << InTable
    parser.insertion_mode = InTable
    halt false
  when Tags::Col
    parser.template_stack.pop
    parser.template_stack << InColumnGroup
    parser.insertion_mode = InColumnGroup
    halt false
  when Tags::Tr
    parser.template_stack.pop
    parser.template_stack << InTableBody
    parser.insertion_mode = InTableBody
    halt false
  when Tags::Td, Tags::Th
    parser.template_stack.pop
    parser.template_stack << InRow
    parser.insertion_mode = InRow
    halt false
  else
    parser.template_stack.pop
    parser.template_stack << InBody
    parser.insertion_mode = InBody
    halt false
  end
end

#text_token(token) ⇒ Object



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

def text_token(token)
  halt InBody.new(parser).process
end