guard-cogs 0.1.0

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: b3e99e91dc97119454caf3fcdf2c2face47c4803
4
+ data.tar.gz: abaaf0831275f2e75771abd5f5e29cd6542ddeb1
5
+ SHA512:
6
+ metadata.gz: 94b6b2ee926c6af8540585c433a8981cef680ed44c14af19df5f388fb7430f388c152a0150b85e3a427467e0128b2c5333d4bf796a4ce7aafba85d98923fff8e
7
+ data.tar.gz: b421b73f1239028f6d0d062835d930bf9847048449a8512777e93e3c54c06a8eaf8070152fb6ac7ae7757c2b26a10eb04a7e6d050e02336672ea310db6906d3c
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /.bundle/
2
+ /vendor/bundle/
3
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'coffee-script'
4
+ gem 'uglifier'
5
+ gem 'sass'
6
+ gem 'yui-compressor'
7
+ gem 'sprockets'
8
+ gem 'sprockets-sass'
9
+
10
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tim Garton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ guard-cogs
2
+ ==========
3
+
4
+ Guard plugin that uses sprockets to package your coffeescript, javascript, sass, and css files. Inspired by the guard-sprockets gem.
5
+
6
+ ## Install
7
+
8
+ Read up on [Guard](https://github.com/guard/guard) before continuing.
9
+
10
+ Add it to your Gemfile:
11
+
12
+ ```ruby
13
+ group :development, :test do
14
+ gem 'guard-cogs'
15
+ end
16
+ ```
17
+
18
+ Install the gem:
19
+
20
+ ```
21
+ $ bundle install --path vendor/bundle --binstubs vendor/bundle/bin --without production
22
+ ```
23
+
24
+ Add guard definition to your Guardfile by running this command:
25
+
26
+ ```
27
+ $ bundle exec guard init cogs
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ``` ruby
33
+ guard 'cogs', compile: ['app.coffee'], dest: 'public/javascripts', asset_paths: ['assets/scripts', 'assets/vendor/scripts'] do
34
+ watch(%r{^assets/.+\.(js|coffee)$})
35
+ end
36
+
37
+ guard 'cogs', compile: ['app.scss'], dest: 'public/stylesheets', asset_paths: ['assets/stylesheets', 'assets/vendor/stylesheets'] do
38
+ watch(%r{^assets/.+\.(css|scss)$})
39
+ end
40
+ ```
41
+
42
+ ## Options
43
+
44
+ ``` ruby
45
+ compile => ['app.coffee', 'assets/vendor/vendor.js' => 'vendor/deps.js'] # Array of files to generate in "dest". Use a hash if you want generated filename
46
+ # to be different than the source filename. Defaults to all watched files.
47
+ dest => 'public/javascripts' # Output folder. Defaults to '.'
48
+ asset_paths => ['assets/scripts', 'assets/vendor/scripts'] # Array of folders containing assets. Defaults to ['.']
49
+ minify => true # Minify generated files (uglifier for javascript, yui-compressor for stylesheets)
50
+ ```
51
+
52
+ ## License
53
+ (The MIT License)
54
+
55
+ Copyright (c) 2014 Tim Garton
56
+
57
+ 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:
58
+
59
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
60
+
61
+ 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/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/cogs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'guard-cogs'
8
+ spec.version = Guard::CogsVersion::VERSION
9
+ spec.authors = ['Tim Garton']
10
+ spec.email = ['garton.tim@gmail.com']
11
+ spec.summary = 'Guard gem for sprockets'
12
+ spec.description = 'Guard::Cogs packages your coffeescript, javascript, sass, and css.'
13
+ spec.homepage = 'https://rubygems.org/gems/guard-cogs'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'guard'
22
+ spec.add_dependency 'coffee-script'
23
+ spec.add_dependency 'uglifier'
24
+ spec.add_dependency 'sass'
25
+ spec.add_dependency 'yui-compressor'
26
+ spec.add_dependency 'sprockets', '~> 2.0'
27
+ spec.add_dependency 'sprockets-sass'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.6'
30
+ spec.add_development_dependency 'rake'
31
+ end
@@ -0,0 +1,7 @@
1
+ guard 'cogs', compile: ['app.coffee'], dest: 'public/javascripts', asset_paths: ['assets/scripts', 'assets/vendor/scripts'] do
2
+ watch(%r{^assets/.+\.(js|coffee)$})
3
+ end
4
+
5
+ guard 'cogs', compile: ['app.scss'], dest: 'public/stylesheets', asset_paths: ['assets/stylesheets', 'assets/vendor/stylesheets'] do
6
+ watch(%r{^assets/.+\.(css|scss)$})
7
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module CogsVersion
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/lib/guard/cogs.rb ADDED
@@ -0,0 +1,93 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'sprockets'
4
+
5
+ module Guard
6
+ class Cogs < Guard
7
+
8
+ def initialize(watchers = [], options = {})
9
+ super
10
+
11
+ @compile = options[:compile]
12
+ @dest = options[:dest] || '.'
13
+
14
+ if options[:sprockets].nil?
15
+ @sprockets = ::Sprockets::Environment.new
16
+ @sprockets.cache = {}
17
+ if options[:minify] == true
18
+ begin
19
+ require 'uglifier'
20
+ @sprockets.js_compressor = ::Uglifier.new
21
+ rescue LoadError
22
+ throw 'Uglifier cannot be loaded. Please include "uglifier" in your Gemfile.'
23
+ end
24
+ begin
25
+ require 'yui/compressor'
26
+ @sprockets.css_compressor = ::YUI::CssCompressor.new
27
+ rescue LoadError
28
+ throw 'YUI Compressor cannot be loaded. Please include "yui/compressor" in your Gemfile.'
29
+ end
30
+ end
31
+ else
32
+ @sprockets = options[:sprockets]
33
+ end
34
+
35
+ asset_paths = options[:asset_paths] ? Array(options[:asset_paths]) : ['.']
36
+ asset_paths.each {|p| @sprockets.append_path(p)}
37
+ end
38
+
39
+ def start
40
+ UI.info 'Starting guard-cogs'
41
+ run_sprockets
42
+ end
43
+
44
+ def run_all
45
+ run_sprockets
46
+ end
47
+
48
+ def run_on_modifications(paths)
49
+ run_sprockets(paths)
50
+ end
51
+
52
+ private
53
+
54
+ def run_sprockets(paths = [])
55
+ paths = @compile unless @compile.nil?
56
+ [paths].flatten.each do |path|
57
+ begin
58
+ case path
59
+ when String
60
+ path = Pathname.new(path)
61
+ output_filename = output_basename(path.basename.to_s)
62
+ output_path = Pathname.new(File.join(@dest, path.parent, output_filename))
63
+ compile_asset(path, output_path)
64
+ when Hash
65
+ path.each {|p,op| compile_asset(Pathname.new(p), Pathname.new(File.join(@dest, op)))}
66
+ else
67
+ raise 'Items in ":compile" option must either be a String or Hash'
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def compile_asset(path, output_path)
74
+ begin
75
+ FileUtils.mkdir_p(output_path.parent) unless output_path.parent.exist?
76
+ asset = @sprockets.find_asset(path.cleanpath)
77
+ raise "'#{path.cleanpath}' could not be found" if asset.nil?
78
+ asset.write_to(output_path.cleanpath)
79
+ UI.info("Compiled '#{path.cleanpath}' -> '#{output_path.cleanpath}'")
80
+ Notifier.notify("Compiled '#{path.cleanpath}' -> '#{output_path.cleanpath}'", title: "Compiled #{path.cleanpath}", image: :success)
81
+ rescue Exception => e
82
+ UI.error("Failed to compile '#{path}': #{e}")
83
+ Notifier.notify("Failed to compile '#{path}': #{e}", title: "Failed to compile #{path}", image: :failed)
84
+ throw :task_has_failed
85
+ end
86
+ end
87
+
88
+ def output_basename(filename)
89
+ result = filename.gsub(/^(.*\.(js|coffee|css|scss|sass))(\.(js|coffee|css|scss|sass|erb))*$/, '\1')
90
+ return result.gsub(/(.*)(\.coffee)$/, '\1.js').gsub(/(.*)(\.scss)$/, '\1.css').gsub(/(.*)(\.sass)$/, '\1.css')
91
+ end
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-cogs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Garton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: guard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coffee-script
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: uglifier
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sass
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yui-compressor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sprockets
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sprockets-sass
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Guard::Cogs packages your coffeescript, javascript, sass, and css.
140
+ email:
141
+ - garton.tim@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - Gemfile
148
+ - Guardfile
149
+ - LICENSE
150
+ - README.md
151
+ - Rakefile
152
+ - guard-cogs.gemspec
153
+ - lib/guard/cogs.rb
154
+ - lib/guard/cogs/templates/Guardfile
155
+ - lib/guard/cogs/version.rb
156
+ homepage: https://rubygems.org/gems/guard-cogs
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.2.2
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Guard gem for sprockets
180
+ test_files: []