Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ruby Sass's importer API #72

Open
nex3 opened this issue Mar 17, 2018 · 6 comments
Open

Support Ruby Sass's importer API #72

nex3 opened this issue Mar 17, 2018 · 6 comments

Comments

@nex3
Copy link

nex3 commented Mar 17, 2018

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
Copy link
Author

nex3 commented Apr 5, 2019

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

@gpakosz
Copy link

gpakosz commented May 4, 2019

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

What does it take to support the Sass importer API?

@mhenrixon
Copy link

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

@denisdefreyne
Copy link

denisdefreyne commented Jan 20, 2023

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: nanoc/nanoc#1545 (comment) (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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants