lib/coffeelint.rb in coffeelint-0.1.3 vs lib/coffeelint.rb in coffeelint-0.2.0
- old
+ new
@@ -5,11 +5,11 @@
module Coffeelint
require 'coffeelint/railtie' if defined?(Rails)
def self.path()
- @path ||= File.expand_path('../../coffeelint/src/coffeelint.coffee', __FILE__)
+ @path ||= File.expand_path('../../coffeelint/lib/coffeelint.js', __FILE__)
end
def self.colorize(str, color_code)
"\e[#{color_code}m#{str}\e[0m"
end
@@ -20,18 +20,27 @@
def self.green(str, pretty_output = true)
pretty_output ? Coffeelint.colorize(str, 32) : str
end
+ def self.context
+ coffeescriptSource = File.read(CoffeeScript::Source.path)
+ bootstrap = <<-EOF
+ window = {
+ CoffeeScript: CoffeeScript,
+ coffeelint: {}
+ };
+ EOF
+ coffeelintSource = File.read(Coffeelint.path)
+ ExecJS.compile(coffeescriptSource + bootstrap + coffeelintSource)
+ end
+
def self.lint(script, config = {})
if !config[:config_file].nil?
fname = config.delete(:config_file)
config.merge!(JSON.parse(File.read(fname)))
end
- coffeescriptSource = File.read(CoffeeScript::Source.path)
- coffeelintSource = CoffeeScript.compile(File.read(Coffeelint.path))
- context = ExecJS.compile(coffeescriptSource + coffeelintSource)
- context.call('coffeelint.lint', script, config)
+ Coffeelint.context.call('window.coffeelint.lint', script, config)
end
def self.lint_file(filename, config = {})
Coffeelint.lint(File.read(filename), config)
end