guard-rails-assets 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +30 -0
- data/README.md +108 -0
- data/Rakefile +1 -0
- data/guard-rails-assets.gemspec +23 -0
- data/lib/guard/rails-assets.rb +49 -0
- data/lib/guard/rails-assets/templates/Guardfile +8 -0
- data/lib/guard/version.rb +5 -0
- data/spec/guard/rails-assets_spec.rb +51 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/shared_examples.rb +31 -0
- metadata +86 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
guard-rails-assets (0.0.1)
|
5
|
+
guard
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.2)
|
11
|
+
guard (0.4.2)
|
12
|
+
thor (~> 0.14.6)
|
13
|
+
rake (0.9.2)
|
14
|
+
rspec (2.6.0)
|
15
|
+
rspec-core (~> 2.6.0)
|
16
|
+
rspec-expectations (~> 2.6.0)
|
17
|
+
rspec-mocks (~> 2.6.0)
|
18
|
+
rspec-core (2.6.4)
|
19
|
+
rspec-expectations (2.6.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.6.0)
|
22
|
+
thor (0.14.6)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
guard-rails-assets!
|
29
|
+
rake
|
30
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Guard::RailsAssets
|
2
|
+
|
3
|
+
|
4
|
+
Guard::RailsAssets compiles all the assets in Rails 3.1 application automatically when files are modified.
|
5
|
+
|
6
|
+
Tested on MRI Ruby 1.9.2 (please report if it works on your platform).
|
7
|
+
Currently only POSIX system is supported. Sorry Windows guys :(
|
8
|
+
|
9
|
+
If you have any questions please contact me [@dnagir](http://www.ApproachE.com).
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
Please be sure to have [Guard](https://github.com/guard/guard) installed.
|
14
|
+
|
15
|
+
Install the gem:
|
16
|
+
|
17
|
+
Add it to your `Gemfile`, preferably inside the test and development group:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'guard-rails-assets'
|
21
|
+
```
|
22
|
+
|
23
|
+
Add guard definition to your `Guardfile` by running:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ guard init rails-assets
|
27
|
+
```
|
28
|
+
|
29
|
+
## Rails 3.1
|
30
|
+
|
31
|
+
The Rails 3.1 is a mandatory requirement, but is not enforeced via dependencies for now.
|
32
|
+
The reason is that the assets are currently compiled via command line and thus this guard does not
|
33
|
+
explicitly depend on Rails.
|
34
|
+
|
35
|
+
Good thing about it is that assets will always be same as produced by Rails.
|
36
|
+
Bad thing is that it is pretty slow (~10 seconds) because it starts Rails from ground zero.
|
37
|
+
|
38
|
+
## Rails Assets Pipeline
|
39
|
+
|
40
|
+
The convention used in this guard are:
|
41
|
+
|
42
|
+
- assets prefix is set to 'assets' meaning that all assets are compiled in to `public/assets` folder;
|
43
|
+
- the assets folder is disposable and can be cleared out.
|
44
|
+
|
45
|
+
If the conventions above are not valid for you then perhaps you'd better submit a patch.
|
46
|
+
|
47
|
+
## Guardfile and Options
|
48
|
+
|
49
|
+
In addition to the standard configuration, this Guard has options to specify when exacly to precompile assets.
|
50
|
+
|
51
|
+
- `:start` - compile assets when the guard starts (default)
|
52
|
+
- `:reload` - compile assets when the guard quites (Ctrl-C) (not enabled)
|
53
|
+
- `:all` - compile assets when running all the guard (Ctrl-/) (default)
|
54
|
+
- `:change` - compile assets when watched files change (default)
|
55
|
+
|
56
|
+
For example:
|
57
|
+
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# compile ONLY when something changes
|
61
|
+
guard 'rails-assets', :run_on => :change do
|
62
|
+
watch(%r{^app/assets/.+$})
|
63
|
+
end
|
64
|
+
|
65
|
+
# compile when something changes and when starting
|
66
|
+
guard 'rails-assets', :run_on => [:start, :change] do
|
67
|
+
watch(%r{^app/assets/.+$})
|
68
|
+
end
|
69
|
+
|
70
|
+
# This is the default behaviour
|
71
|
+
guard 'rails-assets', :run_on => [:start, :change, :all] do
|
72
|
+
watch(%r{^app/assets/.+$})
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Development
|
77
|
+
|
78
|
+
- Source hosted at [GitHub](https://github.com/dnagir/guard-rails-assets)
|
79
|
+
- Report issues and feature requests to [GitHub Issues](https://github.com/dnagir/guard-rails-assets/issues)
|
80
|
+
|
81
|
+
|
82
|
+
Pull requests are very welcome!
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
(The MIT License)
|
87
|
+
|
88
|
+
Copyright (c) 2010 - 2011 Michael Kessler
|
89
|
+
|
90
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
91
|
+
a copy of this software and associated documentation files (the
|
92
|
+
'Software'), to deal in the Software without restriction, including
|
93
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
94
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
95
|
+
permit persons to whom the Software is furnished to do so, subject to
|
96
|
+
the following conditions:
|
97
|
+
|
98
|
+
The above copyright notice and this permission notice shall be
|
99
|
+
included in all copies or substantial portions of the Software.
|
100
|
+
|
101
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
102
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
103
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
104
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
105
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
106
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
107
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
108
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "guard/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "guard-rails-assets"
|
7
|
+
s.version = Guard::RailsAssetsVersion::VERSION
|
8
|
+
s.authors = ["Dmytrii Nagirniak"]
|
9
|
+
s.email = ["dnagir@gmail.com"]
|
10
|
+
s.homepage = "http://github.com/dnagir/guard-rails-assets"
|
11
|
+
s.summary = %q{Guard for compiling Rails assets}
|
12
|
+
s.description = %q{guard-rails-assets automatically generates JavaScript, CSS, Image files using Rails assets pipelie}
|
13
|
+
|
14
|
+
s.rubyforge_project = "guard-rails-assets"
|
15
|
+
|
16
|
+
s.add_dependency 'guard'
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
|
4
|
+
module Guard
|
5
|
+
class RailsAssets < Guard
|
6
|
+
def initialize(watchers=[], options={})
|
7
|
+
super
|
8
|
+
@options = options || {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
compile_assets if run_for? :start
|
13
|
+
end
|
14
|
+
|
15
|
+
def reload
|
16
|
+
compile_assets if run_for? :reload
|
17
|
+
end
|
18
|
+
|
19
|
+
def run_all
|
20
|
+
compile_assets if run_for? :all
|
21
|
+
end
|
22
|
+
|
23
|
+
def run_on_change(paths=[])
|
24
|
+
compile_assets if run_for? :change
|
25
|
+
end
|
26
|
+
|
27
|
+
def compile_assets
|
28
|
+
puts 'Compiling rails assets'
|
29
|
+
result = system "rm -rf public/assets && bundle exec rake assets:precompile"
|
30
|
+
if result
|
31
|
+
tree = `tree public/assets`
|
32
|
+
puts tree
|
33
|
+
summary = tree.split("\n").last
|
34
|
+
Notifier::notify summary, :title => 'Assets compiled'
|
35
|
+
else
|
36
|
+
Notifier::notify 'see the details in the terminal', :title => "Can't compile assets", :image => :failed
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def run_for? command
|
43
|
+
run_on = @options[:run_on]
|
44
|
+
run_on = [:start, :all, :change] if not run_on or run_on.empty?
|
45
|
+
run_on = [run_on] unless run_on.respond_to?(:include?)
|
46
|
+
run_on.include?(command)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
# Make sure this guard is ABOVE any guards using assets such as jasmine-headless-webkit
|
3
|
+
# It is recommended to make explicit list of assets in `config/application.rb`
|
4
|
+
# config.assets.precompile = ['application.js', 'application.css', 'all-ie.css']
|
5
|
+
guard 'rails-assets' do
|
6
|
+
watch(%r{^app/assets/.+$})
|
7
|
+
watch('config/application.rb')
|
8
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'guard/rails-assets'
|
3
|
+
|
4
|
+
describe Guard::RailsAssets do
|
5
|
+
let(:options) { {} }
|
6
|
+
subject { Guard::RailsAssets.new(['watchers'], options) }
|
7
|
+
|
8
|
+
it 'should be able to create guard' do
|
9
|
+
::Guard::RailsAssets.new(['watchers'], {:options=>:here}).should_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#start' do
|
13
|
+
it_behaves_like 'guard command', :command => :start, :run => true
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#reload' do
|
17
|
+
it_behaves_like 'guard command', :command => :reload, :run => false
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#run_all' do
|
21
|
+
it_behaves_like 'guard command', :command => :run_all, :run => true
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#run_on_change' do
|
25
|
+
it_behaves_like 'guard command', :command => :run_on_change, :run => true
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
describe 'asset compilation using CLI' do
|
30
|
+
def stub_system_with result
|
31
|
+
subject.should_receive(:system).with("rm -rf public/assets && bundle exec rake assets:precompile").and_return result
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should notify on success' do
|
35
|
+
stub_system_with true
|
36
|
+
subject.should_receive(:`).with('tree public/assets').and_return "a\nb\n1 directory, 2 files"
|
37
|
+
Guard::Notifier.should_receive(:notify).with('1 directory, 2 files', :title => 'Assets compiled')
|
38
|
+
subject.compile_assets
|
39
|
+
end
|
40
|
+
it 'should notify on failure' do
|
41
|
+
stub_system_with false
|
42
|
+
Kernel.should_not_receive(:`)
|
43
|
+
Guard::Notifier.should_receive(:notify).with('see the details in the terminal', :title => "Can't compile assets", :image => :failed)
|
44
|
+
subject.compile_assets
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'custom assets prefix' do
|
49
|
+
it 'should use given prefix'
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'guard/rails-assets'
|
3
|
+
require 'support/shared_examples'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.color_enabled = true
|
7
|
+
config.filter_run :focus => true
|
8
|
+
config.run_all_when_everything_filtered = true
|
9
|
+
|
10
|
+
config.before(:each) do
|
11
|
+
ENV["GUARD_ENV"] = 'test'
|
12
|
+
@project_path = Pathname.new(File.expand_path('../../', __FILE__))
|
13
|
+
end
|
14
|
+
|
15
|
+
config.after(:each) do
|
16
|
+
ENV["GUARD_ENV"] = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
shared_examples_for "guard command" do |info|
|
2
|
+
|
3
|
+
def set_run_on_option info
|
4
|
+
# run_on_change -> change
|
5
|
+
# run_all -> all
|
6
|
+
run_option = info[:command].to_s.match(/(.*_)?(\w+)/)[2].to_sym
|
7
|
+
options[:run_on] = [run_option]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should execute #{info[:command]} when said so" do
|
11
|
+
set_run_on_option info
|
12
|
+
subject.should_receive(:compile_assets)
|
13
|
+
subject.send(info[:command])
|
14
|
+
end
|
15
|
+
it "should not execute #{info[:command]} when disabled" do
|
16
|
+
options[:run_on] = [:something_other]
|
17
|
+
subject.should_not_receive(:compile_assets)
|
18
|
+
subject.send(info[:command])
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should #{info[:run] ? '' : 'not '}execute #{info[:command]} by default" do
|
22
|
+
options[:run_on] = nil
|
23
|
+
if info[:run]
|
24
|
+
subject.should_receive(:compile_assets)
|
25
|
+
else
|
26
|
+
subject.should_not_receive(:compile_assets)
|
27
|
+
end
|
28
|
+
subject.send(info[:command])
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: guard-rails-assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dmytrii Nagirniak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-06-17 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: guard
|
16
|
+
requirement: &15869340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *15869340
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &15825660 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *15825660
|
36
|
+
description: guard-rails-assets automatically generates JavaScript, CSS, Image files
|
37
|
+
using Rails assets pipelie
|
38
|
+
email:
|
39
|
+
- dnagir@gmail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- guard-rails-assets.gemspec
|
50
|
+
- lib/guard/rails-assets.rb
|
51
|
+
- lib/guard/rails-assets/templates/Guardfile
|
52
|
+
- lib/guard/version.rb
|
53
|
+
- spec/guard/rails-assets_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/support/shared_examples.rb
|
56
|
+
homepage: http://github.com/dnagir/guard-rails-assets
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
hash: -3097363919137116973
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
hash: -3097363919137116973
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project: guard-rails-assets
|
82
|
+
rubygems_version: 1.8.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Guard for compiling Rails assets
|
86
|
+
test_files: []
|