guard-sprockets 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
+ require 'erb'
3
4
 
4
5
  require 'sprockets'
5
6
 
@@ -7,11 +8,24 @@ module Guard
7
8
  class Sprockets < Guard
8
9
  def initialize(watchers=[], options={})
9
10
  super
10
- @destination = options[:destination]
11
+
12
+ # init Sprocket env for use later
13
+ @sprockets_env = ::Sprockets::Environment.new
14
+
15
+ @asset_paths = options.delete(:asset_paths) || []
16
+ # add the asset_paths to the Sprockets env
17
+ @asset_paths.each do |p|
18
+ @sprockets_env.append_path p
19
+ end
20
+ # store the output destination
21
+ @destination = options.delete(:destination)
22
+ @opts = options
11
23
  end
12
24
 
13
25
  def start
14
- UI.info "Sprockets waiting for js file changes..."
26
+ UI.info "Sprockets waiting for asset file changes..."
27
+ UI.info " -- external asset paths = [#{@asset_paths.inspect}]" unless @asset_paths.empty?
28
+ UI.info " -- destination path = [#{@destination.inspect}]"
15
29
  end
16
30
 
17
31
  def run_all
@@ -19,29 +33,28 @@ module Guard
19
33
  end
20
34
 
21
35
  def run_on_change(paths)
22
- sprocketize paths.first
36
+ paths.each{ |js| sprocketize(js) }
37
+ true
23
38
  end
24
39
 
25
40
  private
26
41
 
27
42
  def sprocketize(path)
28
- parts = path.split('/')
29
- file = parts.pop
30
- source_dir = "#{parts[0...-1].join('/')}/*"
31
- destination = parts[1..-1].join('/')
32
- @destination ||= destination
33
- secretary = ::Sprockets::Secretary.new(
34
- :asset_root => "#{parts.first}",
35
- :source_files => ["#{path}"],
36
- :interpolate_constants => false
37
- )
38
- # Generate a Sprockets::Concatenation object from the source files
39
- concatenation = secretary.concatenation
40
- # Write the concatenation to disk
41
- concatenation.save_to("#{@destination}/#{file}")
42
- # Install provided assets into the asset root
43
- secretary.install_assets
44
- UI.info "Sprockets creating file #{@destination}/#{file}"
43
+ changed = Pathname.new(path)
44
+
45
+ @sprockets_env.append_path changed.dirname
46
+
47
+ output_basename = changed.basename.to_s
48
+ if match = output_basename.match(/^(.*\.(?:js|css))\.[^.]+$/)
49
+ output_basename = match[1]
50
+ end
51
+
52
+ output_file = Pathname.new(File.join(@destination, output_basename))
53
+ UI.info "Sprockets creating file #{output_file}"
54
+ FileUtils.mkdir_p(output_file.parent) unless output_file.parent.exist?
55
+ output_file.open('w') do |f|
56
+ f.write @sprockets_env[output_basename]
57
+ end
45
58
  end
46
59
  end
47
60
  end
@@ -1,3 +1,3 @@
1
- guard 'sprockets', :destination => "public/javascripts" do
1
+ guard 'sprockets', :destination => "public/javascripts", :asset_paths => ['/app/assets/javascripts'] do
2
2
  watch (%r{app/assets/javascripts/application.js})
3
- end
3
+ end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Guard
3
3
  module Sprockets
4
- VERSION = '0.1.4'
4
+ VERSION = '0.2.0'
5
5
  end
6
- end
6
+ end
metadata CHANGED
@@ -1,79 +1,72 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: guard-sprockets
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
4
5
  prerelease:
5
- version: 0.1.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Aaron Cruz
9
+ - Kematzy
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
-
13
- date: 2011-05-12 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
13
+ date: 2011-12-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
16
  name: guard
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70194669080740 !ruby/object:Gem::Requirement
19
18
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
23
22
  version: 0.2.2
24
23
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: sprockets
28
24
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70194669080740
26
+ - !ruby/object:Gem::Dependency
27
+ name: sprockets
28
+ requirement: &70194669079080 !ruby/object:Gem::Requirement
30
29
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
35
34
  type: :runtime
36
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: *70194669079080
37
37
  description: guard file for sprockets
38
- email:
38
+ email:
39
39
  - aaron@aaroncruz.com
40
+ - kematzy at gmail
40
41
  executables: []
41
-
42
42
  extensions: []
43
-
44
43
  extra_rdoc_files: []
45
-
46
- files:
44
+ files:
47
45
  - lib/guard/sprockets/templates/Guardfile
48
46
  - lib/guard/sprockets/version.rb
49
47
  - lib/guard/sprockets.rb
50
48
  homepage: http://aaroncruz.com
51
49
  licenses: []
52
-
53
50
  post_install_message:
54
51
  rdoc_options: []
55
-
56
- require_paths:
52
+ require_paths:
57
53
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
54
+ required_ruby_version: !ruby/object:Gem::Requirement
59
55
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
61
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
70
66
  requirements: []
71
-
72
67
  rubyforge_project: guard-sprockets
73
- rubygems_version: 1.7.2
68
+ rubygems_version: 1.8.11
74
69
  signing_key:
75
70
  specification_version: 3
76
71
  summary: guard file for sprockets
77
72
  test_files: []
78
-
79
- has_rdoc: