Class: AssetLibrary::Compiler::Closure

Inherits:
Base
  • Object
show all
Defined in:
lib/asset_library/compiler/closure.rb

Instance Attribute Summary

Attributes inherited from Base

#asset_modules, #config

Instance Method Summary collapse

Methods inherited from Base

#add_asset_module

Constructor Details

#initialize(config) ⇒ Closure

Returns a new instance of Closure.



6
7
8
9
10
11
12
13
14
# File 'lib/asset_library/compiler/closure.rb', line 6

def initialize(config)
  super
  config[:path] or
    raise ConfigurationError, "Please set path of closure jar with compilers.closure.path configuration setting"
  config[:java] ||= 'java'
  config[:java_flags] = Util.normalize_flags(config[:java_flags])
  config[:path] = normalize_path(config[:path])
  config[:flags] = Util.normalize_flags(config[:flags])
end

Instance Method Details

#write_all_caches(format = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asset_library/compiler/closure.rb', line 16

def write_all_caches(format = nil)
  asset_modules.each do |asset_module|
    command = [config[:java]]
    command.concat(config[:java_flags])
    command << '-jar' << config[:path]
    command.concat(config[:flags])
    command.concat(asset_module.compiler_flags)
    command << '--js_output_file' << "#{output_path(asset_module, format)}"
    input_paths(asset_module, format).each do |input|
      command << '--js' << input
    end
    system *command or
      raise Error, "closure compiler failed"
  end
end