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.
18 19 20 |
# File 'lib/browserify-rails/browserify_processor.rb', line 18 def initialize self.config = Rails.application.config.browserify_rails end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/browserify-rails/browserify_processor.rb', line 8 def config @config end |
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/browserify-rails/browserify_processor.rb', line 8 def data @data end |
#file ⇒ Object
Returns the value of attribute file.
8 9 10 |
# File 'lib/browserify-rails/browserify_processor.rb', line 8 def file @file end |
Class Method Details
.call(input) ⇒ Object
14 15 16 |
# File 'lib/browserify-rails/browserify_processor.rb', line 14 def self.call(input) instance.call(input) end |
.instance ⇒ Object
10 11 12 |
# File 'lib/browserify-rails/browserify_processor.rb', line 10 def self.instance @instance ||= new end |
Instance Method Details
#call(input) ⇒ Object
22 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 |
# File 'lib/browserify-rails/browserify_processor.rb', line 22 def call(input) self.data = input[:data] self.file = input[:filename] # 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 config.evaluate_node_modules && !resolved resolved = path end dependencies << "file-digest://#{URI.escape resolved}" if resolved end new_data = run_browserify(input[:name]) { data: new_data, dependencies: dependencies } end |