haml 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of haml might be problematic. Click here for more details.
- data/VERSION +1 -1
- data/lib/haml/exec.rb +14 -3
- data/lib/haml/railtie.rb +1 -0
- data/lib/haml/template.rb +1 -1
- data/lib/sass/callbacks.rb +37 -35
- data/lib/sass/plugin.rb +6 -155
- data/lib/sass/plugin/configuration.rb +224 -0
- data/lib/sass/plugin/rack.rb +2 -2
- data/test/sass/plugin_test.rb +41 -6
- data/test/sass/scss/rx_test.rb +0 -1
- data/test/test_helper.rb +2 -0
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.1
|
data/lib/haml/exec.rb
CHANGED
@@ -200,18 +200,29 @@ END
|
|
200
200
|
opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
|
201
201
|
original_dir = dir
|
202
202
|
|
203
|
+
env = File.join(dir, "config", "environment.rb")
|
204
|
+
if File.exists?(File.join(dir, "Gemfile"))
|
205
|
+
puts("haml --rails isn't needed for Rails 3 or greater.",
|
206
|
+
"Add 'gem \"haml\"' to your Gemfile instead.", "",
|
207
|
+
"haml --rails will no longer work in the next version of #{@name}.", "")
|
208
|
+
elsif File.exists?(env) && File.open(f) {|f| f.grep(/config\.gem/)}
|
209
|
+
puts("haml --rails isn't needed for Rails 2.1 or greater.",
|
210
|
+
"Add 'gem \"haml\"' to config/environment.rb instead.", "",
|
211
|
+
"haml --rails will no longer work in the next version of #{@name}.", "")
|
212
|
+
end
|
213
|
+
|
203
214
|
dir = File.join(dir, 'vendor', 'plugins')
|
204
215
|
|
205
216
|
unless File.exists?(dir)
|
206
217
|
puts "Directory #{dir} doesn't exist"
|
207
|
-
exit
|
218
|
+
exit 1
|
208
219
|
end
|
209
220
|
|
210
221
|
dir = File.join(dir, 'haml')
|
211
222
|
|
212
223
|
if File.exists?(dir)
|
213
224
|
print "Directory #{dir} already exists, overwrite [y/N]? "
|
214
|
-
exit if gets !~ /y/i
|
225
|
+
exit 2 if gets !~ /y/i
|
215
226
|
FileUtils.rm_rf(dir)
|
216
227
|
end
|
217
228
|
|
@@ -219,7 +230,7 @@ END
|
|
219
230
|
Dir.mkdir(dir)
|
220
231
|
rescue SystemCallError
|
221
232
|
puts "Cannot create #{dir}"
|
222
|
-
exit
|
233
|
+
exit 1
|
223
234
|
end
|
224
235
|
|
225
236
|
File.open(File.join(dir, 'init.rb'), 'w') do |file|
|
data/lib/haml/railtie.rb
CHANGED
data/lib/haml/template.rb
CHANGED
data/lib/sass/callbacks.rb
CHANGED
@@ -1,39 +1,40 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# def munge(str)
|
14
|
-
# res = str.gsub(/[a-z]/, '\1\1')
|
15
|
-
# run_string_munged str, res
|
16
|
-
# res
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# @example Use a callback
|
21
|
-
# m = Munger.new
|
22
|
-
# m.on_string_munged {|str, res| puts "#{str} was munged into #{res}!"}
|
23
|
-
# m.munge "bar" #=> bar was munged into bbaarr!
|
24
|
-
module Sass::Callbacks
|
25
|
-
protected
|
26
|
-
|
27
|
-
# Define a callback with the given name.
|
28
|
-
# This will define an `on_#{name}` method
|
29
|
-
# that registers a block,
|
30
|
-
# and a `run_#{name}` method that runs that block
|
31
|
-
# (optionall with some arguments).
|
1
|
+
module Sass
|
2
|
+
# A lightweight infrastructure for defining and running callbacks.
|
3
|
+
# Callbacks are defined using \{#define\_callback\} at the class level,
|
4
|
+
# and called using `run_#{name}` at the instance level.
|
5
|
+
#
|
6
|
+
# Clients can add callbacks by calling the generated `on_#{name}` method,
|
7
|
+
# and passing in a block that's run when the callback is activated.
|
8
|
+
#
|
9
|
+
# @example Define a callback
|
10
|
+
# class Munger
|
11
|
+
# extend Sass::Callbacks
|
12
|
+
# define_callback :string_munged
|
32
13
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
14
|
+
# def munge(str)
|
15
|
+
# res = str.gsub(/[a-z]/, '\1\1')
|
16
|
+
# run_string_munged str, res
|
17
|
+
# res
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# @example Use a callback
|
22
|
+
# m = Munger.new
|
23
|
+
# m.on_string_munged {|str, res| puts "#{str} was munged into #{res}!"}
|
24
|
+
# m.munge "bar" #=> bar was munged into bbaarr!
|
25
|
+
module Callbacks
|
26
|
+
protected
|
27
|
+
|
28
|
+
# Define a callback with the given name.
|
29
|
+
# This will define an `on_#{name}` method
|
30
|
+
# that registers a block,
|
31
|
+
# and a `run_#{name}` method that runs that block
|
32
|
+
# (optionall with some arguments).
|
33
|
+
#
|
34
|
+
# @param name [Symbol] The name of the callback
|
35
|
+
# @return [void]
|
36
|
+
def define_callback(name)
|
37
|
+
class_eval <<RUBY
|
37
38
|
def on_#{name}(&block)
|
38
39
|
@_sass_callbacks ||= {}
|
39
40
|
(@_sass_callbacks[#{name.inspect}] ||= []) << block
|
@@ -46,5 +47,6 @@ def run_#{name}(*args)
|
|
46
47
|
end
|
47
48
|
private :run_#{name}
|
48
49
|
RUBY
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
data/lib/sass/plugin.rb
CHANGED
@@ -2,7 +2,7 @@ require 'fileutils'
|
|
2
2
|
require 'rbconfig'
|
3
3
|
|
4
4
|
require 'sass'
|
5
|
-
require 'sass/
|
5
|
+
require 'sass/plugin/configuration'
|
6
6
|
require 'sass/plugin/staleness_checker'
|
7
7
|
|
8
8
|
module Sass
|
@@ -31,124 +31,8 @@ module Sass
|
|
31
31
|
# #=> Compiling app/sass/ie.scss to public/stylesheets/ie.css
|
32
32
|
module Plugin
|
33
33
|
include Haml::Util
|
34
|
-
include Sass::Callbacks
|
35
|
-
extend self
|
36
|
-
|
37
|
-
@options = {
|
38
|
-
:css_location => './public/stylesheets',
|
39
|
-
:always_update => false,
|
40
|
-
:always_check => true,
|
41
|
-
:full_exception => true
|
42
|
-
}
|
43
|
-
@checked_for_updates = false
|
44
|
-
|
45
|
-
# Register a callback to be run before stylesheets are mass-updated.
|
46
|
-
# This is run whenever \{#update\_stylesheets} is called,
|
47
|
-
# unless the \{file:SASS_REFERENCE.md#never_update-option `:never_update` option}
|
48
|
-
# is enabled.
|
49
|
-
#
|
50
|
-
# @yield [individual_files]
|
51
|
-
# @yieldparam individual_files [<(String, String)>]
|
52
|
-
# Individual files to be updated, in addition to the directories
|
53
|
-
# specified in the options.
|
54
|
-
# The first element of each pair is the source file,
|
55
|
-
# the second is the target CSS file.
|
56
|
-
define_callback :updating_stylesheets
|
57
|
-
|
58
|
-
# Register a callback to be run before a single stylesheet is updated.
|
59
|
-
# The callback is only run if the stylesheet is guaranteed to be updated;
|
60
|
-
# if the CSS file is fresh, this won't be run.
|
61
|
-
#
|
62
|
-
# Even if the \{file:SASS_REFERENCE.md#full_exception-option `:full_exception` option}
|
63
|
-
# is enabled, this callback won't be run
|
64
|
-
# when an exception CSS file is being written.
|
65
|
-
# To run an action for those files, use \{#on\_compilation\_error}.
|
66
|
-
#
|
67
|
-
# @yield [template, css]
|
68
|
-
# @yieldparam template [String]
|
69
|
-
# The location of the Sass/SCSS file being updated.
|
70
|
-
# @yieldparam css [String]
|
71
|
-
# The location of the CSS file being generated.
|
72
|
-
define_callback :updating_stylesheet
|
73
|
-
|
74
|
-
# Register a callback to be run when Sass decides not to update a stylesheet.
|
75
|
-
# In particular, the callback is run when Sass finds that
|
76
|
-
# the template file and none of its dependencies
|
77
|
-
# have been modified since the last compilation.
|
78
|
-
#
|
79
|
-
# Note that this is **not** run when the
|
80
|
-
# \{file:SASS_REFERENCE.md#never-update_option `:never_update` option} is set,
|
81
|
-
# nor when Sass decides not to compile a partial.
|
82
|
-
#
|
83
|
-
# @yield [template, css]
|
84
|
-
# @yieldparam template [String]
|
85
|
-
# The location of the Sass/SCSS file not being updated.
|
86
|
-
# @yieldparam css [String]
|
87
|
-
# The location of the CSS file not being generated.
|
88
|
-
define_callback :not_updating_stylesheet
|
89
|
-
|
90
|
-
# Register a callback to be run when there's an error
|
91
|
-
# compiling a Sass file.
|
92
|
-
# This could include not only errors in the Sass document,
|
93
|
-
# but also errors accessing the file at all.
|
94
|
-
#
|
95
|
-
# @yield [error, template, css]
|
96
|
-
# @yieldparam error [Exception] The exception that was raised.
|
97
|
-
# @yieldparam template [String]
|
98
|
-
# The location of the Sass/SCSS file being updated.
|
99
|
-
# @yieldparam css [String]
|
100
|
-
# The location of the CSS file being generated.
|
101
|
-
define_callback :compilation_error
|
102
|
-
|
103
|
-
# Register a callback to be run when Sass creates a directory
|
104
|
-
# into which to put CSS files.
|
105
|
-
#
|
106
|
-
# Note that even if multiple levels of directories need to be created,
|
107
|
-
# the callback may only be run once.
|
108
|
-
# For example, if "foo/" exists and "foo/bar/baz/" needs to be created,
|
109
|
-
# this may only be run for "foo/bar/baz/".
|
110
|
-
# This is not a guarantee, however;
|
111
|
-
# it may also be run for "foo/bar/".
|
112
|
-
#
|
113
|
-
# @yield [dirname]
|
114
|
-
# @yieldparam dirname [String]
|
115
|
-
# The location of the directory that was created.
|
116
|
-
define_callback :creating_directory
|
117
|
-
|
118
|
-
# Register a callback to be run when Sass detects
|
119
|
-
# that a template has been modified.
|
120
|
-
# This is only run when using \{#watch}.
|
121
|
-
#
|
122
|
-
# @yield [template]
|
123
|
-
# @yieldparam template [String]
|
124
|
-
# The location of the template that was modified.
|
125
|
-
define_callback :template_modified
|
126
|
-
|
127
|
-
# Register a callback to be run when Sass detects
|
128
|
-
# that a new template has been created.
|
129
|
-
# This is only run when using \{#watch}.
|
130
|
-
#
|
131
|
-
# @yield [template]
|
132
|
-
# @yieldparam template [String]
|
133
|
-
# The location of the template that was created.
|
134
|
-
define_callback :template_created
|
135
|
-
|
136
|
-
# Register a callback to be run when Sass detects
|
137
|
-
# that a template has been deleted.
|
138
|
-
# This is only run when using \{#watch}.
|
139
|
-
#
|
140
|
-
# @yield [template]
|
141
|
-
# @yieldparam template [String]
|
142
|
-
# The location of the template that was deleted.
|
143
|
-
define_callback :template_deleted
|
144
34
|
|
145
|
-
|
146
|
-
# This happens when the corresponding Sass/SCSS file has been deleted.
|
147
|
-
#
|
148
|
-
# @yield [filename]
|
149
|
-
# @yieldparam filename [String]
|
150
|
-
# The location of the CSS file that was deleted.
|
151
|
-
define_callback :deleting_css
|
35
|
+
@checked_for_updates = false
|
152
36
|
|
153
37
|
# Whether or not Sass has **ever** checked if the stylesheets need to be updated
|
154
38
|
# (in this Ruby instance).
|
@@ -156,30 +40,6 @@ module Sass
|
|
156
40
|
# @return [Boolean]
|
157
41
|
attr_reader :checked_for_updates
|
158
42
|
|
159
|
-
# An options hash.
|
160
|
-
# See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
|
161
|
-
#
|
162
|
-
# @return [{Symbol => Object}]
|
163
|
-
attr_reader :options
|
164
|
-
|
165
|
-
# Sets the options hash.
|
166
|
-
# See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
|
167
|
-
#
|
168
|
-
# @param value [{Symbol => Object}] The options hash
|
169
|
-
def options=(value)
|
170
|
-
@options.merge!(value)
|
171
|
-
end
|
172
|
-
|
173
|
-
# Non-destructively modifies \{#options} so that default values are properly set.
|
174
|
-
#
|
175
|
-
# @param additional_options [{Symbol => Object}] An options hash with which to merge \{#options}
|
176
|
-
# @return [{Symbol => Object}] The modified options hash
|
177
|
-
def engine_options(additional_options = {})
|
178
|
-
opts = options.dup.merge(additional_options)
|
179
|
-
opts[:load_paths] = load_paths(opts)
|
180
|
-
opts
|
181
|
-
end
|
182
|
-
|
183
43
|
# Same as \{#update\_stylesheets}, but respects \{#checked\_for\_updates}
|
184
44
|
# and the {file:SASS_REFERENCE.md#always_update-option `:always_update`}
|
185
45
|
# and {file:SASS_REFERENCE.md#always_check-option `:always_check`} options.
|
@@ -214,7 +74,7 @@ module Sass
|
|
214
74
|
@checked_for_updates = true
|
215
75
|
staleness_checker = StalenessChecker.new
|
216
76
|
|
217
|
-
|
77
|
+
template_location_array.each do |template_location, css_location|
|
218
78
|
|
219
79
|
Dir.glob(File.join(template_location, "**", "*.s[ca]ss")).each do |file|
|
220
80
|
# Get the relative path to the file
|
@@ -303,7 +163,7 @@ module Sass
|
|
303
163
|
# TODO: Keep better track of what depends on what
|
304
164
|
# so we don't have to run a global update every time anything changes.
|
305
165
|
FSSM.monitor do |mon|
|
306
|
-
|
166
|
+
template_location_array.each do |template_location, css_location|
|
307
167
|
mon.path template_location do |path|
|
308
168
|
path.glob '**/*.s[ac]ss'
|
309
169
|
|
@@ -383,20 +243,11 @@ module Sass
|
|
383
243
|
end
|
384
244
|
|
385
245
|
def template_locations
|
386
|
-
|
387
|
-
if location.is_a?(String)
|
388
|
-
[location]
|
389
|
-
else
|
390
|
-
location.to_a.map { |l| l.first }
|
391
|
-
end
|
246
|
+
template_location_array.to_a.map {|l| l.first}
|
392
247
|
end
|
393
248
|
|
394
249
|
def css_locations
|
395
|
-
|
396
|
-
options[:template_location].to_a.map { |l| l.last }
|
397
|
-
else
|
398
|
-
[options[:css_location]]
|
399
|
-
end
|
250
|
+
template_location_array.to_a.map {|l| l.last}
|
400
251
|
end
|
401
252
|
|
402
253
|
def css_filename(name, path)
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# We keep configuration in its own self-contained file
|
2
|
+
# so that we can load it independently in Rails 3,
|
3
|
+
# where the full plugin stuff is lazy-loaded.
|
4
|
+
|
5
|
+
require 'sass/callbacks'
|
6
|
+
|
7
|
+
module Sass
|
8
|
+
module Plugin
|
9
|
+
include Sass::Callbacks
|
10
|
+
extend self
|
11
|
+
|
12
|
+
# Register a callback to be run before stylesheets are mass-updated.
|
13
|
+
# This is run whenever \{#update\_stylesheets} is called,
|
14
|
+
# unless the \{file:SASS_REFERENCE.md#never_update-option `:never_update` option}
|
15
|
+
# is enabled.
|
16
|
+
#
|
17
|
+
# @yield [individual_files]
|
18
|
+
# @yieldparam individual_files [<(String, String)>]
|
19
|
+
# Individual files to be updated, in addition to the directories
|
20
|
+
# specified in the options.
|
21
|
+
# The first element of each pair is the source file,
|
22
|
+
# the second is the target CSS file.
|
23
|
+
define_callback :updating_stylesheets
|
24
|
+
|
25
|
+
# Register a callback to be run before a single stylesheet is updated.
|
26
|
+
# The callback is only run if the stylesheet is guaranteed to be updated;
|
27
|
+
# if the CSS file is fresh, this won't be run.
|
28
|
+
#
|
29
|
+
# Even if the \{file:SASS_REFERENCE.md#full_exception-option `:full_exception` option}
|
30
|
+
# is enabled, this callback won't be run
|
31
|
+
# when an exception CSS file is being written.
|
32
|
+
# To run an action for those files, use \{#on\_compilation\_error}.
|
33
|
+
#
|
34
|
+
# @yield [template, css]
|
35
|
+
# @yieldparam template [String]
|
36
|
+
# The location of the Sass/SCSS file being updated.
|
37
|
+
# @yieldparam css [String]
|
38
|
+
# The location of the CSS file being generated.
|
39
|
+
define_callback :updating_stylesheet
|
40
|
+
|
41
|
+
# Register a callback to be run when Sass decides not to update a stylesheet.
|
42
|
+
# In particular, the callback is run when Sass finds that
|
43
|
+
# the template file and none of its dependencies
|
44
|
+
# have been modified since the last compilation.
|
45
|
+
#
|
46
|
+
# Note that this is **not** run when the
|
47
|
+
# \{file:SASS_REFERENCE.md#never-update_option `:never_update` option} is set,
|
48
|
+
# nor when Sass decides not to compile a partial.
|
49
|
+
#
|
50
|
+
# @yield [template, css]
|
51
|
+
# @yieldparam template [String]
|
52
|
+
# The location of the Sass/SCSS file not being updated.
|
53
|
+
# @yieldparam css [String]
|
54
|
+
# The location of the CSS file not being generated.
|
55
|
+
define_callback :not_updating_stylesheet
|
56
|
+
|
57
|
+
# Register a callback to be run when there's an error
|
58
|
+
# compiling a Sass file.
|
59
|
+
# This could include not only errors in the Sass document,
|
60
|
+
# but also errors accessing the file at all.
|
61
|
+
#
|
62
|
+
# @yield [error, template, css]
|
63
|
+
# @yieldparam error [Exception] The exception that was raised.
|
64
|
+
# @yieldparam template [String]
|
65
|
+
# The location of the Sass/SCSS file being updated.
|
66
|
+
# @yieldparam css [String]
|
67
|
+
# The location of the CSS file being generated.
|
68
|
+
define_callback :compilation_error
|
69
|
+
|
70
|
+
# Register a callback to be run when Sass creates a directory
|
71
|
+
# into which to put CSS files.
|
72
|
+
#
|
73
|
+
# Note that even if multiple levels of directories need to be created,
|
74
|
+
# the callback may only be run once.
|
75
|
+
# For example, if "foo/" exists and "foo/bar/baz/" needs to be created,
|
76
|
+
# this may only be run for "foo/bar/baz/".
|
77
|
+
# This is not a guarantee, however;
|
78
|
+
# it may also be run for "foo/bar/".
|
79
|
+
#
|
80
|
+
# @yield [dirname]
|
81
|
+
# @yieldparam dirname [String]
|
82
|
+
# The location of the directory that was created.
|
83
|
+
define_callback :creating_directory
|
84
|
+
|
85
|
+
# Register a callback to be run when Sass detects
|
86
|
+
# that a template has been modified.
|
87
|
+
# This is only run when using \{#watch}.
|
88
|
+
#
|
89
|
+
# @yield [template]
|
90
|
+
# @yieldparam template [String]
|
91
|
+
# The location of the template that was modified.
|
92
|
+
define_callback :template_modified
|
93
|
+
|
94
|
+
# Register a callback to be run when Sass detects
|
95
|
+
# that a new template has been created.
|
96
|
+
# This is only run when using \{#watch}.
|
97
|
+
#
|
98
|
+
# @yield [template]
|
99
|
+
# @yieldparam template [String]
|
100
|
+
# The location of the template that was created.
|
101
|
+
define_callback :template_created
|
102
|
+
|
103
|
+
# Register a callback to be run when Sass detects
|
104
|
+
# that a template has been deleted.
|
105
|
+
# This is only run when using \{#watch}.
|
106
|
+
#
|
107
|
+
# @yield [template]
|
108
|
+
# @yieldparam template [String]
|
109
|
+
# The location of the template that was deleted.
|
110
|
+
define_callback :template_deleted
|
111
|
+
|
112
|
+
# Register a callback to be run when Sass deletes a CSS file.
|
113
|
+
# This happens when the corresponding Sass/SCSS file has been deleted.
|
114
|
+
#
|
115
|
+
# @yield [filename]
|
116
|
+
# @yieldparam filename [String]
|
117
|
+
# The location of the CSS file that was deleted.
|
118
|
+
define_callback :deleting_css
|
119
|
+
|
120
|
+
@options = {
|
121
|
+
:css_location => './public/stylesheets',
|
122
|
+
:always_update => false,
|
123
|
+
:always_check => true,
|
124
|
+
:full_exception => true
|
125
|
+
}
|
126
|
+
|
127
|
+
# An options hash.
|
128
|
+
# See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
|
129
|
+
#
|
130
|
+
# @return [{Symbol => Object}]
|
131
|
+
attr_reader :options
|
132
|
+
|
133
|
+
# Sets the options hash.
|
134
|
+
# See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
|
135
|
+
#
|
136
|
+
# @param value [{Symbol => Object}] The options hash
|
137
|
+
def options=(value)
|
138
|
+
@options.merge!(value)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Non-destructively modifies \{#options} so that default values are properly set.
|
142
|
+
#
|
143
|
+
# @param additional_options [{Symbol => Object}] An options hash with which to merge \{#options}
|
144
|
+
# @return [{Symbol => Object}] The modified options hash
|
145
|
+
def engine_options(additional_options = {})
|
146
|
+
opts = options.dup.merge(additional_options)
|
147
|
+
opts[:load_paths] = load_paths(opts)
|
148
|
+
opts
|
149
|
+
end
|
150
|
+
|
151
|
+
# Adds a new template-location/css-location mapping.
|
152
|
+
# This means that Sass/SCSS files in `template_location`
|
153
|
+
# will be compiled to CSS files in `css_location`.
|
154
|
+
#
|
155
|
+
# This is preferred over manually manipulating the {file:SASS_REFERENCE.md#template_location-option `:template_location` option}
|
156
|
+
# since the option can be in multiple formats.
|
157
|
+
#
|
158
|
+
# Note that this method will change `options[:template_location]`
|
159
|
+
# to be in the Array format.
|
160
|
+
# This means that even if `options[:template_location]`
|
161
|
+
# had previously been a Hash or a String,
|
162
|
+
# it will now be an Array.
|
163
|
+
#
|
164
|
+
# @param template_location [String] The location where Sass/SCSS files will be.
|
165
|
+
# @param css_location [String] The location where compiled CSS files will go.
|
166
|
+
def add_template_location(template_location, css_location = options[:css_location])
|
167
|
+
normalize_template_location!
|
168
|
+
template_location_array << [template_location, css_location]
|
169
|
+
end
|
170
|
+
|
171
|
+
# Removes a template-location/css-location mapping.
|
172
|
+
# This means that Sass/SCSS files in `template_location`
|
173
|
+
# will no longer be compiled to CSS files in `css_location`.
|
174
|
+
#
|
175
|
+
# This is preferred over manually manipulating the {file:SASS_REFERENCE.md#template_location-option `:template_location` option}
|
176
|
+
# since the option can be in multiple formats.
|
177
|
+
#
|
178
|
+
# Note that this method will change `options[:template_location]`
|
179
|
+
# to be in the Array format.
|
180
|
+
# This means that even if `options[:template_location]`
|
181
|
+
# had previously been a Hash or a String,
|
182
|
+
# it will now be an Array.
|
183
|
+
#
|
184
|
+
# @param template_location [String]
|
185
|
+
# The location where Sass/SCSS files were,
|
186
|
+
# which is now going to be ignored.
|
187
|
+
# @param css_location [String]
|
188
|
+
# The location where compiled CSS files went, but will no longer go.
|
189
|
+
# @return [Boolean]
|
190
|
+
# Non-`nil` if the given mapping already existed and was removed,
|
191
|
+
# or `nil` if nothing was changed.
|
192
|
+
def remove_template_location(template_location, css_location = options[:css_location])
|
193
|
+
normalize_template_location!
|
194
|
+
template_location_array.delete([template_location, css_location])
|
195
|
+
end
|
196
|
+
|
197
|
+
# Returns the template locations configured for Sass
|
198
|
+
# as an array of `[template_location, css_location]` pairs.
|
199
|
+
# See the {file:SASS_REFERENCE.md#template_location-option `:template_location` option}
|
200
|
+
# for details.
|
201
|
+
#
|
202
|
+
# @return [Array<(String, String)>]
|
203
|
+
# An array of `[template_location, css_location]` pairs.
|
204
|
+
def template_location_array
|
205
|
+
old_template_location = options[:template_location]
|
206
|
+
normalize_template_location!
|
207
|
+
options[:template_location]
|
208
|
+
ensure
|
209
|
+
options[:template_location] = old_template_location
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def normalize_template_location!
|
215
|
+
return if options[:template_location].is_a?(Array)
|
216
|
+
options[:template_location] =
|
217
|
+
case options[:template_location]
|
218
|
+
when nil; [[File.join(options[:css_location], 'sass'), options[:css_location]]]
|
219
|
+
when String; [[options[:template_location], options[:css_location]]]
|
220
|
+
else; options[:template_location].to_a
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
data/lib/sass/plugin/rack.rb
CHANGED
data/test/sass/plugin_test.rb
CHANGED
@@ -148,6 +148,41 @@ CSS
|
|
148
148
|
assert !File.exists?(tempfile_loc('_partial'))
|
149
149
|
end
|
150
150
|
|
151
|
+
def test_template_location_array
|
152
|
+
assert_equal [[template_loc, tempfile_loc]], Sass::Plugin.template_location_array
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_add_template_location
|
156
|
+
Sass::Plugin.add_template_location(template_loc(nil, "more_"), tempfile_loc(nil, "more_"))
|
157
|
+
assert_equal(
|
158
|
+
[[template_loc, tempfile_loc], [template_loc(nil, "more_"), tempfile_loc(nil, "more_")]],
|
159
|
+
Sass::Plugin.template_location_array)
|
160
|
+
|
161
|
+
touch 'more1', 'more_'
|
162
|
+
touch 'basic'
|
163
|
+
assert_needs_update "more1", "more_"
|
164
|
+
assert_needs_update "basic"
|
165
|
+
update_all_stylesheets!
|
166
|
+
assert_doesnt_need_update "more1", "more_"
|
167
|
+
assert_doesnt_need_update "basic"
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_remove_template_location
|
171
|
+
Sass::Plugin.add_template_location(template_loc(nil, "more_"), tempfile_loc(nil, "more_"))
|
172
|
+
Sass::Plugin.remove_template_location(template_loc, tempfile_loc)
|
173
|
+
assert_equal(
|
174
|
+
[[template_loc(nil, "more_"), tempfile_loc(nil, "more_")]],
|
175
|
+
Sass::Plugin.template_location_array)
|
176
|
+
|
177
|
+
touch 'more1', 'more_'
|
178
|
+
touch 'basic'
|
179
|
+
assert_needs_update "more1", "more_"
|
180
|
+
assert_needs_update "basic"
|
181
|
+
update_all_stylesheets!
|
182
|
+
assert_doesnt_need_update "more1", "more_"
|
183
|
+
assert_needs_update "basic"
|
184
|
+
end
|
185
|
+
|
151
186
|
# Callbacks
|
152
187
|
|
153
188
|
def test_updating_stylesheets_callback
|
@@ -346,14 +381,14 @@ CSS
|
|
346
381
|
end
|
347
382
|
end
|
348
383
|
|
349
|
-
def assert_needs_update(
|
350
|
-
assert(Sass::Plugin::StalenessChecker.stylesheet_needs_update?(tempfile_loc(
|
351
|
-
"Expected #{template_loc(
|
384
|
+
def assert_needs_update(*args)
|
385
|
+
assert(Sass::Plugin::StalenessChecker.stylesheet_needs_update?(tempfile_loc(*args), template_loc(*args)),
|
386
|
+
"Expected #{template_loc(*args)} to need an update.")
|
352
387
|
end
|
353
388
|
|
354
|
-
def assert_doesnt_need_update(
|
355
|
-
assert(!Sass::Plugin::StalenessChecker.stylesheet_needs_update?(tempfile_loc(
|
356
|
-
"Expected #{template_loc(
|
389
|
+
def assert_doesnt_need_update(*args)
|
390
|
+
assert(!Sass::Plugin::StalenessChecker.stylesheet_needs_update?(tempfile_loc(*args), template_loc(*args)),
|
391
|
+
"Expected #{template_loc(*args)} not to need an update.")
|
357
392
|
end
|
358
393
|
|
359
394
|
def touch(*args)
|
data/test/sass/scss/rx_test.rb
CHANGED
@@ -57,7 +57,6 @@ class ScssRxTest < Test::Unit::TestCase
|
|
57
57
|
assert_no_match IDENT, "-1foo"
|
58
58
|
assert_no_match IDENT, "--foo"
|
59
59
|
assert_no_match IDENT, "_1foo"
|
60
|
-
assert_no_match IDENT, "__foo"
|
61
60
|
assert_no_match IDENT, "-_foo"
|
62
61
|
assert_no_match IDENT, "_-foo"
|
63
62
|
assert_no_match IDENT, "foo bar"
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 3.0.
|
8
|
+
- 1
|
9
|
+
version: 3.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nathan Weizenbaum
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/sass/tree/variable_node.rb
|
106
106
|
- lib/sass/plugin/rails.rb
|
107
107
|
- lib/sass/plugin/rack.rb
|
108
|
+
- lib/sass/plugin/configuration.rb
|
108
109
|
- lib/sass/plugin/merb.rb
|
109
110
|
- lib/sass/plugin/staleness_checker.rb
|
110
111
|
- lib/sass/environment.rb
|