Esempio n. 1
0
// SassMakeImport attaches a Go pointer to a Sass function. Go will
// eventually kill this behavior and we should find a new way to do this.
func SassMakeImporter(fn SassImporterFN, priority int, v interface{}) (SassImporter, error) {
	vv := reflect.ValueOf(v).Elem()
	if !vv.CanAddr() {
		return nil, errors.New("can not take address of")
	}
	// TODO: this will leak memory, the interface must be freed manually
	lst := C.sass_make_importer(fn, C.double(priority), unsafe.Pointer(vv.Addr().Pointer()))
	return (SassImporter)(lst), nil
}
Esempio n. 2
0
// SetImporter enables custom importer in libsass
func (ctx *Context) SetImporter(opts *C.struct_Sass_Options) {

	imps := C.sass_make_importer_list(1)
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(imps)),
		Len:  1, Cap: 1,
	}
	goimps := *(*[]C.Sass_Importer_Entry)(unsafe.Pointer(&hdr))
	p := C.SassImporter
	imp := C.sass_make_importer(
		C.Sass_Importer_Fn(p),
		C.double(0),
		unsafe.Pointer(ctx))
	goimps[0] = imp
	C.sass_option_set_c_importers(opts, imps)
}
Esempio n. 3
0
// BindHeader attaches the header to a libsass context ensuring
// gc does not delete the pointers necessary to make this happen.
func BindHeader(opts SassOptions, entries []ImportEntry) *string {

	idx := globalHeaders.set(entries)
	ptr := unsafe.Pointer(idx)

	imper := C.sass_make_importer(
		C.Sass_Importer_Fn(C.SassHeaders),
		C.double(0),
		ptr,
	)
	impers := C.sass_make_importer_list(1)
	C.sass_importer_set_list_entry(impers, 0, imper)

	C.sass_option_set_c_headers(
		(*C.struct_Sass_Options)(unsafe.Pointer(opts)),
		impers)
	return idx
}
Esempio n. 4
0
// BindImporter attaches a custom importer Go function to an import in Sass
func BindImporter(opts SassOptions, entries []ImportEntry) int {

	idx := globalImports.Set(entries)
	ptr := unsafe.Pointer(idx)

	imper := C.sass_make_importer(
		C.Sass_Importer_Fn(C.SassImporterHandler),
		C.double(0),
		ptr,
	)
	impers := C.sass_make_importer_list(1)
	C.sass_importer_set_list_entry(impers, 0, imper)

	C.sass_option_set_c_importers(
		(*C.struct_Sass_Options)(unsafe.Pointer(opts)),
		impers,
	)
	return *idx
}
Esempio n. 5
0
func (ctx *Context) SetHeaders(opts *C.struct_Sass_Options) {
	// Push the headers into the local array
	for _, gh := range globalHeaders {
		ctx.Headers.Add(gh)
	}

	cheads := C.sass_make_importer_list(1)
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(cheads)),
		Len:  1, Cap: 1,
	}
	goheads := *(*[]C.Sass_Importer_Entry)(unsafe.Pointer(&hdr))

	imper := C.sass_make_importer(
		C.Sass_Importer_Fn(C.SassHeaders),
		C.double(0),
		unsafe.Pointer(ctx))

	goheads[0] = imper

	C.sass_option_set_c_headers(opts, cheads)
}