Class: CoffeeCompiler
- Inherits:
-
Object
- Object
- CoffeeCompiler
- Defined in:
- lib/coffee_compiler.rb,
lib/coffee_compiler/version.rb
Defined Under Namespace
Classes: SyntaxError
Constant Summary collapse
- VERSION =
"0.9.4"
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
- #compile ⇒ Object
- #context ⇒ Object
- #eval ⇒ Object
-
#initialize(code) ⇒ CoffeeCompiler
constructor
A new instance of CoffeeCompiler.
Constructor Details
#initialize(code) ⇒ CoffeeCompiler
Returns a new instance of CoffeeCompiler.
8 9 10 |
# File 'lib/coffee_compiler.rb', line 8 def initialize(code) @code = code end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/coffee_compiler.rb', line 6 def code @code end |
Instance Method Details
#compile ⇒ Object
12 13 14 15 16 |
# File 'lib/coffee_compiler.rb', line 12 def compile context['CoffeeScript'].compile(code) rescue V8::JSError => e raise CoffeeCompiler::SyntaxError, e. end |
#context ⇒ Object
22 23 24 25 26 |
# File 'lib/coffee_compiler.rb', line 22 def context V8::Context.new do |context| context.load(File.('coffee-script/extras/coffee-script.js', File.dirname(__FILE__))) end end |
#eval ⇒ Object
18 19 20 |
# File 'lib/coffee_compiler.rb', line 18 def eval context.eval(compile) end |