Skip to content

Commit fe52b1a

Browse files
authored
Fix Scss#sass_dir_relative_to_site_source logic (#99)
Merge pull request 99
1 parent b9334db commit fe52b1a

File tree

7 files changed

+52
-3
lines changed

7 files changed

+52
-3
lines changed

lib/jekyll/converters/scss.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def user_sass_load_paths
123123
end
124124

125125
def sass_dir_relative_to_site_source
126-
Jekyll.sanitized_path(site_source, sass_dir)
126+
@sass_dir_relative_to_site_source ||= begin
127+
Jekyll.sanitized_path(site_source, sass_dir).sub(site.source + "/", "")
128+
end
127129
end
128130

129131
# rubocop:disable Metrics/AbcSize
@@ -137,7 +139,7 @@ def sass_load_paths
137139

138140
# Expand file globs (e.g. `node_modules/*/node_modules` )
139141
Dir.chdir(site_source) do
140-
paths = paths.flat_map { |path| Dir.glob(path) }.uniq
142+
paths = paths.flat_map { |path| Dir.glob(path) }
141143

142144
paths.map! do |path|
143145
if safe?
@@ -149,6 +151,7 @@ def sass_load_paths
149151
end
150152
end
151153

154+
paths.uniq!
152155
paths << site.theme.sass_path if site.theme&.sass_path
153156
paths.select { |path| File.directory?(path) }
154157
end

spec/[alpha]beta/_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sass:
2+
style: :compressed
3+
highlighter: rouge

spec/[alpha]beta/_sass/_color.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$black: #999;
2+
a { color: $black }

spec/[alpha]beta/_sass/_grid.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.half { width: 50% }

spec/[alpha]beta/css/main.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
@import "grid";

spec/sass_converter_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,22 @@ def converter(overrides = {})
9595
expect(verter.convert(content)).to eql(css_output)
9696
end
9797
end
98+
99+
context "in a site nested inside directory with square brackets" do
100+
let(:site) do
101+
make_site(
102+
"source" => File.expand_path("[alpha]beta", __dir__),
103+
"sass" => {
104+
"style" => :compact,
105+
}
106+
)
107+
end
108+
109+
let(:verter) { sass_converter_instance(site) }
110+
111+
it "produces CSS without raising errors" do
112+
expect { site.process }.not_to raise_error
113+
expect(verter.convert(content)).to eql(css_output)
114+
end
115+
end
98116
end

spec/scss_converter_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def converter(overrides = {})
8181
it "not allow sass_dirs outside of site source" do
8282
expect(
8383
converter("sass_dir" => "/etc/passwd").sass_dir_relative_to_site_source
84-
).to eql(source_dir("etc/passwd"))
84+
).to eql("etc/passwd")
8585
end
8686
end
8787
end
@@ -356,4 +356,22 @@ def converter(overrides = {})
356356
expect(verter.convert(content)).to eql(css_output)
357357
end
358358
end
359+
360+
context "in a site nested inside directory with square brackets" do
361+
let(:site) do
362+
make_site(
363+
"source" => File.expand_path("[alpha]beta", __dir__),
364+
"sass" => {
365+
"style" => :compact,
366+
}
367+
)
368+
end
369+
370+
let(:verter) { scss_converter_instance(site) }
371+
372+
it "produces CSS without raising errors" do
373+
expect { site.process }.not_to raise_error
374+
expect(verter.convert(content)).to eql(css_output)
375+
end
376+
end
359377
end

0 commit comments

Comments
 (0)