guard-sprockets 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +70 -0
- data/lib/guard/sprockets.rb +50 -49
- data/lib/guard/sprockets/templates/Guardfile +2 -2
- data/lib/guard/sprockets/version.rb +5 -0
- metadata +61 -14
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Guard::Sprockets [![Build Status](https://secure.travis-ci.org/guard/guard-sprockets.png?branch=master)](http://travis-ci.org/guard/guard-sprockets)
|
2
|
+
|
3
|
+
Sprockets guard automatically packages your JavaScript files together when your source files are saved.
|
4
|
+
|
5
|
+
* Compatible with Sprockets 2.x (for Sprockets 1.x compatibility, please use Guard::Sprockets 0.1.4 or the `sprockets_1` branch).
|
6
|
+
* Tested against Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest versions of JRuby & Rubinius.
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Please be sure to have [Guard](https://github.com/guard/guard) installed before continue.
|
11
|
+
|
12
|
+
Install the gem:
|
13
|
+
|
14
|
+
```
|
15
|
+
$ gem install guard-sprockets
|
16
|
+
```
|
17
|
+
|
18
|
+
Add it to your Gemfile (inside the `:tools` group for instance):
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
group :tools do
|
22
|
+
gem 'guard-sprockets'
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Add guard definition to your Guardfile by running this command:
|
27
|
+
|
28
|
+
```
|
29
|
+
$ guard init sprockets
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Please read [Guard usage doc](https://github.com/guard/guard#readme)
|
35
|
+
|
36
|
+
## Guardfile
|
37
|
+
|
38
|
+
Guard::Sprockets can be adapted to all kind of projects.
|
39
|
+
|
40
|
+
### Typical Rails 3 app (default generated Guardfile)
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
guard 'sprockets', :destination => 'public/javascripts', :asset_paths => ['/app/assets/javascripts'] do
|
44
|
+
watch 'app/assets/javascripts/application.js'
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Please read [Guard doc](https://github.com/guard/guard#readme) for more information about the Guardfile DSL.
|
49
|
+
|
50
|
+
## Options
|
51
|
+
|
52
|
+
``` ruby
|
53
|
+
:destination => 'public/js' # change the destination folder in which the compiled assets are saved, default: 'public/javascripts'
|
54
|
+
:asset_paths => 'app/js' # add a directory (or on array of directories) to Sprockets' environment's load path, default: ['app/assets/javascripts']
|
55
|
+
:asset_paths => ['app/js', 'lib/js'] # asset_paths can be a String or an Array
|
56
|
+
:minify => true # minify the JavaScript files content using Uglifier, default: false
|
57
|
+
# be sure to add: "gem 'uglifier'" in your Gemfile
|
58
|
+
:root_file => 'app/js/app.js' # if set, only this file will be compiled, default: nil
|
59
|
+
```
|
60
|
+
|
61
|
+
## License
|
62
|
+
(The MIT License)
|
63
|
+
|
64
|
+
Copyright (c) 2011-2012 Aaron Cruz
|
65
|
+
|
66
|
+
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:
|
67
|
+
|
68
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
69
|
+
|
70
|
+
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.
|
data/lib/guard/sprockets.rb
CHANGED
@@ -6,84 +6,85 @@ require 'execjs'
|
|
6
6
|
|
7
7
|
module Guard
|
8
8
|
class Sprockets < Guard
|
9
|
-
def initialize(watchers=[], options={})
|
10
|
-
super
|
11
9
|
|
12
|
-
|
10
|
+
attr_reader :asset_paths, :destination, :root_file, :sprockets
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def initialize(watchers = [], options = {})
|
13
|
+
super(watchers, options)
|
14
|
+
|
15
|
+
@options = options
|
16
|
+
@asset_paths = Array(@options[:asset_paths] || 'app/assets/javascripts')
|
17
|
+
@destination = @options[:destination] || 'public/javascripts'
|
18
|
+
@root_file = @options[:root_file]
|
19
|
+
|
20
|
+
@sprockets = ::Sprockets::Environment.new
|
21
|
+
@asset_paths.each { |p| @sprockets.append_path(p) }
|
22
|
+
@sprockets.append_path(@root_file) if @root_file
|
18
23
|
|
19
|
-
if options.delete(:minify)
|
24
|
+
if @options.delete(:minify)
|
20
25
|
begin
|
21
26
|
require 'uglifier'
|
22
|
-
@
|
23
|
-
UI.info
|
24
|
-
rescue
|
25
|
-
UI.error "minify: Uglifier cannot be loaded. No compression will be used.\nPlease include 'uglifier' in your Gemfile
|
27
|
+
@sprockets.js_compressor = ::Uglifier.new
|
28
|
+
UI.info 'Sprockets will compress output.'
|
29
|
+
rescue LoadError => ex
|
30
|
+
UI.error "minify: Uglifier cannot be loaded. No compression will be used.\nPlease include 'uglifier' in your Gemfile."
|
31
|
+
UI.debug ex.message
|
26
32
|
end
|
27
33
|
end
|
28
|
-
# store the output destination
|
29
|
-
@destination = options.delete(:destination)
|
30
|
-
@root_file = options.delete(:root_file)
|
31
|
-
|
32
|
-
@opts = options
|
33
34
|
end
|
34
35
|
|
35
36
|
def start
|
36
|
-
UI.info
|
37
|
-
UI.
|
38
|
-
UI.
|
39
|
-
UI.info "Sprockets guard is ready and waiting for some file changes..."
|
37
|
+
UI.info 'Guard::Sprockets is ready and waiting for some file changes...'
|
38
|
+
UI.debug "Guard::Sprockets.asset_paths = #{@asset_paths.inspect}" unless @asset_paths.empty?
|
39
|
+
UI.debug "Guard::Sprockets.destination = #{@destination.inspect}"
|
40
40
|
|
41
41
|
run_all
|
42
42
|
end
|
43
43
|
|
44
44
|
def run_all
|
45
|
-
run_on_change([
|
46
|
-
|
47
|
-
true
|
45
|
+
run_on_change([@root_file]) if @root_file
|
48
46
|
end
|
49
47
|
|
50
|
-
def
|
51
|
-
if @root_file
|
52
|
-
sprocketize(@root_file)
|
53
|
-
else
|
54
|
-
paths.each do |file|
|
55
|
-
sprocketize(file)
|
56
|
-
end
|
57
|
-
end
|
48
|
+
def run_on_changes(paths)
|
49
|
+
paths = [@root_file] if @root_file
|
58
50
|
|
59
|
-
true
|
51
|
+
success = true
|
52
|
+
paths.each do |file|
|
53
|
+
success &= sprocketize(file)
|
54
|
+
end
|
55
|
+
success
|
60
56
|
end
|
61
57
|
|
62
58
|
private
|
63
59
|
|
64
60
|
def sprocketize(path)
|
65
|
-
|
61
|
+
path = Pathname.new(path)
|
66
62
|
|
67
|
-
@sprockets.append_path
|
63
|
+
@sprockets.append_path(path.dirname) unless @sprockets.paths.include?(path.dirname)
|
68
64
|
|
69
|
-
|
70
|
-
|
65
|
+
output_filename = without_preprocessor_extension(path.basename.to_s)
|
66
|
+
output_path = Pathname.new(File.join(@destination, output_filename))
|
71
67
|
|
72
|
-
|
68
|
+
UI.info "Sprockets will compile #{output_filename}"
|
73
69
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
output_file.open('w') do |f|
|
78
|
-
f.write @sprockets[output_basename]
|
70
|
+
FileUtils.mkdir_p(output_path.parent) unless output_path.parent.exist?
|
71
|
+
output_path.open('w') do |f|
|
72
|
+
f.write @sprockets[output_filename]
|
79
73
|
end
|
80
74
|
|
81
|
-
UI.info "Sprockets
|
82
|
-
Notifier.notify "
|
83
|
-
rescue ExecJS::ProgramError =>
|
84
|
-
UI.error "Sprockets failed
|
85
|
-
UI.error
|
86
|
-
Notifier.notify "
|
75
|
+
UI.info "Sprockets compiled #{output_filename}"
|
76
|
+
Notifier.notify "Sprockets compiled #{output_filename}"
|
77
|
+
rescue ExecJS::ProgramError => ex
|
78
|
+
UI.error "Sprockets failed compiling #{output_filename}"
|
79
|
+
UI.error ex.message
|
80
|
+
Notifier.notify "Sprockets failed compiling #{output_filename}!", :priority => 2, :image => :failed
|
81
|
+
|
82
|
+
false
|
87
83
|
end
|
84
|
+
|
85
|
+
def without_preprocessor_extension(filename)
|
86
|
+
filename.gsub(/^(.*\.(?:js|css))\.[^.]+$/, '\1')
|
87
|
+
end
|
88
|
+
|
88
89
|
end
|
89
90
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
guard 'sprockets', :destination =>
|
2
|
-
watch
|
1
|
+
guard 'sprockets', :destination => 'public/javascripts', :asset_paths => ['app/assets/javascripts'] do
|
2
|
+
watch 'app/assets/javascripts/application.js'
|
3
3
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-sprockets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,31 +10,73 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03
|
13
|
+
date: 2012-06-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: guard
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 1.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.1.0
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: sprockets
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ~>
|
32
37
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2'
|
38
|
+
version: '2.0'
|
34
39
|
type: :runtime
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.1'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '2.10'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2.10'
|
79
|
+
description: Guard::Sprockets automatically packages your javascript files together.
|
38
80
|
email:
|
39
81
|
- aaron@aaroncruz.com
|
40
82
|
- kematzy at gmail
|
@@ -43,8 +85,10 @@ extensions: []
|
|
43
85
|
extra_rdoc_files: []
|
44
86
|
files:
|
45
87
|
- lib/guard/sprockets/templates/Guardfile
|
88
|
+
- lib/guard/sprockets/version.rb
|
46
89
|
- lib/guard/sprockets.rb
|
47
|
-
|
90
|
+
- README.md
|
91
|
+
homepage: https://rubygems.org/gems/guard-sprockets
|
48
92
|
licenses: []
|
49
93
|
post_install_message:
|
50
94
|
rdoc_options: []
|
@@ -56,16 +100,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
100
|
- - ! '>='
|
57
101
|
- !ruby/object:Gem::Version
|
58
102
|
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: 1279114043870312487
|
59
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
107
|
none: false
|
61
108
|
requirements:
|
62
109
|
- - ! '>='
|
63
110
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
111
|
+
version: 1.3.6
|
65
112
|
requirements: []
|
66
113
|
rubyforge_project: guard-sprockets
|
67
|
-
rubygems_version: 1.8.
|
114
|
+
rubygems_version: 1.8.23
|
68
115
|
signing_key:
|
69
116
|
specification_version: 3
|
70
|
-
summary:
|
117
|
+
summary: Guard gem for Sprockets
|
71
118
|
test_files: []
|