Class: Nutils::Filters::YuiCompressor

Inherits:
Nanoc3::Filter
  • Object
show all
Defined in:
lib/nutils/filters/yuicompressor.rb

Overview

Note:

Requires «yui-compressor»

Author:

  • Arnau Siches

Version:

  • 1.2.1

Instance Method Summary collapse

Instance Method Details

#run(content, params = {}) ⇒ String

Compress the content with [YUI Compressor](developer.yahoo.com/yui/compressor/). This method takes no options.

Parameters:

  • content (String)

    The content to filter.

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :type (Symbol)

    The type of code to compress. Should be ‘:css` or `:js`.

Returns:

  • (String)

    The filtered content.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nutils/filters/yuicompressor.rb', line 23

def run(content, params={})
  require "yui/compressor"
  if (params[:type] == :css)
    compressor = ::YUI::CssCompressor.new
  else
    puts "Remember to add a params[:type] to your filter declaration to ensure straight compatibility with YUICompressor" unless params.has_key?(:type)
    # elsif (params[:type] == :js)
    # It fallbacks to `:type => :js` because backwards compatibility w/
    # prior versions of the filter.
    compressor = ::YUI::JavaScriptCompressor.new
  end

  compressor.compress(content)
end