Skip to content

Commit

Permalink
Add support for _index files (#2456)
Browse files Browse the repository at this point in the history
Closes #690
  • Loading branch information
john681611 authored and nex3 committed Mar 9, 2018
1 parent ed215ad commit ad7760a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -3,6 +3,11 @@
* Table of contents
{:toc}

## 3.6.0 (Unreleased)

* Add support for importing an `_index.scss` or `_index.sass` file when
importing a directory.

## 3.5.6 (Unreleased)

* `var()` may now be passed in place of multiple arguments to `rgb()`, `rgba()`,
Expand Down
8 changes: 8 additions & 0 deletions doc-src/SASS_REFERENCE.md
Expand Up @@ -1349,6 +1349,14 @@ Note that you may not include a partial and a non-partial with the same name in
the same directory. For example, `_colors.scss` may not exist alongside
`colors.scss`.

#### Index Files

If you write a file with the special name `_index.scss` or `_index.sass`, it
will be loaded if you import the directory that contains it. For example, if you
have `dir/_index.scss`, you can write `@import "dir";` and it will load your
file. However, if you have a file named `_dir.scss` *and* a file named
`dir/_index.scss`, `_dir.scss` will take precedence.

#### Nested `@import`

Although most of the time it's most useful to just have `@import`s
Expand Down
6 changes: 4 additions & 2 deletions lib/sass/importers/filesystem.rb
Expand Up @@ -154,7 +154,9 @@ def find_real_file(dir, name, options)
[Sass::Util.cleanpath(full_path).to_s, s]
end
end.flatten(1)
return if found.empty?
if found.empty? && split(name)[2].nil? && File.directory?("#{dir}/#{name}")
return find_real_file("#{dir}/#{name}", "index", options)
end

if found.size > 1 && !@same_name_warnings.include?(found.first.first)
found.each {|(f, _)| @same_name_warnings << f}
Expand Down Expand Up @@ -202,7 +204,7 @@ def split(name)

def _find(dir, name, options)
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
return unless full_filename && File.readable?(full_filename)
return unless full_filename && File.file?(full_filename) && File.readable?(full_filename)

# TODO: this preserves historical behavior, but it's possible
# :filename should be either normalized to the native format
Expand Down

0 comments on commit ad7760a

Please sign in to comment.