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

- old
+ new

@@ -5,11 +5,15 @@ @@__ERB_PATH__ = "." def self.erb_path=( p ) @@__ERB_PATH__ = p end - def render_erb( f ) #:nodoc: + def get_binding + binding + end + + def render_erb( f, opts ) #:nodoc: f = f.to_s if f.include? '..' return [403, {}, '403 - Invalid path'] end @@ -20,12 +24,23 @@ else unless( @@__ERB_PATH__[0].chr == "/" ) @@__ERB_PATH__ = File.expand_path( File.join(@@__ROOT_DIRECTORY, @@__ERB_PATH__) ) end end - + + layout = opts.delete(:layout)||:layout + layout_file = File.join( @@__ERB_PATH__, layout.to_s+".rhtml" ) + f = f + ".rhtml" if File.extname( f ) != ".rhtml" file = File.join( @@__ERB_PATH__, f ) - ERB.new(open(file).read).result(binding) + + if( File.exist?( layout_file ) ) + ERB.new(open(layout_file).read).result( get_binding { |*args| + @@__ARGS__ = args + ERB.new(open(file).read).result(binding) + } ) + else + ERB.new(open(file).read).result(binding) + end end end end \ No newline at end of file