Sha256: 7d7f519ddee7d2a91e07ee9b7692b013d171c3696c2e665824236750cf59da70

Contents?: true

Size: 839 Bytes

Versions: 1

Compression:

Stored size: 839 Bytes

Contents

require "haml"

module Capcode
  module Helpers
    @@__HAML_PATH__ = "."
    def self.haml_path=( p )
      @@__HAML_PATH__ = p
    end
    
    def render_haml( f ) #: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
       
      f = f + ".haml" if File.extname( f ) != ".haml"
      file = File.join( @@__HAML_PATH__, f )
      Haml::Engine.new( open( file ).read ).to_html( self )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Capcode-0.6.1 lib/capcode/render/haml.rb