Module: CoffeeScript::Source

Defined in:
lib/coffee_script.rb

Constant Summary collapse

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

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