Class: HtmlMockup::Release::Processors::Yuicompressor
- Defined in:
- lib/html_mockup/release/processors/yuicompressor.rb
Instance Method Summary collapse
-
#call(release, options = {}) ⇒ Object
Compresses all JS and CSS files, it will keep all lines before.
Methods inherited from Base
Constructor Details
This class inherits a constructor from HtmlMockup::Release::Processors::Base
Instance Method Details
#call(release, options = {}) ⇒ Object
Compresses all JS and CSS files, it will keep all lines before
/* -------------------------------------------------------------------------------- */
(80 dashes)
16 17 18 19 20 21 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 49 50 51 52 53 54 55 56 |
# File 'lib/html_mockup/release/processors/yuicompressor.rb', line 16 def call(release, ={}) = { :match => ["**/*.{css,js}"], :skip => [/javascripts\/vendor\/.*\.js\Z/, /_doc\/.*/], :delimiter => Regexp.escape("/* -------------------------------------------------------------------------------- */") }.update() = {:line_break => 80} css_compressor = YUI::CssCompressor.new() js_compressor = YUI::JavaScriptCompressor.new() release.log self, "Minifying #{[:match].inspect}" # Add version numbers and minify the files release.get_files([:match], [:skip]).each do |f| type = f[/\.([^.]+)\Z/,1] data = File.read(f); File.open(f,"w") do |fh| # Extract header and store for later use header = data[/\A(.+?)\n#{[:delimiter]}\s*\n/m,1] minified = [header] # Actual minification release.debug self, "Minifying #{f}" case type when "css" minified << css_compressor.compress(data) when "js" minified << js_compressor.compress(data) else release.warn self, "Error minifying: encountered unknown type \"#{type}\"" minified << data end fh.write minified.join("\n") end end end |