Class: WebAssets::ScriptProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/web_assets/script_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScriptProcessor

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

#environmentObject (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, options
  environment.js_compressor = options[:minify] ? :uglifier : nil
  return "" unless bundle = environment[filename]
  WebAssets.logger.debug "ScriptProcessor#content #{filename.inspect}"
  content = options[:bundle] ? bundle.to_s : bundle.body
  options[: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

#pathsObject



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