Skip to content

Commit

Permalink
Merge pull request sass#113 from michaelglass/add-global-load-path
Browse files Browse the repository at this point in the history
copy global load path from sass
  • Loading branch information
bolandrm committed May 8, 2019
2 parents 58d09fe + 7e30473 commit e7da015
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
24 changes: 24 additions & 0 deletions lib/sassc.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
# frozen_string_literal: true

module SassC
# The global load paths for Sass files. This is meant for plugins and
# libraries to register the paths to their Sass stylesheets to that they may
# be `@imported`. This load path is used by every instance of {Sass::Engine}.
# They are lower-precedence than any load paths passed in via the
# {file:SASS_REFERENCE.md#load_paths-option `:load_paths` option}.
#
# If the `SASS_PATH` environment variable is set,
# the initial value of `load_paths` will be initialized based on that.
# The variable should be a colon-separated list of path names
# (semicolon-separated on Windows).
#
# Note that files on the global load path are never compiled to CSS
# themselves, even if they aren't partials. They exist only to be imported.
#
# @example
# SassC.load_paths << File.dirname(__FILE__ + '/sass')
# @return [Array<String, Pathname, Sass::Importers::Base>]
def self.load_paths
@load_paths ||= if ENV['SASS_PATH']
ENV['SASS_PATH'].split(SassC::Util.windows? ? ';' : ':')
else
[]
end
end
end

require_relative "sassc/version"
Expand Down
4 changes: 2 additions & 2 deletions lib/sassc/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def output_style
end

def load_paths
paths = @options[:load_paths]
paths.join(":") if paths
paths = (@options[:load_paths] || []) + SassC.load_paths
paths.join(":") if paths.any?
end
end
end
25 changes: 25 additions & 0 deletions test/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ def test_load_paths
).render
end

def test_global_load_paths
temp_dir("included_1")
temp_dir("included_2")

temp_file("included_1/import_parent.scss", "$s: 30px;")
temp_file("included_2/import.scss", "@import 'import_parent'; $size: $s;")
temp_file("styles.scss", "@import 'import.scss'; .hi { width: $size; }")

::SassC.load_paths << "included_1"
::SassC.load_paths << "included_2"

assert_equal ".hi {\n width: 30px; }\n", Engine.new(
File.read("styles.scss"),
).render
::SassC.load_paths.clear
end

def test_env_load_paths
expected_load_paths = [ "included_1", "included_2" ]
::SassC.instance_eval { @load_paths = nil }
ENV['SASS_PATH'] = expected_load_paths.join(':')
assert_equal expected_load_paths, ::SassC.load_paths
::SassC.load_paths.clear
end

def test_load_paths_not_configured
temp_file("included_1/import_parent.scss", "$s: 30px;")
temp_file("included_2/import.scss", "@import 'import_parent'; $size: $s;")
Expand Down

0 comments on commit e7da015

Please sign in to comment.