lib/barista/compiler.rb in barista-1.1.0 vs lib/barista/compiler.rb in barista-1.2.0

- old
+ new

@@ -1,10 +1,12 @@ require 'digest/sha2' module Barista class Compiler + UNAVAILABLE_MESSAGE = "No method of compiling coffee-script is currently available. Please see the ExecJS page (https://github.com/sstephenson/execjs) for details on how to set one up." + # TODO: Deprecate. class << self def js_path CoffeeScript::Source.path @@ -13,23 +15,15 @@ def js_path=(value) CoffeeScript::Source.path = value end def bin_path - if defined?(CoffeeScript::Engines::Node) - CoffeeScript::Engines::Node.binary - else - execjs_runtime_call :binary - end + execjs_runtime_call :binary end def bin_path=(path) - if defined?(CoffeeScript::Engines::Node) - CoffeeScript::Engines::Node.binary = path - else - execjs_runtime_call :binary=, path - end + execjs_runtime_call :binary=, path end def execjs_runtime_call(method, *args) runtime = ExecJS.runtime if runtime.respond_to?(method, true) @@ -38,17 +32,17 @@ nil end end def available? - CoffeeScript.engine && CoffeeScript.engine.supported? + ExecJS.runtime and ExecJS.runtime.available? end def check_availability!(silence = false) available = available? if !available && Barista.exception_on_error? && !silence - raise CompilerUnavailableError, "No method of compiling cofffescript is currently available. Please install therubyracer or node." + raise CompilerUnavailableError, UNAVAILABLE_MESSAGE end available end def compile(content, options = {}) @@ -71,10 +65,10 @@ end return File.read(destination_path) unless dirty?(origin_path, destination_path) || force # Ensure we have a coffeescript compiler available. if !check_availability!(silence_error) - Barista.debug "The coffeescript compiler at '#{Compiler.bin_path}' is currently unavailable." + Barista.debug UNAVAILABLE_MESSAGE return nil end Barista.debug "Compiling #{file} from framework '#{framework.name}'" compiler = new(origin_path, :silence_error => silence_error, :output_path => destination_path) content = compiler.to_js