Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Scss#sass_dir_relative_to_site_source logic #99

Merged
merged 2 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/jekyll/converters/scss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def user_sass_load_paths
end

def sass_dir_relative_to_site_source
Jekyll.sanitized_path(site_source, sass_dir)
@sass_dir_relative_to_site_source ||= begin
Jekyll.sanitized_path(site_source, sass_dir).sub(site.source + "/", "")
end
end

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

# Expand file globs (e.g. `node_modules/*/node_modules` )
Dir.chdir(site_source) do
paths = paths.flat_map { |path| Dir.glob(path) }.uniq
paths = paths.flat_map { |path| Dir.glob(path) }

paths.map! do |path|
if safe?
Expand All @@ -149,6 +151,7 @@ def sass_load_paths
end
end

paths.uniq!
paths << site.theme.sass_path if site.theme&.sass_path
paths.select { |path| File.directory?(path) }
end
Expand Down
3 changes: 3 additions & 0 deletions spec/[alpha]beta/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sass:
style: :compressed
highlighter: rouge
2 changes: 2 additions & 0 deletions spec/[alpha]beta/_sass/_color.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$black: #999;
a { color: $black }
1 change: 1 addition & 0 deletions spec/[alpha]beta/_sass/_grid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.half { width: 50% }
4 changes: 4 additions & 0 deletions spec/[alpha]beta/css/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

@import "grid";
18 changes: 18 additions & 0 deletions spec/sass_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,22 @@ def converter(overrides = {})
expect(verter.convert(content)).to eql(css_output)
end
end

context "in a site nested inside directory with square brackets" do
let(:site) do
make_site(
"source" => File.expand_path("[alpha]beta", __dir__),
"sass" => {
"style" => :compact,
}
)
end

let(:verter) { sass_converter_instance(site) }

it "produces CSS without raising errors" do
expect { site.process }.not_to raise_error
expect(verter.convert(content)).to eql(css_output)
end
end
end
20 changes: 19 additions & 1 deletion spec/scss_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def converter(overrides = {})
it "not allow sass_dirs outside of site source" do
expect(
converter("sass_dir" => "/etc/passwd").sass_dir_relative_to_site_source
).to eql(source_dir("etc/passwd"))
).to eql("etc/passwd")
end
end
end
Expand Down Expand Up @@ -356,4 +356,22 @@ def converter(overrides = {})
expect(verter.convert(content)).to eql(css_output)
end
end

context "in a site nested inside directory with square brackets" do
let(:site) do
make_site(
"source" => File.expand_path("[alpha]beta", __dir__),
"sass" => {
"style" => :compact,
}
)
end

let(:verter) { scss_converter_instance(site) }

it "produces CSS without raising errors" do
expect { site.process }.not_to raise_error
expect(verter.convert(content)).to eql(css_output)
end
end
end