Module: Capcode::Helpers
- Defined in:
- lib/capcode/render/erb.rb
Class Method Summary collapse
-
.erb_path=(p) ⇒ Object
Set the path to ERB files.
Instance Method Summary collapse
-
#get_binding ⇒ Object
:nodoc:.
-
#render_erb(f, opts) ⇒ Object
:nodoc:.
Class Method Details
.erb_path=(p) ⇒ Object
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
7 8 9 10 |
# File 'lib/capcode/render/erb.rb', line 7 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 |
Instance Method Details
#get_binding ⇒ Object
:nodoc:
12 13 14 |
# File 'lib/capcode/render/erb.rb', line 12 def get_binding #:nodoc: binding end |
#render_erb(f, opts) ⇒ Object
:nodoc:
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/capcode/render/erb.rb', line 16 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.( File.join(".", @erb_path) ) end else unless( @erb_path[0].chr == "/" ) @erb_path = File.( 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 |