Module: Capcode::Helpers
- Defined in:
- lib/capcode/render/coffee.rb
Class Method Summary collapse
-
.coffee_path=(p) ⇒ Object
Set the path to Coffee files.
Instance Method Summary collapse
-
#render_coffee(f, opts) ⇒ Object
:nodoc:.
Class Method Details
.coffee_path=(p) ⇒ Object
Set the path to Coffee 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
11 12 13 14 |
# File 'lib/capcode/render/coffee.rb', line 11 def self.coffee_path=( p ) warn "Capcode::Helpers.coffee_path is deprecated and will be removed in version 1.0, please use `set :coffee'" Capcode::Configuration.set :coffee, p end |
Instance Method Details
#render_coffee(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 |
# File 'lib/capcode/render/coffee.rb', line 16 def render_coffee( f, opts ) #:nodoc: if @coffee_path.nil? @coffee_path = Capcode::Configuration.get( :coffee ) || Capcode.static() end f = f.to_s if f.include? '..' return [403, {}, '403 - Invalid path'] end if /Windows/.match( ENV['OS'] ) unless( /.:\\/.match( @coffee_path[0] ) ) @coffee_path = File.( File.join(".", @coffee_path) ) end else unless( @coffee_path[0].chr == "/" ) @coffee_path = File.( File.join(".", @coffee_path) ) end end # Update options opts = (Capcode::Configuration.[:coffee] || {}).merge(opts) # Get coffee File f = f + ".coffee" if File.extname( f ) != ".coffee" file = File.join( @coffee_path, f ) # Set content-type @response['Content-Type'] = "text/javascript" # Render if( File.exist?( file ) ) CoffeeScript.compile(open(file), opts) else raise Capcode::RenderError, "Error rendering `coffee', #{file} does not exist !" end end |