Skip to content

Commit e7da015

Browse files
authored
Merge pull request #113 from michaelglass/add-global-load-path
copy global load path from sass
2 parents 58d09fe + 7e30473 commit e7da015

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

lib/sassc.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
# frozen_string_literal: true
22

33
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
428
end
529

630
require_relative "sassc/version"

lib/sassc/engine.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def output_style
132132
end
133133

134134
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?
137137
end
138138
end
139139
end

test/engine_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,31 @@ def test_load_paths
198198
).render
199199
end
200200

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+
201226
def test_load_paths_not_configured
202227
temp_file("included_1/import_parent.scss", "$s: 30px;")
203228
temp_file("included_2/import.scss", "@import 'import_parent'; $size: $s;")

0 commit comments

Comments
 (0)