guard-sass 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +2 -2
- data/README.md +171 -31
- data/lib/guard/sass/version.rb +1 -1
- data/lib/guard/sass.rb +35 -32
- metadata +10 -10
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010 Joshua Hawxwell
|
1
|
+
Copyright (c) 2010 - 2011 Joshua Hawxwell
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# Guard-Sass
|
2
2
|
|
3
|
-
guard-sass compiles your sass (and scss) files automatically when
|
3
|
+
guard-sass compiles or validates your sass (and scss) files automatically when
|
4
|
+
changed.
|
4
5
|
|
5
6
|
## Install
|
6
7
|
|
7
|
-
You will need to have [guard](http://github.com/guard/guard) to continue, so
|
8
|
+
You will need to have [guard](http://github.com/guard/guard) to continue, so
|
9
|
+
install it now!
|
8
10
|
|
9
11
|
Install the gem with:
|
10
12
|
|
@@ -18,30 +20,102 @@ And finally add a basic setup to your Guardfile with:
|
|
18
20
|
|
19
21
|
guard init sass
|
20
22
|
|
21
|
-
|
22
23
|
## Usage
|
23
24
|
|
25
|
+
Please read the [Guard usage documentation][gdoc].
|
26
|
+
|
27
|
+
## Guardfile
|
28
|
+
|
29
|
+
guard-sass can be adapted to all kind of projects. Please read the
|
30
|
+
[Guard documentation][gdoc] for more information about the Guardfile DSL.
|
31
|
+
|
32
|
+
### Ruby project
|
33
|
+
|
34
|
+
In a Ruby project you want to configure your input and output directories.
|
35
|
+
|
24
36
|
```ruby
|
25
|
-
guard 'sass'
|
26
|
-
watch(%r{^sass/(.+\.s[ac]ss)})
|
27
|
-
end
|
37
|
+
guard 'sass', :input => 'sass', :output => 'styles'
|
28
38
|
```
|
29
39
|
|
30
|
-
|
40
|
+
If your output directory is the same as the input directory, you can simply skip it:
|
31
41
|
|
32
42
|
```ruby
|
33
|
-
guard 'sass', :
|
34
|
-
|
35
|
-
|
43
|
+
guard 'sass', :input => 'styles'
|
44
|
+
```
|
45
|
+
|
46
|
+
### Rails app with the asset pipeline
|
47
|
+
|
48
|
+
With the introduction of the [asset pipeline][rpipe] in Rails 3.1 there is no
|
49
|
+
need to compile your Sass stylesheets with this Guard. However, if you would
|
50
|
+
still like to have feedback on the validation of your stylesheets (preferably
|
51
|
+
with a Growl notification) directly after you save a change, then you can still
|
52
|
+
use this Guard and simply skip generation of the output file:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
guard 'sass', :input => 'app/assets/stylesheets', :noop => true
|
56
|
+
```
|
57
|
+
|
58
|
+
This gives you (almost) immediate feedback on whether the changes made are valid,
|
59
|
+
and is much faster than making a subsequent request to your Rails application.
|
60
|
+
If you just want to be notified when an error occurs you can hide the success
|
61
|
+
compilation message:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
guard 'sass',
|
65
|
+
:input => 'app/assets/stylesheets',
|
66
|
+
:noop => true,
|
67
|
+
:hide_success => true
|
36
68
|
```
|
37
69
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
70
|
+
### Rails app without the asset pipeline
|
71
|
+
|
72
|
+
Without the asset pipeline you just define an input and output directory as in
|
73
|
+
a normal Ruby project:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
guard 'sass', :input => 'app/stylesheets', :output => 'public/stylesheets'
|
77
|
+
```
|
78
|
+
|
79
|
+
## Options
|
42
80
|
|
43
|
-
|
44
|
-
|
81
|
+
The following options can be passed to guard-sass:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
:input => 'sass' # Relative path to the input directory.
|
85
|
+
# A suffix `/(.+\.s[ac]ss)` will be added to this option.
|
86
|
+
# default: nil
|
87
|
+
|
88
|
+
:output => 'css' # Relative path to the output directory.
|
89
|
+
# default: 'css' or the :input option when supplied
|
90
|
+
|
91
|
+
:notification => false # Whether to display success and error notifications.
|
92
|
+
# default: true
|
93
|
+
|
94
|
+
:hide_success => true # Disable successful compilation messages.
|
95
|
+
# default: false
|
96
|
+
|
97
|
+
:shallow => true # Do not create nested output directories.
|
98
|
+
# default: false
|
99
|
+
|
100
|
+
:style => :nested # Controls the output style. Accepted options are :nested,
|
101
|
+
# :compact, :compressed and :expanded
|
102
|
+
# default: :nested
|
103
|
+
|
104
|
+
:load_paths => ['sass/partials'] # Paths for sass to find imported sass files from.
|
105
|
+
# default: all directories under current
|
106
|
+
|
107
|
+
:noop => true # No operation: Do not write output file
|
108
|
+
# default: false
|
109
|
+
|
110
|
+
:debug_info_ => true # File and line number info for FireSass.
|
111
|
+
# default: false
|
112
|
+
```
|
113
|
+
|
114
|
+
### Output short notation
|
115
|
+
|
116
|
+
guard-sass also has a short notation like [guard-coffeescript][gcs], this lets
|
117
|
+
you define an input folder (with an optional output folder) automatically creating
|
118
|
+
the required watcher.
|
45
119
|
|
46
120
|
```ruby
|
47
121
|
guard 'sass', :input => 'sass', :output => 'styles'
|
@@ -49,7 +123,7 @@ guard 'sass', :input => 'sass', :output => 'styles'
|
|
49
123
|
guard 'sass', :input => 'stylesheets'
|
50
124
|
```
|
51
125
|
|
52
|
-
These are
|
126
|
+
These are equivalent to
|
53
127
|
|
54
128
|
```ruby
|
55
129
|
guard 'sass', :output => 'styles' do
|
@@ -61,25 +135,91 @@ guard 'sass' do
|
|
61
135
|
end
|
62
136
|
```
|
63
137
|
|
138
|
+
### Nested directories
|
64
139
|
|
65
|
-
|
140
|
+
By default the guard detects nested directories and writes files into the output
|
141
|
+
directory with the same structure.
|
142
|
+
|
143
|
+
The Guard detects by default nested directories and creates these within the
|
144
|
+
output directory. The detection is based on the match of the watch regular expression:
|
145
|
+
|
146
|
+
A file
|
147
|
+
|
148
|
+
```
|
149
|
+
/app/stylesheets/form/button.sass
|
150
|
+
```
|
151
|
+
|
152
|
+
that has been detected by the watch
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
watch(%r{^app/stylesheets/(.+\.s[ac]ss)$})
|
156
|
+
```
|
157
|
+
|
158
|
+
with an output directory of
|
66
159
|
|
67
160
|
```ruby
|
68
|
-
:
|
69
|
-
:output => 'css' # Relative path to the output directory
|
70
|
-
:notification => false # Whether to display notifications after finished,
|
71
|
-
# default: true
|
72
|
-
:shallow => true # Whether to output nested directories or just put css
|
73
|
-
# directly in output folder, default: false
|
74
|
-
:style => :nested # Controls the output style, by default :nested
|
75
|
-
# accepted options are :nested, :compact, :compressed and :expanded
|
76
|
-
:load_paths => ['sass/partials'] # Paths for sass to find imported sass files from,
|
77
|
-
# default: all directories under current
|
78
|
-
:debug_info_ => true # File and line number info for FireSass, default: false
|
161
|
+
:output => 'public/stylesheets'
|
79
162
|
```
|
80
163
|
|
164
|
+
will be compiled to
|
165
|
+
|
166
|
+
```
|
167
|
+
public/stylesheets/form/button.css
|
168
|
+
```
|
169
|
+
|
170
|
+
Note the parenthesis around `.+\.s[ac]ss`. This enables guard-sass to place
|
171
|
+
the full path that was matched inside the parenthesis into the proper output directory.
|
172
|
+
|
173
|
+
This behaviour can be switched off by passing the option `:shallow => true` to the
|
174
|
+
Guard, so that all stylesheets will be compiled directly to the output directory.
|
175
|
+
So the previous example would have compiled to `public/stylesheets/button.css`.
|
176
|
+
|
177
|
+
## Development
|
178
|
+
|
179
|
+
- Source hosted at [GitHub](https://github.com/hawx/guard-sass)
|
180
|
+
- Report issues and feature requests to [GitHub Issues][issues]
|
181
|
+
|
182
|
+
Pull requests are very welcome!
|
183
|
+
|
184
|
+
For questions please join us on our [Google group][ggroup] or
|
185
|
+
on `#guard` (irc.freenode.net).
|
186
|
+
|
187
|
+
## Contributors
|
188
|
+
|
189
|
+
Have a look at the [GitHub contributor][contrib] list to see all contributors.
|
190
|
+
|
191
|
+
Since this Guard is very close to [guard-coffeescript][gcs], some features have been
|
192
|
+
incorporated into guard-sass.
|
193
|
+
|
194
|
+
## License
|
195
|
+
|
196
|
+
(The MIT License)
|
197
|
+
|
198
|
+
Copyright (c) 2010 - 2011 Joshua Hawxwell
|
199
|
+
|
200
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
201
|
+
a copy of this software and associated documentation files (the
|
202
|
+
'Software'), to deal in the Software without restriction, including
|
203
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
204
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
205
|
+
permit persons to whom the Software is furnished to do so, subject to
|
206
|
+
the following conditions:
|
207
|
+
|
208
|
+
The above copyright notice and this permission notice shall be
|
209
|
+
included in all copies or substantial portions of the Software.
|
81
210
|
|
82
|
-
|
211
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
212
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
213
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
214
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
215
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
216
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
217
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
83
218
|
|
84
219
|
|
85
|
-
[gcs]:
|
220
|
+
[gcs]: http://github.com/netzpirat/guard-coffeescript
|
221
|
+
[gdoc]: http://github.com/guard/guard#readme
|
222
|
+
[rpipe]: http://guides.rubyonrails.org/asset_pipeline.html
|
223
|
+
[issues]: http://github.com/hawx/guard-sass/issues
|
224
|
+
[ggroup]: http://groups.google.com/group/guard-dev
|
225
|
+
[contrib]: http://github.com/hawx/guard-sass/contributors
|
data/lib/guard/sass/version.rb
CHANGED
data/lib/guard/sass.rb
CHANGED
@@ -6,33 +6,34 @@ require 'sass'
|
|
6
6
|
|
7
7
|
module Guard
|
8
8
|
class Sass < Guard
|
9
|
-
|
9
|
+
|
10
10
|
DEFAULTS = {
|
11
|
-
:output
|
12
|
-
:notification => true,
|
13
|
-
:shallow
|
14
|
-
:style
|
15
|
-
:debug_info
|
16
|
-
:
|
11
|
+
:output => 'css', # Output directory
|
12
|
+
:notification => true, # Enable notifications?
|
13
|
+
:shallow => false, # Output nested directories?
|
14
|
+
:style => :nested, # Nested output
|
15
|
+
:debug_info => false, # File and line number info for FireSass
|
16
|
+
:noop => false, # Do no write output file
|
17
|
+
:hide_success => false, # Do not show success message
|
18
|
+
:load_paths => Dir.glob('**/**').find_all {|i| File.directory?(i) }
|
17
19
|
}
|
18
|
-
|
20
|
+
|
19
21
|
def initialize(watchers = [], options = {})
|
20
22
|
if options[:input]
|
21
23
|
options[:output] = options[:input] unless options.has_key?(:output)
|
22
24
|
watchers << ::Guard::Watcher.new(%r{^#{options.delete(:input)}/(.+\.s[ac]ss)$})
|
23
25
|
end
|
24
|
-
|
26
|
+
|
25
27
|
super(watchers, DEFAULTS.merge(options))
|
26
28
|
end
|
27
|
-
|
28
|
-
|
29
|
+
|
30
|
+
|
29
31
|
# Builds the sass or scss. Determines engine to use by extension
|
30
32
|
# of path given.
|
31
33
|
#
|
32
34
|
# @param file [String] path to file to build
|
33
35
|
# @return [String] the output css
|
34
36
|
#
|
35
|
-
|
36
37
|
def build_sass(file)
|
37
38
|
content = File.new(file).read
|
38
39
|
# sass or scss?
|
@@ -43,17 +44,11 @@ module Guard
|
|
43
44
|
:style => options[:style].to_sym,
|
44
45
|
:debug_info => options[:debug_info],
|
45
46
|
}
|
46
|
-
engine = ::Sass::Engine.new(content, sass_options)
|
47
47
|
|
48
|
-
|
49
|
-
engine.render
|
50
|
-
rescue ::Sass::SyntaxError => e
|
51
|
-
puts "ERROR: #{e.message}\n on line #{e.sass_line} of #{e.sass_filename || file}"
|
52
|
-
nil
|
53
|
-
end
|
48
|
+
::Sass::Engine.new(content, sass_options).render
|
54
49
|
end
|
55
|
-
|
56
|
-
# Get the file path to output the css based on the file being
|
50
|
+
|
51
|
+
# Get the file path to output the css based on the file being
|
57
52
|
# built.
|
58
53
|
#
|
59
54
|
# @param file [String] path to file being built
|
@@ -61,7 +56,7 @@ module Guard
|
|
61
56
|
#
|
62
57
|
def get_output(file)
|
63
58
|
folder = File.join ::Guard.listener.directory, options[:output]
|
64
|
-
|
59
|
+
|
65
60
|
unless options[:shallow]
|
66
61
|
watchers.product([file]).each do |watcher, file|
|
67
62
|
if matches = file.match(watcher.pattern)
|
@@ -72,20 +67,20 @@ module Guard
|
|
72
67
|
end
|
73
68
|
end
|
74
69
|
end
|
75
|
-
|
70
|
+
|
76
71
|
FileUtils.mkdir_p folder
|
77
72
|
r = File.join folder, File.basename(file).split('.')[0]
|
78
73
|
r << '.css'
|
79
74
|
end
|
80
|
-
|
75
|
+
|
81
76
|
def ignored?(path)
|
82
77
|
File.basename(path)[0,1] == "_"
|
83
78
|
end
|
84
|
-
|
79
|
+
|
85
80
|
# ================
|
86
81
|
# = Guard method =
|
87
82
|
# ================
|
88
|
-
|
83
|
+
|
89
84
|
# Build all files being watched
|
90
85
|
def run_all
|
91
86
|
run_on_change(Watcher.match_files(self, Dir.glob(File.join('**', '[^_]*.*'))))
|
@@ -101,20 +96,28 @@ module Guard
|
|
101
96
|
begin
|
102
97
|
contents = build_sass(file)
|
103
98
|
if contents
|
104
|
-
|
105
|
-
|
106
|
-
|
99
|
+
message = options[:noop] ? "verified #{file}" : "rebuilt #{file}"
|
100
|
+
|
101
|
+
File.open(css_file, 'w') {|f| f.write(contents) } unless options[:noop]
|
102
|
+
::Guard::UI.info "-> #{message}", :reset => true
|
103
|
+
if options[:notification] && !options[:hide_success]
|
104
|
+
::Guard::Notifier.notify(message, :title => "Guard::Sass", :image => :success)
|
105
|
+
end
|
107
106
|
end
|
108
107
|
css_file
|
109
108
|
rescue ::Sass::SyntaxError => e
|
110
109
|
::Guard::UI.error "Sass > #{e.sass_backtrace_str(file)}"
|
111
|
-
::Guard::Notifier.notify(
|
110
|
+
::Guard::Notifier.notify(
|
111
|
+
(options[:noop] ? 'validation' : 'rebuild') + " failed > #{e.sass_backtrace_str(file)}",
|
112
|
+
:title => "Guard::Sass",
|
113
|
+
:image => :error
|
114
|
+
) if options[:notification]
|
112
115
|
nil
|
113
116
|
end
|
114
117
|
end.compact
|
115
118
|
notify changed_files
|
116
119
|
end
|
117
|
-
|
120
|
+
|
118
121
|
def notify(changed_files)
|
119
122
|
::Guard.guards.reject{ |guard| guard == self }.each do |guard|
|
120
123
|
paths = Watcher.match_files(guard, changed_files)
|
@@ -123,4 +126,4 @@ module Guard
|
|
123
126
|
end
|
124
127
|
|
125
128
|
end
|
126
|
-
end
|
129
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-sass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-04 00:00:00.000000000 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: guard
|
17
|
-
requirement: &
|
17
|
+
requirement: &2153652620 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.4.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2153652620
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: sass
|
28
|
-
requirement: &
|
28
|
+
requirement: &2153652160 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '3.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2153652160
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &2153651700 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.0.2
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2153651700
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &2153651240 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>'
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: 2.0.0.rc
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *2153651240
|
59
59
|
description: Guard::Sass automatically rebuilds sass (like sass --watch)
|
60
60
|
email:
|
61
61
|
- m@hawx.me
|