-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
Allow Sass to import files even if they don’t have an item #1379
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,15 +20,16 @@ def find_relative(name, base_identifier, options) | |
return unless raw_filename | ||
|
||
item = raw_filename_to_item(raw_filename) | ||
# it doesn't make sense to import a file, from Nanoc's content if the corresponding item has been deleted | ||
raise "unable to map #{raw_filename} to any item" if item.nil? | ||
|
||
filter.depend_on([item]) | ||
content = item ? item.raw_content : File.read(raw_filename) | ||
filename = item ? item.identifier.to_s : raw_filename | ||
|
||
filter.depend_on([item]) if item | ||
|
||
options[:syntax] = syntax | ||
options[:filename] = item.identifier.to_s | ||
options[:filename] = filename | ||
options[:importer] = self | ||
::Sass::Engine.new(item.raw_content, options) | ||
::Sass::Engine.new(content, options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why you're doing it. Indeed it may be desirable to keep backward compatibility and let people |
||
end | ||
|
||
def find(identifier, options) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'GH-1378', site: true, stdio: true do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally cool to learn how to assemble a "real site" instead of having to mock all Nanoc internals 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in particular used for regression tests, although I have also started writing integration tests in It’s not a substitute for unit tests, though, because the integration/regression tests tend to run slowly and so it’s not great for testing all the different cases. |
||
before do | ||
FileUtils.mkdir_p('content') | ||
File.write('outside.scss', 'p { color: red; }') | ||
File.write('content/style.scss', '@import "../outside.scss";') | ||
|
||
File.write('Rules', <<~EOS) | ||
compile '/*' do | ||
filter :sass, syntax: :scss | ||
write ext: 'css' | ||
end | ||
EOS | ||
end | ||
|
||
example do | ||
expect { Nanoc::CLI.run([]) } | ||
.to change { File.file?('output/style.css') } | ||
.from(false) | ||
.to(true) | ||
|
||
expect(File.read('output/style.css')).to match(/p\s*{\s*color:\s*red;\s*}/) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, this line indeed makes the compilation stop.
I think you should replace
by
And keep the rest of
importer.rb
as it is.This suggestion alone fixes #1378.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on Gitter, this won’t work with paths that are relative to the item itself and live outside of the Nanoc content directory.
e.g. current item =
content/style/foo.sass
, path to import = `../../external.sass'