Sha256: 5321807c987df05a2bd659f4f3b42fd39fd7ef0b48957ed294b17104121114c9

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# -*- encoding: utf-8 -*-

require 'nokogiri'
require 'bluecloth'
require 'haml'

module Genit

  # Open an xml file.
  class XmlDocument
  
    # Public: Open an xml document.
    #
    # file - Full path String filename.
    #
    # Returns a Nokogiri::XML document.
    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

    # Public: Open a (xml) document from a haml file.
    #
    # file - Full path String filename of haml file.
    #
    # Returns a Nokogiri::XML document.
    def self.open_via_haml file
      tmp = Haml::Engine.new(File.open(file).read, :format => :xhtml).render
      Nokogiri::XML(tmp) 
    end
    
    # Public: Open a fragment of xml document.
    #
    # file - Full path String filename.
    #
    # Returns a Nokogiri::XML document.
    def self.open_fragment file
      string = IO.read file
      Nokogiri::XML.fragment string
    end
    
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
genit-2.1 lib/genit/documents/xml_document.rb