Class: BrowserifyRails::BrowserifyProcessor
- Inherits:
-
Object
- Object
- BrowserifyRails::BrowserifyProcessor
- Defined in:
- lib/browserify-rails/browserify_processor.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#data ⇒ Object
Returns the value of attribute data.
-
#file ⇒ Object
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize ⇒ BrowserifyProcessor
constructor
A new instance of BrowserifyProcessor.
Constructor Details
#initialize ⇒ BrowserifyProcessor
Returns a new instance of BrowserifyProcessor.
19 20 21 |
# File 'lib/browserify-rails/browserify_processor.rb', line 19 def initialize self.config = Rails.application.config.browserify_rails end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/browserify-rails/browserify_processor.rb', line 9 def config @config end |
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/browserify-rails/browserify_processor.rb', line 9 def data @data end |
#file ⇒ Object
Returns the value of attribute file.
9 10 11 |
# File 'lib/browserify-rails/browserify_processor.rb', line 9 def file @file end |
Class Method Details
.call(input) ⇒ Object
15 16 17 |
# File 'lib/browserify-rails/browserify_processor.rb', line 15 def self.call(input) instance.call(input) end |
.instance ⇒ Object
11 12 13 |
# File 'lib/browserify-rails/browserify_processor.rb', line 11 def self.instance @instance ||= new end |
Instance Method Details
#call(input) ⇒ Object
23 24 25 26 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 53 54 |
# File 'lib/browserify-rails/browserify_processor.rb', line 23 def call(input) self.file = input[:filename] return input[:data] unless in_path? self.data = input[:data] # Clear the cached dependencies because the source file changes @dependencies = nil ensure_tmp_dir_exists! ensure_commands_exist! # If there's nothing to do, we just return the data we received return data unless should_browserify? dependencies = Set.new(input[:metadata][:dependencies]) # Signal dependencies to sprockets to ensure we track changes evaluate_dependencies(input[:environment].paths).each do |path| resolved = input[:environment].resolve(path) if resolved && resolved.is_a?(Array) dependencies += resolved[1] elsif resolved dependencies << "file-digest://#{Addressable::URI.escape resolved}" elsif config.evaluate_node_modules dependencies << "file-digest://#{Addressable::URI.escape path}" end end new_data = run_browserify(input[:name]) { data: new_data, dependencies: dependencies } end |