Sha256: bffb4a07d38fa3786fc96b74b6d0f75a4d5d86e445e4b77f48a20cb5c25dc804

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require "haml"

module Capcode
  module Helpers
    @@__HAML_PATH__ = "."
    def self.haml_path=( p )
      @@__HAML_PATH__ = p
    end
    
    def render_haml( f, opts ) #:nodoc:
      f = f.to_s
      if f.include? '..'
        return [403, {}, '403 - Invalid path']
      end
      
      if /Windows/.match( ENV['OS'] )
        unless( /.:\\/.match( @@__ERB_PATH__[0] ) )
          @@__HAML_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__HAML_PATH__) )
        end
      else
        unless( @@__HAML_PATH__[0].chr == "/" )
          @@__HAML_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__HAML_PATH__) )
        end
      end
       
      layout = opts.delete(:layout)||:layout
      layout_file = File.join( @@__HAML_PATH__, layout.to_s+".haml" )
      
      f = f + ".haml" if File.extname( f ) != ".haml"
      file = File.join( @@__HAML_PATH__, f )

      if( File.exist?( layout_file ) )
        Haml::Engine.new( open( layout_file ).read ).to_html(self) { |*args| 
          @@__ARGS__ = args
          Haml::Engine.new( open( file ).read ).render(self) 
        }
      else
        Haml::Engine.new( open( file ).read ).to_html( self )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Capcode-0.6.2 lib/capcode/render/haml.rb
Capcode-0.7.0 lib/capcode/render/haml.rb
Capcode-0.7.1 lib/capcode/render/haml.rb