lib/ember_script.rb in ember_script-0.0.3 vs lib/ember_script.rb in ember_script-0.0.4
- old
+ new
@@ -1,26 +1,35 @@
# encoding: utf-8
+require 'execjs'
require 'tilt'
-require 'open3'
+require 'ember_script/source'
require 'ember_script/version'
module EmberScript
- class << self
- def engine
+ module Source
+ def self.path
+ @path ||= ENV['EMBERSCRIPT_SOURCE_PATH'] || bundled_path
end
- def engine=(engine)
+ def self.contents
+ @contents ||= File.read(path)
end
- def version
- `ember-script -v`
+ def self.version
+ Source.context.eval("EmberScript.VERSION")
end
- # Compile a EmberScript file to JavaScript
+ def self.context
+ @context ||= ExecJS.compile(contents)
+ end
+ end
+
+ class << self
+ # Compile an EmberScript file to JavaScript
# or generate the source maps.
#
# @param [String,#read] the source string or IO
# @param [Hash] options the compiler options
# @option options [Boolean] bare compile the JavaScript without the top-level function safety wrapper
@@ -35,10 +44,10 @@
else
options[:bare] = false
end
bare = options[:bare] ? "--bare" : ""
- Open3.capture3("ember-script --js #{bare}", :stdin_data=>script)[0]
+ Source.context.call("EmberScript.em2js", script, options)
end
end
class EmberScriptTemplate < ::Tilt::Template
self.default_mime_type = 'application/javascript'