Class: Genit::XmlDocument
- Inherits:
-
Object
- Object
- Genit::XmlDocument
- Defined in:
- lib/genit/documents/xml_document.rb
Overview
Open an xml file.
Class Method Summary collapse
-
.open(file) ⇒ Object
Public: Open an xml document.
-
.open_fragment(file) ⇒ Object
Public: Open a fragment of xml document.
-
.open_via_haml(file) ⇒ Object
Public: Open a (xml) document from a haml file.
Class Method Details
.open(file) ⇒ Object
Public: Open an xml document.
file - Full path String filename.
Returns a Nokogiri::XML document.
17 18 19 20 21 22 23 |
# File 'lib/genit/documents/xml_document.rb', line 17 def self.open file begin Nokogiri::XML(File.open(file)){|config| config.strict} rescue Nokogiri::XML::SyntaxError => ex error "Malformed xhtml in file #{file} : #{ex}" end end |
.open_fragment(file) ⇒ Object
Public: Open a fragment of xml document.
file - Full path String filename.
Returns a Nokogiri::XML document.
40 41 42 43 |
# File 'lib/genit/documents/xml_document.rb', line 40 def self.open_fragment file string = IO.read file Nokogiri::XML.fragment string end |
.open_via_haml(file) ⇒ Object
Public: Open a (xml) document from a haml file.
file - Full path String filename of haml file.
Returns a Nokogiri::XML document.
30 31 32 33 |
# File 'lib/genit/documents/xml_document.rb', line 30 def self.open_via_haml file tmp = Haml::Engine.new(File.open(file).read, :format => :xhtml).render Nokogiri::XML(tmp) end |