sassc-ruby icon indicating copy to clipboard operation
sassc-ruby copied to clipboard

Support Ruby Sass's importer API

Open nex3 opened this issue 7 years ago • 6 comments

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.

nex3 avatar Mar 17 '18 19:03 nex3

Note to self: when this is fixed, update https://sass-lang.com/ruby-sass.

nex3 avatar Apr 05 '19 07:04 nex3

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?

gpakosz avatar May 04 '19 16:05 gpakosz

Having the same (and imo valid) question. Why was it removed?

mhenrixon avatar Jan 20 '23 08:01 mhenrixon

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).

denisdefreyne avatar Jan 20 '23 10:01 denisdefreyne

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

mhenrixon avatar Jan 29 '23 12:01 mhenrixon

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.

mhenrixon avatar Jan 29 '23 12:01 mhenrixon