Class: BrowserifySprockets::Engine
- Inherits:
-
Object
- Object
- BrowserifySprockets::Engine
- Defined in:
- lib/browserify_sprockets.rb
Class Attribute Summary collapse
-
.node_path ⇒ Object
Returns the value of attribute node_path.
-
.transforms ⇒ Object
Returns the value of attribute transforms.
Instance Method Summary collapse
- #browserify_build(pathname, data) ⇒ Object
-
#initialize(pathname, &block) ⇒ Engine
constructor
A new instance of Engine.
- #render(context, locals) ⇒ Object
Constructor Details
#initialize(pathname, &block) ⇒ Engine
Returns a new instance of Engine.
18 19 20 |
# File 'lib/browserify_sprockets.rb', line 18 def initialize(pathname, &block) @pathname = pathname end |
Class Attribute Details
.node_path ⇒ Object
Returns the value of attribute node_path.
15 16 17 |
# File 'lib/browserify_sprockets.rb', line 15 def node_path @node_path end |
.transforms ⇒ Object
Returns the value of attribute transforms.
14 15 16 |
# File 'lib/browserify_sprockets.rb', line 14 def transforms @transforms end |
Instance Method Details
#browserify_build(pathname, data) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/browserify_sprockets.rb', line 27 def browserify_build(pathname, data) build_script = File.("../../bin/browserify_build", __FILE__) base_directory = File.(pathname.dirname) debug = (ENV['RACK_ENV'] == "production") ? "" : "--debug" transforms = self.class.transforms.join(',') output = "" Open3.popen3({"NODE_PATH" => self.class.node_path}, build_script, debug, base_directory, transforms) do |stdin, stdout, stderr| stdin.puts data stdin.close output = stdout.gets(nil) unless output output = stderr.gets(nil) end stdout.close stderr.close end output end |
#render(context, locals) ⇒ Object
22 23 24 25 |
# File 'lib/browserify_sprockets.rb', line 22 def render(context, locals) data = File.open(context.pathname, 'rb') { |io| io.read } browserify_build(context.pathname, data) end |