File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module SassC
4
+ # The global load paths for Sass files. This is meant for plugins and
5
+ # libraries to register the paths to their Sass stylesheets to that they may
6
+ # be `@imported`. This load path is used by every instance of {Sass::Engine}.
7
+ # They are lower-precedence than any load paths passed in via the
8
+ # {file:SASS_REFERENCE.md#load_paths-option `:load_paths` option}.
9
+ #
10
+ # If the `SASS_PATH` environment variable is set,
11
+ # the initial value of `load_paths` will be initialized based on that.
12
+ # The variable should be a colon-separated list of path names
13
+ # (semicolon-separated on Windows).
14
+ #
15
+ # Note that files on the global load path are never compiled to CSS
16
+ # themselves, even if they aren't partials. They exist only to be imported.
17
+ #
18
+ # @example
19
+ # SassC.load_paths << File.dirname(__FILE__ + '/sass')
20
+ # @return [Array<String, Pathname, Sass::Importers::Base>]
21
+ def self . load_paths
22
+ @load_paths ||= if ENV [ 'SASS_PATH' ]
23
+ ENV [ 'SASS_PATH' ] . split ( SassC ::Util . windows? ? ';' : ':' )
24
+ else
25
+ [ ]
26
+ end
27
+ end
4
28
end
5
29
6
30
require_relative "sassc/version"
Original file line number Diff line number Diff line change @@ -132,8 +132,8 @@ def output_style
132
132
end
133
133
134
134
def load_paths
135
- paths = @options [ :load_paths ]
136
- paths . join ( ":" ) if paths
135
+ paths = ( @options [ :load_paths ] || [ ] ) + SassC . load_paths
136
+ paths . join ( ":" ) if paths . any?
137
137
end
138
138
end
139
139
end
Original file line number Diff line number Diff line change @@ -198,6 +198,31 @@ def test_load_paths
198
198
) . render
199
199
end
200
200
201
+ def test_global_load_paths
202
+ temp_dir ( "included_1" )
203
+ temp_dir ( "included_2" )
204
+
205
+ temp_file ( "included_1/import_parent.scss" , "$s: 30px;" )
206
+ temp_file ( "included_2/import.scss" , "@import 'import_parent'; $size: $s;" )
207
+ temp_file ( "styles.scss" , "@import 'import.scss'; .hi { width: $size; }" )
208
+
209
+ ::SassC . load_paths << "included_1"
210
+ ::SassC . load_paths << "included_2"
211
+
212
+ assert_equal ".hi {\n width: 30px; }\n " , Engine . new (
213
+ File . read ( "styles.scss" ) ,
214
+ ) . render
215
+ ::SassC . load_paths . clear
216
+ end
217
+
218
+ def test_env_load_paths
219
+ expected_load_paths = [ "included_1" , "included_2" ]
220
+ ::SassC . instance_eval { @load_paths = nil }
221
+ ENV [ 'SASS_PATH' ] = expected_load_paths . join ( ':' )
222
+ assert_equal expected_load_paths , ::SassC . load_paths
223
+ ::SassC . load_paths . clear
224
+ end
225
+
201
226
def test_load_paths_not_configured
202
227
temp_file ( "included_1/import_parent.scss" , "$s: 30px;" )
203
228
temp_file ( "included_2/import.scss" , "@import 'import_parent'; $size: $s;" )
You can’t perform that action at this time.
0 commit comments