Class: Glimmer::XML::HtmlVisitor

Inherits:
XmlVisitor show all
Defined in:
lib/glimmer/xml/html_visitor.rb

Instance Attribute Summary

Attributes inherited from XmlVisitor

#document

Instance Method Summary collapse

Methods inherited from XmlVisitor

#initialize, #process_after_children, #process_before_children

Methods inherited from NodeVisitor

#process_after_children, #process_before_children

Constructor Details

This class inherits a constructor from Glimmer::XML::XmlVisitor

Instance Method Details

#append_attributes(node) ⇒ Object



55
56
57
58
# File 'lib/glimmer/xml/html_visitor.rb', line 55

def append_attributes(node)
  return unless render_html_tag?(node)
  super(node)
end

#append_close_tag(node) ⇒ Object



50
51
52
53
# File 'lib/glimmer/xml/html_visitor.rb', line 50

def append_close_tag(node)
  return unless render_html_tag?(node)
  super(node)
end

#begin_open_tag(node) ⇒ Object



39
40
41
42
43
# File 'lib/glimmer/xml/html_visitor.rb', line 39

def begin_open_tag(node)
  return unless render_html_tag?(node)
  @document += "<!DOCTYPE html>" if node.name == 'html'
  super(node)
end

#end_open_tag(node) ⇒ Object



45
46
47
48
# File 'lib/glimmer/xml/html_visitor.rb', line 45

def end_open_tag(node)
  return unless render_html_tag?(node)
  super(node)
end

#render_html_tag?(node) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
# File 'lib/glimmer/xml/html_visitor.rb', line 28

def render_html_tag?(node)
  if node.name == 'html'
    node_children = node.children.select {|node_or_text| node_or_text.is_a?(Glimmer::XML::Node)}
    if !node_children.empty?
      children_names = node_children.map(&:name)
      return false unless children_names.include?('head') || children_names.include?('body')
    end
  end
  true
end