added template and README

This commit is contained in:
Dmytrii Nagirniak 2011-06-17 23:23:04 +10:00
parent 2983323f7a
commit fe50bfd1c1
5 changed files with 123 additions and 0 deletions

View File

@ -1,3 +1,5 @@
source "http://rubygems.org"
gemspec
gem 'rake'

View File

@ -10,6 +10,7 @@ GEM
diff-lcs (1.1.2)
guard (0.4.2)
thor (~> 0.14.6)
rake (0.9.2)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
@ -25,4 +26,5 @@ PLATFORMS
DEPENDENCIES
guard-rails-assets!
rake
rspec

108
README.md Normal file
View File

@ -0,0 +1,108 @@
# 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](http://www.ApproachE.com).
## Install
Please be sure to have [Guard](https://github.com/guard/guard) installed.
Install the gem:
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
$ 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 convention used in this guard are:
- assets prefix is set to 'assets' meaning that all assets are compiled in to `public/assets` folder;
- the assets folder 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:
```ruby
# 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
- 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!
## License
(The MIT License)
Copyright (c) 2010 - 2011 Michael Kessler
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -25,9 +25,11 @@ module Guard
end
def compile_assets
puts 'Compiling rails assets'
result = system "rm -rf public/assets && bundle exec rake assets:precompile"
if result
tree = `tree public/assets`
puts tree
summary = tree.split("\n").last
Notifier::notify summary, :title => 'Assets compiled'
else
@ -40,6 +42,7 @@ module Guard
def run_for? command
run_on = @options[:run_on]
run_on = [:start, :all, :change] if not run_on or run_on.empty?
run_on = [run_on] unless run_on.respond_to?(:include?)
run_on.include?(command)
end
end

View File

@ -0,0 +1,8 @@
# Make sure this guard is ABOVE any guards using assets such as jasmine-headless-webkit
# It is recommended to make explicit list of assets in `config/application.rb`
# config.assets.precompile = ['application.js', 'application.css', 'all-ie.css']
guard 'rails-assets' do
watch(%r{^app/assets/.+$})
watch('config/application.rb')
end