sass / sassc-rails

Integrate SassC-Ruby with Rails!
MIT License
706 stars 104 forks source link

Sassc-rails support for @import directory/_index.scss #120

Closed johnnybenson closed 5 years ago

johnnybenson commented 5 years ago

It appears that Sassc doesn't support directory imports.

I have my load_paths configured, it just looks like Importer#imports never looks for index files as a directory import.

https://sass-lang.com/documentation/file.SASS_REFERENCE.html#index_files

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.

Add support for directory imports

lib/sassc/rails/importer.rb#imports

        search_paths.each do |search_path|
          PREFIXS.each do |prefix|
            file_name = prefix + specified_file

            EXTENSIONS.each do |extension|
              try_path = File.join(search_path, file_name + extension.postfix)
              if File.exist?(try_path)
                record_import_as_dependency try_path
                return extension.import_for(try_path, parent_dir, options)
              end
+             try_path = File.join(search_path, specified_file,  prefix + 'index' + extension.postfix)
+             if File.exist?(try_path)
+                record_import_as_dependency try_path
+                return extension.import_for(try_path, parent_dir, options)              
+             end
            end
          end
        end

Has anyone else encountered this issue?

Adding these lines seems to add support for importing a directory, I can open a pull request if this seems reasonable.

First, I wanted to make sure it's not configuration on my end that I'm missing.

/* styles.scss */
@import 'directory';
app/
    stylesheets/
        styles.scss
        directory/
            _index.scss

This might be related / meaningful:

https://github.com/sass/sass/pull/2456/files

bolandrm commented 5 years ago

Hey, thanks for writing this up. Support for this has been added to libsass- https://github.com/sass/libsass/commit/3af837c4e6053487186cfcf564a990ff11e4e356 - and it will be available in sassc-rails when the next version of libsass is released.