Sha256: bd7c09cc31509dca3ebfff1becaa4b0dc9d40b0118f41ea594ecd72160a2635b

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'sync'

require 'xml/xslt'

module Nitro

# Pre-applies an XSL transformation to the template file to 
# generate the final template file. Due to preproccessing, the
# transformation comes for free.

class XSLTransform
  @@sync = Sync.new

  class << self

    # The xslt filename.
    
    attr :xsl_filename
    
    # The xslt transformer.
    
    attr :xslt
  
    def initialize(xsl_filename, next_stage = nil)

      # leave this require here. only inlcude the xslt 
      # library if the project needs it.
      
      require "xml/xslt"

      @name = File.basename(xsl_filename, '.*')
      @xsl_filename = xsl_filename
      @xslt = XML::XSLT.new
      @next_stage = next_stage
    end
    
    # Transform the given xml.
    
    def transform(text, compiler = nil)      
      parse_xsl()
      @xslt.xml = text
      hash += @name
      Logger.debug "Applying xsl '#{@xsl_filename}' to template" if $DBG
      process_next(hash, xslt.serve)
    end
    
  private 
  
    # Parse the xsl.
    
    def parse_xsl
      Logger.debug "Parsing xsl '#{@xsl_filename}'" if $DBG
      @mtime = File.mtime(@xsl_filename)
      @xslt.xsl = File.read(@xsl_filename)
    end  
  end
  
end

end

# * George Moschovitis <gm@navel.gr>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.30.0 lib/nitro/compiler/xslt.rb
nitro-0.31.0 lib/nitro/compiler/xslt.rb