Class: WebAssets::ScriptProcessor
- Inherits:
-
Object
- Object
- WebAssets::ScriptProcessor
- Defined in:
- lib/web_assets/script_processor.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
- #add_load_path(path) ⇒ Object
- #content(filename, options) ⇒ Object
- #digest_filename(filename) ⇒ Object
- #filenames(filename) ⇒ Object
-
#initialize ⇒ ScriptProcessor
constructor
A new instance of ScriptProcessor.
- #paths ⇒ Object
- #set_path(path) ⇒ Object
Constructor Details
#initialize ⇒ ScriptProcessor
Returns a new instance of ScriptProcessor.
10 11 12 13 14 15 16 |
# File 'lib/web_assets/script_processor.rb', line 10 def initialize @environment = Sprockets::Environment.new if defined?(HandlebarsAssets) environment.append_path(HandlebarsAssets.path) HandlebarsAssets::Config.ember = true end end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
8 9 10 |
# File 'lib/web_assets/script_processor.rb', line 8 def environment @environment end |
Instance Method Details
#add_load_path(path) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/web_assets/script_processor.rb', line 25 def add_load_path path return [:error, "#{path} isn't an existing directory."] unless Dir.exists? path WebAssets.logger.debug "ScriptProcessor#add_load_path #{path.inspect}" environment.append_path path :ok end |
#content(filename, options) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/web_assets/script_processor.rb', line 48 def content filename, environment.js_compressor = [:minify] ? :uglifier : nil return "" unless bundle = environment[filename] WebAssets.logger.debug "ScriptProcessor#content #{filename.inspect}" content = [:bundle] ? bundle.to_s : bundle.body [:gzip] ? Gzipper.compress(content) : content end |
#digest_filename(filename) ⇒ Object
42 43 44 45 46 |
# File 'lib/web_assets/script_processor.rb', line 42 def digest_filename filename return "" unless bundle = environment[filename] WebAssets.logger.debug "ScriptProcessor#digest_filename #{filename.inspect}" bundle.digest_path end |
#filenames(filename) ⇒ Object
36 37 38 39 40 |
# File 'lib/web_assets/script_processor.rb', line 36 def filenames filename return [] unless bundle = environment[filename] WebAssets.logger.debug "ScriptProcessor#filenames #{filename.inspect}" bundle.to_a.map(&:logical_path) end |
#paths ⇒ Object
32 33 34 |
# File 'lib/web_assets/script_processor.rb', line 32 def paths environment.paths.dup end |
#set_path(path) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/web_assets/script_processor.rb', line 18 def set_path path return [:error, "#{path} isn't an existing directory."] unless Dir.exists? path WebAssets.logger.debug "ScriptProcessor#set_path #{path.inspect}" environment.prepend_path path :ok end |