lib/excesselt/stylesheet.rb in excesselt-1.0.0 vs lib/excesselt/stylesheet.rb in excesselt-1.1.0

- old
+ new

@@ -5,18 +5,21 @@ attr_reader :builder, :errors def self.transform(xml) self.new.transform(xml) end - - def initialize - @builder = Builder::XmlMarkup.new - @helper_modules = [] - @errors = [] + + def initialize(options={}) + @builder = options[:builder] || Builder::XmlMarkup.new + @helper_modules = options[:helper_modules] || [] + @errors = options[:errors] || [] end + # Pass in a string or a Nokogiri Node or Document. def transform(xml) - generate_element(Nokogiri::XML(xml, nil, nil, Nokogiri::XML::ParseOptions.new).root) + xml = xml.root if xml.is_a? Nokogiri::XML::Document + xml = Nokogiri::XML(xml, nil, nil, Nokogiri::XML::ParseOptions.new).root unless xml.is_a? Nokogiri::XML::Node + generate_element(xml) end def generate_element(element) rule = rule_for(element) raise "Attempted to generate #{self.name} with parents #{self.parents.inspect} but no rule was found." unless rule \ No newline at end of file