Skip to content

Commit

Permalink
Add support for index imports
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Mar 24, 2018
1 parent afdb2ab commit b80efe7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ namespace Sass {
// (2) underscore + given
// (3) underscore + given + extension
// (4) given + extension
// (5) given + _index.scss
// (6) given + _index.sass
std::vector<Include> resolve_includes(const std::string& root, const std::string& file, const std::vector<std::string>& exts, const std::vector<std::string>& d_exts)
{
std::string filename = join_paths(root, file);
Expand Down Expand Up @@ -363,6 +365,25 @@ namespace Sass {
abs_path = join_paths(root, rel_path);
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
}
// index files
if (includes.size() == 0) {
// ignore directories that look like @import'able filename
for(auto ext : exts) {
if (ends_with(name, ext)) return includes;
}
// next test underscore index exts
for(auto ext : exts) {
rel_path = join_paths(base, join_paths(name, "_index" + ext));
abs_path = join_paths(root, rel_path);
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
}
// next test plain index exts
for(auto ext : exts) {
rel_path = join_paths(base, join_paths(name, "index" + ext));
abs_path = join_paths(root, rel_path);
if (file_exists(abs_path)) includes.push_back({{ rel_path, root }, abs_path });
}
}
// nothing found
return includes;
}
Expand Down

0 comments on commit b80efe7

Please sign in to comment.