Module: CoffeeScript::Source

Defined in:
lib/coffee_script.rb

Constant Summary collapse

COMPILE_FUNCTION_SOURCE =
"  ;function compile(script, options) {\n    try {\n      return CoffeeScript.compile(script, options);\n    } catch (err) {\n      if (err instanceof SyntaxError && err.location) {\n        throw new SyntaxError([\n          err.filename || \"[stdin]\",\n          err.location.first_line + 1,\n          err.location.first_column + 1\n        ].join(\":\") + \": \" + err.message)\n      } else {\n        throw err;\n      }\n    }\n  }\n"

Class Method Summary collapse

Class Method Details

.bare_optionObject



45
46
47
# File 'lib/coffee_script.rb', line 45

def self.bare_option
  @bare_option ||= contents.match(/noWrap/) ? 'noWrap' : 'bare'
end

.contentsObject



37
38
39
# File 'lib/coffee_script.rb', line 37

def self.contents
  @contents ||= File.read(path) + COMPILE_FUNCTION_SOURCE
end

.contextObject



49
50
51
# File 'lib/coffee_script.rb', line 49

def self.context
  @context ||= ExecJS.compile(contents)
end

.pathObject



10
11
12
# File 'lib/coffee_script.rb', line 10

def self.path
  @path ||= ENV['COFFEESCRIPT_SOURCE_PATH'] || bundled_path
end

.path=(path) ⇒ Object



14
15
16
17
# File 'lib/coffee_script.rb', line 14

def self.path=(path)
  @contents = @version = @bare_option = @context = nil
  @path = path
end

.versionObject



41
42
43
# File 'lib/coffee_script.rb', line 41

def self.version
  @version ||= contents[/CoffeeScript Compiler v([\d.]+)/, 1]
end