Guard to automatically compile Rails 3.1 assets
Go to file
James A. Rosen 8424beee1e obey config.assets.prefix. Closes #1. Closes #2.
Instead of doing an `rm -rf`, rely on `rake assets:clean`, which already
obeys the setting. Unfortunately, the call to figure out the count of assets
compiled would still need to have a directory specified. Thus, it's been
removed. Less information, but the compilation still works fine.
2011-06-19 14:06:23 -07:00
lib/guard obey config.assets.prefix. Closes #1. Closes #2. 2011-06-19 14:06:23 -07:00
spec obey config.assets.prefix. Closes #1. Closes #2. 2011-06-19 14:06:23 -07:00
.gitignore initial commit with aprox specs 2011-06-17 20:32:50 +10:00
Gemfile added template and README 2011-06-17 23:23:04 +10:00
Gemfile.lock added template and README 2011-06-17 23:23:04 +10:00
guard-rails-assets.gemspec initial commit with aprox specs 2011-06-17 20:32:50 +10:00
Rakefile initial commit with aprox specs 2011-06-17 20:32:50 +10:00
README.md Typo 2011-06-17 08:43:49 -07:00

Guard::RailsAssets

Guard::RailsAssets compiles all the assets in Rails 3.1 application automatically when files are modified.

Tested on MRI Ruby 1.9.2 (please report if it works on your platform). Currently only POSIX system is supported. Sorry Windows guys :(

If you have any questions please contact me @dnagir.

Install

Please be sure to have Guard installed.

Install the gem:

Add it to your Gemfile, preferably inside the test and development group:

gem 'guard-rails-assets'

Add guard definition to your Guardfile by running:

$ guard init rails-assets

Rails 3.1

The Rails 3.1 is a mandatory requirement, but is not enforeced via dependencies for now. The reason is that the assets are currently compiled via command line and thus this guard does not explicitly depend on Rails.

Good thing about it is that assets will always be same as produced by Rails. Bad thing is that it is pretty slow (~10 seconds) because it starts Rails from ground zero.

Rails Assets Pipeline

The conventions used in this guard are:

  • assets prefix is set to 'assets' meaning that all assets are compiled in to public/assets directory;
  • the assets directory is disposable and can be cleared out.

If the conventions above are not valid for you then perhaps you'd better submit a patch.

Guardfile and Options

In addition to the standard configuration, this Guard has options to specify when exacly to precompile assets.

  • :start - compile assets when the guard starts (default)
  • :reload - compile assets when the guard quites (Ctrl-C) (not enabled)
  • :all - compile assets when running all the guard (Ctrl-/) (default)
  • :change - compile assets when watched files change (default)

For example:

# compile ONLY when something changes
guard 'rails-assets', :run_on => :change do
  watch(%r{^app/assets/.+$})
end

# compile when something changes and when starting
guard 'rails-assets', :run_on => [:start, :change] do
  watch(%r{^app/assets/.+$})
end

# This is the default behaviour
guard 'rails-assets', :run_on => [:start, :change, :all] do
  watch(%r{^app/assets/.+$})
end

Development

Pull requests are very welcome!

License

MIT License