Sha256: cf9a6463ef586f5be29d2355236b6fe1d8dc7b407a4c989638129feec4d155ae

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module Merb
  module Template
    autoload :Erubis,  'merb/template/erubis'
    autoload :Haml,  'merb/template/haml'    
    autoload :Markaby,  'merb/template/markaby'    
    autoload :XMLBuilder,  'merb/template/xml_builder'      
    
    EXTENSIONS = {} unless defined?(EXTENSIONS)
    
    # lookup the template_extensions for the extname of the filename
    # you pass. Answers with the engine that matches the extension
    def self.engine_for(file)
      engine_for_extension(File.extname(file)[1..-1])
    end
    
    def self.engine_for_extension(ext)
      const_get EXTENSIONS[ext]
    end
    
    def self.register_extensions(engine,extensions)
      raise ArgumentError unless engine.is_a?(Symbol) && extensions.is_a?(Array)
      extensions.each{ |ext| EXTENSIONS[ext] = engine }
    end
    
    # Register the default extensions.  They must be here
    # since the template engines will not be loaded until they
    # are directly referenced, or a file with their extension is found.
    # If these are declared inside the template engine then
    # they will never be found :(
    register_extensions( :Erubis, %w[erb])
    register_extensions( :Haml, %w[haml])
    register_extensions( :Markaby, %w[mab])
    register_extensions( :XMLBuilder, %w[builder])
    
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
merb-0.5.0 lib/merb/template.rb
merb-0.5.1 lib/merb/template.rb
merb-0.5.2 lib/merb/template.rb
merb-0.5.3 lib/merb/template.rb