Sha256: 9a81559d6186296228d73fa686c023a3ca3de9032240a100836832198c04cbc0
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
require 'erb' module Capcode module Helpers # Set the path to ERB files. If this path is not set, Capcode will search in the static path. # This method is deprecated and will be removed in version 1.0 def self.erb_path=( p ) warn "Capcode::Helpers.erb_path is deprecated and will be removed in version 1.0, please use `set :erb'" Capcode::Configuration.set :erb, p end def get_binding #:nodoc: binding end def render_erb( f, opts ) #:nodoc: if @erb_path.nil? @erb_path = Capcode::Configuration.get( :erb ) || Capcode.static() end f = f.to_s if f.include? '..' return [403, {}, '403 - Invalid path'] end if /Windows/.match( ENV['OS'] ) unless( /.:\\/.match( @erb_path[0] ) ) @erb_path = File.expand_path( File.join(".", @erb_path) ) end else unless( @erb_path[0].chr == "/" ) @erb_path = File.expand_path( File.join(".", @erb_path) ) end end # Get Layout layout = opts.delete(:layout)||:layout layout_file = File.join( @erb_path, layout.to_s ) layout_file = layout_file+".rhtml" if File.extname(layout_file) == "" # Get file f = f + ".rhtml" if File.extname( f ) == "" file = File.join( @erb_path, f ) if( File.exist?( file ) ) if( File.exist?( layout_file ) ) ERB.new(open(layout_file).read).result( get_binding { |*args| #@@__ARGS__ = args Capcode::Helpers.args = args ERB.new(open(file).read).result(binding) } ) else ERB.new(open(file).read).result(binding) end else raise Capcode::RenderError, "Error rendering `erb', #{file} does not exist !" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
capcode-render-erb-0.2.0 | lib/capcode/render/erb.rb |