guard-llsprockets 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b04f4a0f27636d5faa6e521e9fb5ecb8cd7e1ec9
4
+ data.tar.gz: a3b94f5bc993d74254feb849e16b02715397e2b4
5
+ SHA512:
6
+ metadata.gz: 221bacd51ebacc33c1ad594d367645ade4b5b494b93c0845d2353ebe299837726f20daf44dbaca3193649da7ef86cb9a81b318fb4325941c800fe28bbdf8bb33
7
+ data.tar.gz: 01aaa1e72123afd4ebae309c1389400af3cfa7daa34464fda87cf1878fe7b0d36a2427e87d1bc250ed2145c55bb218b2549d60b236782dd1c3f86e480ba2678d
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Guard::Sprockets [![Build Status](https://secure.travis-ci.org/guard/guard-llsprockets.png?branch=master)](http://travis-ci.org/guard/guard-llsprockets)
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-llsprockets
16
+ ```
17
+
18
+ Add it to your Gemfile (inside the `:tools` group for instance):
19
+
20
+ ```ruby
21
+ group :tools do
22
+ gem 'guard-llsprockets'
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
+ :root_file => ['one.js', 'two.js'] # root_file can be a String or an Array
60
+ ```
61
+
62
+ ## License
63
+ (The MIT License)
64
+
65
+ Copyright (c) 2011-2012 Aaron Cruz
66
+
67
+ 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:
68
+
69
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
70
+
71
+ 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.
@@ -0,0 +1,3 @@
1
+ guard 'sprockets', :destination => 'public/javascripts', :asset_paths => ['app/assets/javascripts'] do
2
+ watch 'app/assets/javascripts/application.js'
3
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module SprocketsVersion
3
+ VERSION = '0.2'
4
+ end
5
+ end
@@ -0,0 +1,89 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ require 'sprockets'
5
+ require 'execjs'
6
+
7
+ module Guard
8
+ class Sprockets < Guard
9
+
10
+ attr_reader :asset_paths, :destination, :root_file, :sprockets
11
+
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 = Array(@options[:root_file])
19
+
20
+ @sprockets = ::Sprockets::Environment.new
21
+ @asset_paths.each { |p| @sprockets.append_path(p) }
22
+ @root_file.each { |f| @sprockets.append_path(Pathname.new(f).dirname) }
23
+
24
+ if @options.delete(:minify)
25
+ begin
26
+ require 'uglifier'
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
32
+ end
33
+ end
34
+ end
35
+
36
+ def start
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
+
41
+ run_all
42
+ end
43
+
44
+ def run_all
45
+ run_on_changes []
46
+ end
47
+
48
+ def run_on_changes(paths)
49
+ paths = @root_file unless @root_file.empty?
50
+
51
+ success = true
52
+ paths.each do |file|
53
+ success &= sprocketize(file)
54
+ end
55
+ success
56
+ end
57
+
58
+ private
59
+
60
+ def sprocketize(path)
61
+ path = Pathname.new(path)
62
+
63
+ input_filename = without_preprocessor_extension(path.basename.to_s)
64
+
65
+ output_filename = without_preprocessor_extension(path.basename.to_s).reverse.sub(".".reverse, ".min.".reverse).reverse
66
+ output_path = Pathname.new(File.join(@destination, output_filename))
67
+
68
+ UI.info "Sprockets will compile #{path} -> #{output_path}"
69
+
70
+ FileUtils.mkdir_p(output_path.parent) unless output_path.parent.exist?
71
+ output_path.open('w') do |f|
72
+ f.write @sprockets[input_filename]
73
+ end
74
+
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
83
+ end
84
+
85
+ def without_preprocessor_extension(filename)
86
+ filename.gsub(/^(.*\.(?:js|css))\.[^.]+(\.erb)?$/, '\1')
87
+ end
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-llsprockets
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Christian menix Hahn
8
+ - Aaron Cruz
9
+ - Kematzy
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-08-20 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: guard
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: 1.1.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: execjs
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: sprockets
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '2.0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '2.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: bundler
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '1.1'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '1.1'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.10'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: '2.10'
85
+ description: Guard::Sprockets automatically packages your javascript files together.
86
+ email:
87
+ - chahn at livinglogic deaaron@aaroncruz.com
88
+ - kematzy at gmail
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - lib/guard/sprockets/templates/Guardfile
94
+ - lib/guard/sprockets/version.rb
95
+ - lib/guard/sprockets.rb
96
+ - README.md
97
+ homepage: https://rubygems.org/gems/guard-llsprockets
98
+ licenses: []
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: 1.3.6
114
+ requirements: []
115
+ rubyforge_project: guard-llsprockets
116
+ rubygems_version: 2.0.7
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Guard gem for Sprockets
120
+ test_files: []