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

Configure Sass to load from theme-gem if possible #80

Merged
merged 5 commits into from
Aug 4, 2019
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
9 changes: 8 additions & 1 deletion lib/jekyll/converters/scss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def sass_dir_relative_to_site_source
Jekyll.sanitized_path(site_source, sass_dir)
end

# rubocop:disable Metrics/AbcSize
def sass_load_paths
paths = user_sass_load_paths + [sass_dir_relative_to_site_source]
paths << site.theme.sass_path if site.theme&.sass_path

if safe?
# Sanitize paths to prevent any attack vectors (.e.g. `/**/*`)
Expand All @@ -103,6 +105,7 @@ def sass_load_paths

paths.select { |path| File.directory?(path) }
end
# rubocop:enable Metrics/AbcSize

def allow_caching?
!safe?
Expand Down Expand Up @@ -130,8 +133,12 @@ def convert(content)

private

def site
@site ||= Jekyll.sites.last
end

def site_source
@site_source ||= File.expand_path(@config["source"]).freeze
@site_source ||= site.source
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/sass_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def compressed(content)
end

def converter(overrides = {})
Jekyll::Converters::Sass.new(site_configuration("sass" => overrides))
sass_converter_instance(site).dup.tap do |obj|
obj.instance_variable_get(:@config)["sass"] = overrides
end
end

context "matching file extensions" do
Expand All @@ -46,7 +48,7 @@ def converter(overrides = {})

context "converting sass" do
it "produces CSS" do
expect(converter.convert(content)).to eql(compressed(css_output))
expect(converter.convert(content)).to eql(css_output)
end

it "includes the syntax error line in the syntax error message" do
Expand Down
6 changes: 4 additions & 2 deletions spec/scss_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def compressed(content)
end

def converter(overrides = {})
Jekyll::Converters::Scss.new(site_configuration("sass" => overrides))
scss_converter_instance(site).dup.tap do |obj|
obj.instance_variable_get(:@config)["sass"] = overrides
end
end

context "matching file extensions" do
Expand Down Expand Up @@ -118,7 +120,7 @@ def converter(overrides = {})

context "converting SCSS" do
it "produces CSS" do
expect(converter.convert(content)).to eql(compressed(css_output))
expect(converter.convert(content)).to eql(css_output)
end

it "includes the syntax error line in the syntax error message" do
Expand Down
10 changes: 5 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def make_site(config)
end

def scss_converter_instance(site)
if Jekyll::VERSION >= "3.0"
site.find_converter_instance(Jekyll::Converters::Scss)
else
site.getConverterImpl(Jekyll::Converters::Scss)
end
site.find_converter_instance(Jekyll::Converters::Scss)
end

def sass_converter_instance(site)
site.find_converter_instance(Jekyll::Converters::Sass)
end
end