Sha256: 13db2379ff75fb6083631e522fb2bc0896bbbf596e3330239832a005b3ba1365

Contents?: true

Size: 1.32 KB

Versions: 93

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module SassC
  class ImportHandler
    def initialize(options)
      @importer = if options[:importer]
        options[:importer].new(options)
      else
        nil
      end
    end

    def setup(native_options)
      return unless @importer

      importer_callback = Native.make_importer(import_function, nil)

      list = Native.make_function_list(1)
      Native::function_set_list_entry(list, 0, importer_callback)

      Native.option_set_c_importers(native_options, list)
    end

    private

    def import_function
      @import_function ||= FFI::Function.new(:pointer, [:string, :pointer, :pointer]) do |path, importer_entry, compiler|
        last_import = Native::compiler_get_last_import(compiler)
        parent_path = Native::import_get_abs_path(last_import)

        imports = [*@importer.imports(path, parent_path)]
        imports_to_native(imports)
      end
    end

    def imports_to_native(imports)
      import_list = Native.make_import_list(imports.size)

      imports.each_with_index do |import, i|
        source = import.source ? Native.native_string(import.source) : nil
        source_map_path = nil

        entry = Native.make_import_entry(import.path, source, source_map_path)
        Native.import_set_list_entry(import_list, i, entry)
      end

      import_list
    end
  end
end

Version data entries

93 entries across 77 versions & 7 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/sassc-2.4.0/lib/sassc/import_handler.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/sassc-2.4.0/lib/sassc/import_handler.rb
sassc-embedded-1.80.2 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.80.1 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.80.0 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.79.0 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.78.0 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/sassc-2.4.0/lib/sassc/import_handler.rb
sassc-embedded-1.77.8 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.7 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.6 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.5 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.4 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.3 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.2 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.1 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.77.0 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.76.0 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.75.2 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb
sassc-embedded-1.75.1 vendor/github.com/sass/sassc-ruby/lib/sassc/import_handler.rb