Ruby YUI

Well, ok, it’s not that Yui, but now that I’ve got your attention, I’ve made a ruby wrapper for the YUI JavaScript compressor.  What’s the point in that you say.  Well, I’d ideally like to keep my javascript like I keep my Sass/CSS.  The source I work on in one place, the ‘compiled’ stuff in a public one.  Why?  It just feels cleaner, and I like clean.

So whats it do?  Well essentially the same thing as the YUI compressor command line except that it will process an entire folder structure.  It also has the ability to bundle all the compressed files into one file.  It includes Thor tasks so you can use it from the command line and a ruby Yui class so you can access it programatically.

You can git it (haha, ‘git it’, git it? God damn I’m funny) from: http://github.com/coryodaniel/ruby-yui/tree/master

What using it look like, well:


require 'rubygems'
require 'ruby-yui'

yui = Yui.new "./public/javascripts"

yui.minify #=> true | false
yui.bundle #=> path to bundle or nil
yui.clobber #=> cleans up generated files

#Shortcut
Yui.compress "./public/javascripts" #=> same thing as Yui#minify
Yui.clobber "./public/javascripts" #=> cleans up generated files

Yui#initialize and Yui.compress also take params hashes:


yui = Yui.new "public/javascripts", {

# clobber files before compressing new ones
:clobber        => false,

# change the java command to run it
:java_cli       => "java -jar",

# alternate  YUI jar file
:yui_jar        => File.join(YUI_ROOT,"ext","yuicompressor-2.4.2.jar"),

# change the suffix used on the compressed file
:suffix         => "yui-min",

# change the out path; NOTE: the outpath is String#sub for the input path
# ./public/javascripts/main.js => ./my/out/path/main.js
:out_path       => nil,

# :js or :css
:type           => :js,

# YUI parameters
:charset        => nil,
:preserve_semi  => false,
:disable_opt    => false,
:nomunge        => false
}

Tags:

2 Responses to “Ruby YUI”

  1. Vokle > MovingParts: Auto versioning your Javascript and CSS Says:

    [...] compress your assets in a number of ways, I’ll go with shameless self promotion and recommend RubyYUI.  RubyYUI is a ruby wrapper for the Java-based YUI  Compressor.  It lets you glob paths instead [...]

  2. СловарьДаля Says:

    Хм…Неплохо :) Блоггер - трапезничать предложение , заполни форму на моём сайте ,оки ? )

Leave a Reply