Sha256: f016f8e5b6ac9d65bd3a830249730c871a2964ae851d5054acccbb44be5f3bd9

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

module SassC
  class Importer
    attr_reader :options

    def imports(path, parent_path)
      # A custom importer must override this method.
      raise NotImplementedError
    end

    def setup(native_options)
      @function = FFI::Function.new(:pointer, [:string, :string, :pointer]) do |path, parent_path, cookie|
        imports = [*imports(path, parent_path)]
        self.class.imports_to_native(imports)
      end

      callback = SassC::Native.make_importer(@function, nil)
      SassC::Native.option_set_importer(native_options, callback)
    end

    def initialize(options)
      @options = options
    end

    def self.empty_imports
      SassC::Native.make_import_list(0)
    end

    def self.imports_to_native(imports)
      import_list = SassC::Native.make_import_list(imports.size)

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

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

      import_list
    end

    def self.native_string(string)
      string += "\0"
      data = SassC::Native::LibC.malloc(string.size)
      data.write_string(string)
      data
    end

    class Import
      attr_accessor :path, :source, :source_map_path

      def initialize(path, source: nil, source_map_path: nil)
        @path = path
        @source = source
        @source_map_path = source_map_path
      end

      def to_s
        "Import: #{path} #{source} #{source_map_path}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sassc-0.0.9 lib/sassc/importer.rb