sass / sassc-ruby

Use libsass with Ruby!
MIT License
363 stars 157 forks source link

Support Ruby Sass's importer API #72

Open nex3 opened 6 years ago

nex3 commented 6 years ago

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 commented 5 years ago

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

gpakosz commented 5 years ago

Ruby Sass has reached end-of-life and should no longer be used.

What does it take to support the Sass importer API?

mhenrixon commented 1 year ago

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

denisdefreyne commented 1 year ago

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

mhenrixon commented 1 year ago

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 commented 1 year ago

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.