Class: Excesselt::Stylesheet
- Inherits:
-
Object
- Object
- Excesselt::Stylesheet
- Defined in:
- lib/excesselt/stylesheet.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
- #generate_element(element) ⇒ Object
-
#initialize(options = {}) ⇒ Stylesheet
constructor
A new instance of Stylesheet.
-
#transform(xml) ⇒ Object
Pass in a string or a Nokogiri Node or Document.
Constructor Details
#initialize(options = {}) ⇒ Stylesheet
Returns a new instance of Stylesheet.
13 14 15 16 17 18 |
# File 'lib/excesselt/stylesheet.rb', line 13 def initialize(={}) @builder = [:builder] || Builder::XmlMarkup.new @helper_modules = [:helper_modules] || [] @errors = [:errors] || [] @within = [] end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
7 8 9 |
# File 'lib/excesselt/stylesheet.rb', line 7 def builder @builder end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/excesselt/stylesheet.rb', line 7 def errors @errors end |
Class Method Details
.transform(xml) ⇒ Object
9 10 11 |
# File 'lib/excesselt/stylesheet.rb', line 9 def self.transform(xml) self.new.transform(xml) end |
Instance Method Details
#generate_element(element) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/excesselt/stylesheet.rb', line 27 def generate_element(element) return '' if element.instance_of? Nokogiri::XML::Comment rule = rule_for(element) raise "Attempted to generate #{self.name} with parents #{self.parents.inspect} but no rule was found." unless rule rule.generate(builder) end |
#transform(xml) ⇒ Object
Pass in a string or a Nokogiri Node or Document.
21 22 23 24 25 |
# File 'lib/excesselt/stylesheet.rb', line 21 def transform(xml) 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 |