SmartAsset
===========
Smart asset packaging for Rails and Sinatra.
Features
--------
Similar to AssetPackager
, but with the following changes:
* Git modified date/time for package version (only re-packages files that have been modified)
* Google Closure Compiler for javascript compression
* Framework agnostic (adapters provided for Rails 2, Rails 3, and Sinatra)
Installation
------------
### Install Gem
gem install smart_asset### Rails 2 #### config/environment.rb
config.gem 'smart_asset'### Rails 3 #### Gemfile
gem 'smart_asset'### Sinatra
require 'sinatra/base' require 'smart_asset' class Application < Sinatra::Base include SmartAsset::Adapters::Sinatra endCreate Configuration File ------------------------- ### config/assets.yml
javascripts: package_1: - jquery/jquery - underscore package_2: - front_page stylesheets: package_1: - blueprint/blueprint - 960 package_2: - front_pageBy default, SmartAsset will look for assets in
public/javascripts
and public/stylesheets
.
Create Packaged Assets
----------------------
cd
to your project and run
smart_assetIf your project is Git version controlled, only the assets that have changed are repackaged. Otherwise, all packages generate every time. Include Packages in Your Template ---------------------------------
<%= javascript_include_merged :package_1, :package_2 %> <%= stylesheet_link_merged :package_1, :package_2 %>Migrating from AssetPackager ---------------------------- *
rm vendor/plugins/asset\_packager
* Install SmartAsset
* Move config/asset\_packages.yml
to config/assets.yml
* Instead of running rake asset:packager:build_all
, run smart\_asset
Other Options
-------------
### config/assets.yml
You may add extra options to your config/assets.yml
file.
Below are the default values (excluding asset\_host
):
# Append random numbers to script paths on each request append_random: development: true # Asset host URL (defaults to ActionController::Base.asset_host or nil) asset_host: production: http://assets%d.mydomain.com # How many asset hosts you have (use if asset_host defined with %d) asset_host_count: 4 # Public directory public: public # Package destination directory (within the public directory) destination: javascripts: javascripts/packaged stylesheets: stylesheets/packaged # Asset source directories (within the public directory) sources: javascripts: javascripts stylesheets: stylesheets### smart\_asset You may use environment variables with the
smart\_asset
command to alter its behavior.
DEBUG=1
PACKAGE=package\_1
MODIFIED='12/1/2010 12:00'
WARN=1
WARN=1 smart_asset