Class: Awestruct::Extensions::Minify

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/extensions/minify.rb

Defined Under Namespace

Classes: JSCompressor

Instance Method Summary collapse

Constructor Details

#initialize(types = [ :js ]) ⇒ Minify

Returns a new instance of Minify.



49
50
51
# File 'lib/awestruct/extensions/minify.rb', line 49

def initialize(types = [ :js ])
  @types = types
end

Instance Method Details

#transform(site, page, input) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/awestruct/extensions/minify.rb', line 53

def transform(site, page, input)
  if site.minify
    require 'shellwords'
    require 'fileutils'
    require 'htmlcompressor'
    require 'uglifier'

    ext = File.extname(page.output_path)
    if !ext.empty?
      ext_sym = ext[1..-1].to_sym
      if @types.include?(ext_sym)
        case ext_sym
        when :html
          $LOG.debug "minifying html #{page.output_path}" if $LOG.debug?
          input = htmlcompressor(page, input, site.minify_html_opts)
        when :css
          # TODO: Figure out how to do this is sass / less and document it
          #print "minifying css #{page.output_path}"
          #input = yuicompressor_css(page, input)
        when :js
          $LOG.debug "minifying js #{page.output_path}" if $LOG.debug?
          input = js_compressor(page, input)
        when :png
          $LOG.debug "minifying png #{page.output_path}" if $LOG.debug?
          input = pngcrush(page, input)
        end
      end
    end
  end
  input
end