Sha256: c1e7e2068cba62c91a3f7e8183072eed52b1ac0218e5475af8fb725ea671cc90

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

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, :string, :pointer]) do |path, parent_path, cookie|
        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

4 entries across 4 versions & 1 rubygems

Version Path
sassc-1.1.1 lib/sassc/import_handler.rb
sassc-1.1.0 lib/sassc/import_handler.rb
sassc-1.0.0 lib/sassc/import_handler.rb
sassc-0.0.11 lib/sassc/import_handler.rb