Open nex3 opened 6 years ago
Note to self: when this is fixed, update https://sass-lang.com/ruby-sass.
Ruby Sass has reached end-of-life and should no longer be used.
If you use Sass as a command-line tool, we recommend using Dart Sass, the new primary implementation: https://sass-lang.com/install
If you use Sass as a plug-in for a Ruby web framework, we recommend using the sassc gem: https://github.com/sass/sassc-ruby#readme
For more details, please refer to the Sass blog: https://sass-lang.com/blog/posts/7828841
What does it take to support the Sass importer API?
Having the same (and imo valid) question. Why was it removed?
I believe it was never added in the first place.
sassc
(and thus sassc-ruby
) is not maintained anymore, but there is Dart Sass which is better in all aspects, and also has an importer API.
I use sass-embedded-host-ruby instead of sassc-ruby and it works great. I think this comment shows fairly well how to use it with the importer API: https://github.com/nanoc/nanoc/issues/1545#issuecomment-1321210053 (and a better-factored version at https://github.com/nanoc/nanoc/blob/main/nanoc-dart-sass/lib/nanoc/dart_sass/filter.rb#L19-L24).
Figured out how to write one for SassC:
# frozen_string_literal: true
module WM3
class SassImporter < SassC::Importer
def initialize(options)
@options = options
@site_id = options[:site_id]
end
def imports(path, parent_path)
template = find_template(path)
SassC::Importer::Import.new(path, source: template.content.to_s)
end
private
attr_reader :site_id
def find_template(path)
cache[key(path)] ||= Template.find_by(
site_id: site_id,
name: path,
tpl_type: "css"
)
end
def cache
@cache ||= {}
end
def key(path)
[site_id.to_s, path.to_s]
end
end
end
I use sass-embedded-host-ruby instead of sassc-ruby and it works great.
Unfortunately, it doesn't work at all for me, and in my opinion, dartsass is inferior to sassc. Shame it was deprecated.
This gem should support Ruby Sass's API for defining importers. Not only will this help users migrating to the
sassc
gem from Ruby Sass, it's a more robust API that provides stronger guarantees to the stylesheet author that relative URLs will work as expected.