lib/capcode/render/haml.rb in Capcode-0.6.1 vs lib/capcode/render/haml.rb in Capcode-0.6.2

- old
+ new

@@ -5,11 +5,11 @@ @@__HAML_PATH__ = "." def self.haml_path=( p ) @@__HAML_PATH__ = p end - def render_haml( f ) #:nodoc: + def render_haml( f, opts ) #:nodoc: f = f.to_s if f.include? '..' return [403, {}, '403 - Invalid path'] end @@ -21,11 +21,22 @@ 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 ) - Haml::Engine.new( open( file ).read ).to_html( self ) + + 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 \ No newline at end of file