Class: PrettyXML::XHTML

Inherits:
PrettyPrint show all
Defined in:
lib/printers/xhtml.rb

Constant Summary collapse

VOID =
%w(area base br col embed hr img input keygen link meta param source track wbr)

Instance Attribute Summary

Attributes inherited from PrettyPrint

#handler, #printer

Instance Method Summary collapse

Methods inherited from PrettyPrint

#doctype_node, #pp

Constructor Details

#initialize(options) ⇒ XHTML

Returns a new instance of XHTML.



5
6
7
8
9
10
11
# File 'lib/printers/xhtml.rb', line 5

def initialize(options)
  @elements = PrettyXML.load_config('xhtml.yml')
  options[:close_tags] = explicit_closing_tags
  options[:control_chars] = :hex
  options.merge!(@elements)
  super
end

Instance Method Details

#explicit_closing_tagsObject



13
14
15
# File 'lib/printers/xhtml.rb', line 13

def explicit_closing_tags
  @elements.values.flatten - VOID
end

#parsed_doc?(doc) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/printers/xhtml.rb', line 17

def parsed_doc?(doc)
  doc.is_a?(Nokogiri::HTML::Document) or doc.is_a?(Nokogiri::XML::Document)
end

#verify_doc(doc) ⇒ Object



21
22
23
# File 'lib/printers/xhtml.rb', line 21

def verify_doc(doc)
  parsed_doc?(doc) ? doc.to_xml : doc
end