Class: RSLT::Stylesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/rslt/stylesheet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Stylesheet

Returns a new instance of Stylesheet.



13
14
15
16
17
18
# File 'lib/rslt/stylesheet.rb', line 13

def initialize(options={})
  @builder = options[:builder] || Builder::XmlMarkup.new
  @helper_modules = options[:helper_modules] || []
  @errors = options[:errors] || []
  @within = []
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



7
8
9
# File 'lib/rslt/stylesheet.rb', line 7

def builder
  @builder
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/rslt/stylesheet.rb', line 7

def errors
  @errors
end

Class Method Details

.transform(xml) ⇒ Object



9
10
11
# File 'lib/rslt/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/rslt/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/rslt/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