Class: SC::Builder::Minify

Inherits:
Base
  • Object
show all
Defined in:
lib/sproutcore/builders/minify.rb

Overview

This builder combines several javascript files into a single file. It is used to prepare a single javascript file for production use. This build tool expects the javascript files to have already been processed for any build directives such sc_static().

Instance Attribute Summary

Attributes inherited from Base

#entry

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#joinlines, #readlines, #replace_static_url, #static_url, #writelines

Constructor Details

#initialize(entry = nil, kind = nil) ⇒ Minify

Returns a new instance of Minify.



25
26
27
28
# File 'lib/sproutcore/builders/minify.rb', line 25

def initialize(entry=nil, kind=nil)
  super(entry)
  @kind = kind
end

Class Method Details

.build(entry, dst_path, kind) ⇒ Object

main entry called by build tasls



21
22
23
# File 'lib/sproutcore/builders/minify.rb', line 21

def self.build(entry, dst_path, kind)
  new(entry, kind).build(dst_path)
end

Instance Method Details

#build(dst_path) ⇒ Object

override this method in subclasses to actually do build



31
32
33
# File 'lib/sproutcore/builders/minify.rb', line 31

def build(dst_path)
  send("build_#{@kind}".to_sym, dst_path)
end

#build_css(dst_path) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sproutcore/builders/minify.rb', line 35

def build_css(dst_path)
      yui_root = File.expand_path(File.join(LIBPATH, '..', 'vendor', 'yui-compressor'))
    jar_path = File.join(yui_root, 'yuicompressor-2.4.2.jar')
    FileUtils.mkdir_p(File.dirname(dst_path)) # make sure loc exists...
    filecompress = "java -jar " + jar_path + " --charset utf-8 --line-break 0 --nomunge --preserve-semi --disable-optimizations " + entry.source_path + " -o " + dst_path
    SC.logger.info  'Compressing CSS with YUI .... '+ dst_path
    SC.logger.debug `#{filecompress}`

    if $?.exitstatus != 0
      SC.logger.fatal("!!!!YUI compressor failed, please check that your css code is valid.")
      SC.logger.fatal("!!!!Failed compressing CSS... "+ dst_path)
    end    
end

#build_javascript(dst_path) ⇒ Object

Minify some javascript by invoking the YUI compressor.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sproutcore/builders/minify.rb', line 50

def build_javascript(dst_path)
  yui_root = File.expand_path(File.join(LIBPATH, '..', 'vendor', 'yui-compressor'))
  jar_path = File.join(yui_root, 'yuicompressor-2.4.2.jar')
  FileUtils.mkdir_p(File.dirname(dst_path)) # make sure loc exists...
  filecompress = "java -jar " + jar_path + " --charset utf-8 --line-break 80 " + entry.source_path + " -o " + dst_path
  SC.logger.info  'Compressing with YUI .... '+ dst_path
  SC.logger.debug `#{filecompress}`
  
  if $?.exitstatus != 0
    SC.logger.fatal("!!!!YUI compressor failed, please check that your js code is valid and doesn't contain reserved statements like debugger;")
    SC.logger.fatal("!!!!Failed compressing ... "+ dst_path)
  end
  
end