guard-sprockets 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/guard/sprockets.rb +50 -21
- data/lib/guard/sprockets/templates/Guardfile +1 -1
- metadata +7 -8
- data/lib/guard/sprockets/version.rb +0 -6
data/lib/guard/sprockets.rb
CHANGED
@@ -1,60 +1,89 @@
|
|
1
1
|
require 'guard'
|
2
2
|
require 'guard/guard'
|
3
|
-
require 'erb'
|
4
3
|
|
5
4
|
require 'sprockets'
|
5
|
+
require 'execjs'
|
6
6
|
|
7
7
|
module Guard
|
8
8
|
class Sprockets < Guard
|
9
9
|
def initialize(watchers=[], options={})
|
10
|
-
super
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
super
|
11
|
+
|
12
|
+
@sprockets = ::Sprockets::Environment.new
|
13
|
+
|
15
14
|
@asset_paths = options.delete(:asset_paths) || []
|
16
|
-
# add the asset_paths to the Sprockets env
|
17
15
|
@asset_paths.each do |p|
|
18
|
-
@
|
16
|
+
@sprockets.append_path p
|
17
|
+
end
|
18
|
+
|
19
|
+
if options.delete(:minify)
|
20
|
+
begin
|
21
|
+
require 'uglifier'
|
22
|
+
@sprockets_env.js_compressor = ::Uglifier.new
|
23
|
+
UI.info "Sprockets will compress output (minify)."
|
24
|
+
rescue
|
25
|
+
UI.error "minify: Uglifier cannot be loaded. No compression will be used.\nPlease include 'uglifier' in your Gemfile.\n#{$!}"
|
26
|
+
end
|
19
27
|
end
|
20
28
|
# store the output destination
|
21
29
|
@destination = options.delete(:destination)
|
30
|
+
@root_file = options.delete(:root_file)
|
31
|
+
|
22
32
|
@opts = options
|
23
33
|
end
|
24
34
|
|
25
35
|
def start
|
26
|
-
UI.info "Sprockets
|
27
|
-
UI.info "
|
28
|
-
UI.info "
|
36
|
+
UI.info "Sprockets activated."
|
37
|
+
UI.info " - external asset paths = #{@asset_paths.inspect}" unless @asset_paths.empty?
|
38
|
+
UI.info " - destination path = #{@destination.inspect}"
|
39
|
+
UI.info "Sprockets guard is ready and waiting for some file changes..."
|
40
|
+
|
41
|
+
run_all
|
29
42
|
end
|
30
|
-
|
43
|
+
|
31
44
|
def run_all
|
45
|
+
run_on_change([ @root_file ]) if @root_file
|
46
|
+
|
32
47
|
true
|
33
48
|
end
|
34
49
|
|
35
50
|
def run_on_change(paths)
|
36
|
-
|
51
|
+
if @root_file
|
52
|
+
sprocketize(@root_file)
|
53
|
+
else
|
54
|
+
paths.each do |file|
|
55
|
+
sprocketize(file)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
37
59
|
true
|
38
60
|
end
|
39
|
-
|
61
|
+
|
40
62
|
private
|
41
|
-
|
63
|
+
|
42
64
|
def sprocketize(path)
|
43
65
|
changed = Pathname.new(path)
|
44
66
|
|
45
|
-
@
|
67
|
+
@sprockets.append_path changed.dirname
|
46
68
|
|
47
69
|
output_basename = changed.basename.to_s
|
48
|
-
|
49
|
-
output_basename = match[1]
|
50
|
-
end
|
70
|
+
output_basename.gsub!(/^(.*\.(?:js|css))\.[^.]+$/, '\1')
|
51
71
|
|
52
72
|
output_file = Pathname.new(File.join(@destination, output_basename))
|
53
|
-
|
73
|
+
|
74
|
+
UI.info "Sprockets: compiling #{output_file}"
|
75
|
+
|
54
76
|
FileUtils.mkdir_p(output_file.parent) unless output_file.parent.exist?
|
55
77
|
output_file.open('w') do |f|
|
56
|
-
f.write @
|
78
|
+
f.write @sprockets[output_basename]
|
57
79
|
end
|
80
|
+
|
81
|
+
UI.info "Sprockets finished compiling #{output_file}"
|
82
|
+
Notifier.notify "Compiled #{output_basename}"
|
83
|
+
rescue ExecJS::ProgramError => e
|
84
|
+
UI.error "Sprockets failed to compile #{output_file}"
|
85
|
+
UI.error e.message
|
86
|
+
Notifier.notify "Syntax error in #{output_basename}: #{e.message}", :priority => 2, :image => :failed
|
58
87
|
end
|
59
88
|
end
|
60
89
|
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.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2012-03-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: guard
|
17
|
-
requirement: &
|
17
|
+
requirement: &70307030217180 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.2.2
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70307030217180
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sprockets
|
28
|
-
requirement: &
|
28
|
+
requirement: &70307030213960 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70307030213960
|
37
37
|
description: guard file for sprockets
|
38
38
|
email:
|
39
39
|
- aaron@aaroncruz.com
|
@@ -43,7 +43,6 @@ extensions: []
|
|
43
43
|
extra_rdoc_files: []
|
44
44
|
files:
|
45
45
|
- lib/guard/sprockets/templates/Guardfile
|
46
|
-
- lib/guard/sprockets/version.rb
|
47
46
|
- lib/guard/sprockets.rb
|
48
47
|
homepage: http://aaroncruz.com
|
49
48
|
licenses: []
|