PackR plugin
Plugin details
Documentation
ruby script/plugin install http://svn.jcoglan.com/packr/trunk/packr/
Usage is dead simple. Within your Rails app, you can compress pieces of code like this:
# Create a new instance of Packr first
packr = Packr.new compressed = packr.pack(script)
# Pass options to control the type of compression
compressed = packr.pack(script, :shrink_vars => true) compressed = packr.pack(script, :base62 => true) compressed = packr.pack(script, :shrink_vars => true, :base62 => true)
If you want to compress a particular file, you can do this:
packr = Packr.new packr.pack_file(path, ... options as above ...)
Be careful with that - it will overwrite the contents of the file with the packed version. Be a good kid and use version control in case something goes wrong and you lose all your source code!
=== Automated packing
PackR also comes with a rake task to let you batch-pack all your scripts. To use it, store any files you want to serve in packed form in the directory lib/javascripts. (The idea is that you won't be serving the source files to the public, so why keep them in the public folder? Also, it keeps the source files and packed copies nicely separated.) Then run:
rake packr:pack_libs
You can specify the type of packing using flags:
rake packr:pack_libs shrink_vars= rake packr:pack_libs base62= shrink_vars=
PackR will put packed copies of all the scripts from lib/javascripts in public/javascripts. Again, be careful as this will overwrite any pre-existing files in your public directory.
It is not recommended to run this as part of your deployment process, as you will need to verfiy that your JavaScript works when packed. PackR works using regular expressions -- not a true JavaScript interpreter -- and cannot fix missing semicolons for you.
Also, DO NOT use PackR to compress files on-the-fly in response to HTTP requests. The packing process can be quite processor-intensive and it will make you app very slow when serving script files.
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: scott, 7 months ago

