2011-06-17 13:23:04 +00:00
# Guard::RailsAssets
2011-09-04 08:09:45 +00:00
Guard::RailsAssets compiles the assets within Rails 3.1 application whenever those change.
2011-06-17 13:23:04 +00:00
2011-09-04 08:09:45 +00:00
Tested on MRI 1.9.2 (please report if it works on your platform).
2011-06-17 13:23:04 +00:00
If you have any questions please contact me [@dnagir ](http://www.ApproachE.com ).
## Install
Please be sure to have [Guard ](https://github.com/guard/guard ) installed.
Add it to your `Gemfile` , preferably inside the test and development group:
```ruby
gem 'guard-rails-assets'
```
Add guard definition to your `Guardfile` by running:
```bash
2011-09-04 08:09:45 +00:00
$ bundle exec guard init rails-assets
2011-06-17 13:23:04 +00:00
```
2011-11-07 22:24:35 +00:00
## Configuration for Jasmine
In order to make it work better with Jasmine it is recommended to explicitly move files precompiled for testing into a separate directory.
This way it doesn't conflict with any files in `public/assets` .
This is optional and you can skip it for now.
2011-11-07 22:25:18 +00:00
But if you are in for that, then:
2011-11-07 22:24:35 +00:00
1. Add the option `config.assets.prefix = 'public/assets-test'` to `config/environments/test.rb` .
2. Replace all `public/assets` with `public/assets-test` in `spec/javascripts/support/jasmine.yml` .
3. Add `public/assets*` to your `.gitignore` (if you haven't yet).
2011-09-04 08:09:45 +00:00
## Options
2011-06-17 13:23:04 +00:00
2011-09-04 07:57:57 +00:00
In addition to the guard configuration, `guard-rails-assets` has options to specify when exacly to precompile assets.
2011-06-17 13:23:04 +00:00
2011-07-16 09:06:12 +00:00
- `:start` - compile assets when the guard starts (enabled by default)
- `:change` - compile assets when watched files change (enabled by default)
- `:reload` - compile assets when the guard quites (Ctrl-C) (not enabled by default)
- `:all` - compile assets when running all the guards (Ctrl-/) (not enabled by default)
2011-06-17 13:23:04 +00:00
2011-10-10 22:38:13 +00:00
You can also set the `:runner` option:
2011-08-02 12:22:03 +00:00
- `:cli` - compile assets using the rake task - the most correct method, but slow.
2011-09-04 08:09:45 +00:00
- `:rails` - compile assets by loading rails environment (default) - fast, but does not pick up changes. Additionally it relies on a single instance of your app to be loaded, so you can't have multiple guards with different rails configurations.
2011-08-02 12:22:03 +00:00
2011-10-10 22:38:13 +00:00
Additional options are:
- `:rails_env` - specify the Rails environment to use (defaults to 'test').
- `:digest` - overrides the `config.asset.digest` setting (for production env it is usually `true` , for test - `false` ).
2011-08-02 12:22:03 +00:00
2011-06-17 13:23:04 +00:00
For example:
```ruby
2011-08-02 12:22:03 +00:00
# This is the default behaviour
2011-09-04 07:57:57 +00:00
guard 'rails-assets', :run_on => [:start, :change], :runner => :rails, :rails_env => 'test' do
2011-06-17 13:23:04 +00:00
watch(%r{^app/assets/.+$})
end
2011-08-02 12:22:03 +00:00
# compile ONLY when something changes
guard 'rails-assets', :run_on => :change do
2011-06-17 13:23:04 +00:00
watch(%r{^app/assets/.+$})
end
2011-08-02 12:22:03 +00:00
# compile when something changes and when starting
2011-07-08 03:50:12 +00:00
guard 'rails-assets', :run_on => [:start, :change] do
2011-06-17 13:23:04 +00:00
watch(%r{^app/assets/.+$})
end
```
## Development
- Source hosted at [GitHub ](https://github.com/dnagir/guard-rails-assets )
- Report issues and feature requests to [GitHub Issues ](https://github.com/dnagir/guard-rails-assets/issues )
Pull requests are very welcome!
2011-07-08 03:50:12 +00:00
## Licensed under WTFPL
```
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Dmytrii Nagirniak < dnagir @ gmail . com >
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
```