Sha256: 7dd7848a7bfaf94b4b99892ebe923cb6ae6310d39ad54170fb92523d1e901c77

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Nitro
  
# Performs static includes. Typically you should include this compiler
# as the first stage of the compile pipeline.
# 
# This compiler is extremely helpful, typically you would want
# to use static includes in many many cases.
 
class StaticInclude
  #--
  # FIXME: use template root of the controller.
  #++
  
  def self.transform(text)
    # Statically include sub-template files.
    # The target file is included at compile time.
    #
    # gmosx: must be xformed before the <?r pi.
    #
    # Example:    
    # <?include href="root/myfile.sx" ?>

    return text.gsub(/<\?include href=["|'](.*?)["|'](.*)\?>/) do |match|
      unless File.exist?(filename = "#{Template.root}/#$1")
       unless File.exist?(filename = "#{Template.root}/#$1.xinc")
          unless File.exist?(filename = "#{Template.root}/#$1.xhtml")
            raise "Cannot include '#{Template.root}/#$1'"
          end
        end
      end
      itext = File.read(filename)
      itext.gsub!(/<\?xml.*\?>/, '')
      itext.gsub!(/<\/?root(.*?)>/m, ' ');
      itext
    end
  end
  
end
  
end

# * George Moschovitis <gm@navel.gr>

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nitro-0.25.0 lib/nitro/compiler/include.rb
nitro-0.26.0 lib/nitro/compiler/include.rb
nitro-0.27.0 lib/nitro/compiler/include.rb
nitro-0.28.0 lib/nitro/compiler/include.rb