Class: CoffeeCompiler

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/coffee_compiler.rb', line 6

def code
  @code
end

Instance Method Details

#compileObject



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.message
end

#contextObject



22
23
24
25
26
# File 'lib/coffee_compiler.rb', line 22

def context
  V8::Context.new do |context|
    context.load(File.expand_path('coffee-script/extras/coffee-script.js', File.dirname(__FILE__)))
  end
end

#evalObject



18
19
20
# File 'lib/coffee_compiler.rb', line 18

def eval
  context.eval(compile)
end