Sha256: 596284cd05efe0ba3012a59374db214302ec692c2bbf7b4ad856b6cb1104f385

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nitro-0.41.0 lib/nitro/compiler/xslt.rb
nitro-0.40.0 lib/nitro/compiler/xslt.rb