Skip to content

Commit d1c4324

Browse files
authored
Merge pull request #67 from dreyks/load_paths
support config.sass.load_paths
2 parents a7e1b5f + 5646f70 commit d1c4324

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

lib/sassc/rails/template.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def call(input)
2626
environment: input[:environment],
2727
dependencies: context.metadata[:dependency_paths]
2828
}
29-
}.merge(config_options)
29+
}.merge(config_options) { |*args| safe_merge(*args) }
3030

3131
engine = ::SassC::Engine.new(input[:data], options)
3232

@@ -56,7 +56,7 @@ def evaluate(context, locals, &block)
5656
context: context,
5757
environment: context.environment
5858
}
59-
}.merge(config_options)
59+
}.merge(config_options, &method(:safe_merge))
6060

6161
::SassC::Engine.new(data, options).render
6262
end
@@ -69,7 +69,7 @@ def evaluate(context, locals, &block)
6969
end
7070

7171
def config_options
72-
opts = { style: sass_style }
72+
opts = { style: sass_style, load_paths: load_paths }
7373

7474

7575
if Rails.application.config.sass.inline_source_maps
@@ -87,9 +87,23 @@ def sass_style
8787
(Rails.application.config.sass.style || :expanded).to_sym
8888
end
8989

90+
def load_paths
91+
Rails.application.config.sass.load_paths || []
92+
end
93+
9094
def line_comments?
9195
Rails.application.config.sass.line_comments
9296
end
97+
98+
def safe_merge(key, left, right)
99+
if [left, right].all? { |v| v.is_a? Hash }
100+
left.merge(right) { |*args| safe_merge *args }
101+
elsif [left, right].all? { |v| v.is_a? Array }
102+
(left + right).uniq
103+
else
104+
right
105+
end
106+
end
93107
end
94108

95109
class ScssTemplate < SassTemplate

test/dummy/app/assets/stylesheets/imports_test.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@import "css_sass_handler";
1414
@import "css_scss_erb_handler";
1515
@import "css_sass_erb_handler";
16+
@import 'partial_in_load_paths';
1617

1718
.main {
1819
color: yellow;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.partial_in_load_paths {
2+
color: #BADA55
3+
}

test/sassc_rails_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def test_sass_asset_paths_work
116116
end
117117

118118
def test_sass_imports_work_correctly
119+
app.config.sass.load_paths << Rails.root.join('app/assets/stylesheets/in_load_paths')
119120
initialize!
120121

121122
css_output = render_asset("imports_test.css")
@@ -145,6 +146,8 @@ def test_sass_imports_work_correctly
145146

146147
assert_match /globbed/, css_output
147148
assert_match /nested-glob/, css_output
149+
150+
assert_match /partial_in_load_paths/, css_output
148151
end
149152

150153
def test_style_config_item_is_defaulted_to_expanded_in_development_mode

0 commit comments

Comments
 (0)