コード例 #1
0
ファイル: wrap.go プロジェクト: pcasaretto/go-libsass
// ImporterBridge is called by C to pass Importer arguments into Go land. A
// Sass_Import is returned for libsass to resolve.
//
//export ImporterBridge
func ImporterBridge(url *C.char, prev *C.char, ptr unsafe.Pointer) C.Sass_Import_List {
	// Retrieve the index
	idx := (*string)(ptr)
	entries, ok := globalImports.get(idx).([]ImportEntry)
	if !ok {
		fmt.Printf("failed to resolve import slice: %p\n", ptr)
		entries = []ImportEntry{}
	}

	parent := C.GoString(prev)
	rel := C.GoString(url)
	list := C.sass_make_import_list(1)
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(list)),
		Len:  1, Cap: 1,
	}

	golist := *(*[]C.Sass_Import_Entry)(unsafe.Pointer(&hdr))
	if body, err := GetEntry(entries, parent, rel); err == nil {
		ent := C.sass_make_import_entry(url, C.CString(body), nil)
		cent := (C.Sass_Import_Entry)(ent)
		golist[0] = cent
	} else if strings.HasPrefix(rel, "compass") {
		ent := C.sass_make_import_entry(url, C.CString(""), nil)
		cent := (C.Sass_Import_Entry)(ent)
		golist[0] = cent
	} else {
		ent := C.sass_make_import_entry(url, nil, nil)
		cent := (C.Sass_Import_Entry)(ent)
		golist[0] = cent
	}

	return list
}
コード例 #2
0
ファイル: export.go プロジェクト: godeep/wellington
// ImporterBridge is called by C to pass Importer arguments into Go land. A
// Sass_Import is returned for libsass to resolve.
//
//export ImporterBridge
func ImporterBridge(url *C.char, prev *C.char, ptr unsafe.Pointer) C.Sass_Import_List {
	ctx := (*Context)(ptr)
	parent := C.GoString(prev)
	rel := C.GoString(url)
	list := C.sass_make_import_list(1)
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(list)),
		Len:  1, Cap: 1,
	}
	golist := *(*[]C.Sass_Import_Entry)(unsafe.Pointer(&hdr))
	if body, err := ctx.Imports.Get(parent, rel); err == nil {
		conts := C.CString(string(body))
		ent := C.sass_make_import_entry(url, conts, nil)
		cent := (C.Sass_Import_Entry)(ent)
		golist[0] = cent
	} else if strings.HasPrefix(rel, "compass") {
		ent := C.sass_make_import_entry(url, C.CString(""), nil)
		cent := (C.Sass_Import_Entry)(ent)
		golist[0] = cent
	} else {
		ent := C.sass_make_import_entry(url, nil, nil)
		cent := (C.Sass_Import_Entry)(ent)
		golist[0] = cent
	}

	return list
}
コード例 #3
0
ファイル: wrap.go プロジェクト: pcasaretto/go-libsass
//export HeaderBridge
func HeaderBridge(ptr unsafe.Pointer) C.Sass_Import_List {
	idx := (*string)(ptr)
	entries, ok := globalHeaders.get(idx).([]ImportEntry)
	if !ok {
		fmt.Printf("failed to resolve header slice: %p\n", ptr)
		return C.sass_make_import_list(C.size_t(1))
	}

	cents := C.sass_make_import_list(C.size_t(len(entries)))

	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(cents)),
		Len:  len(entries), Cap: len(entries),
	}
	goents := *(*[]C.Sass_Import_Entry)(unsafe.Pointer(&hdr))

	for i, ent := range entries {
		// Each entry needs a unique name
		cent := C.sass_make_import_entry(
			C.CString(ent.Path),
			C.CString(ent.Source),
			C.CString(ent.SrcMap))
		// There is a function for modifying an import list, but a proper
		// slice might be more useful.
		// C.sass_import_set_list_entry(cents, C.size_t(i), cent)
		goents[i] = cent
	}

	return cents
}
コード例 #4
0
ファイル: export.go プロジェクト: godeep/wellington
// HeaderBridge is called by libsass to find available custom headers
//
//export HeaderBridge
func HeaderBridge(ptr unsafe.Pointer) C.Sass_Import_List {
	ctx := (*Context)(ptr)
	l := ctx.Headers.Len()
	list := C.sass_make_import_list(C.size_t(l))
	hdr := reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(list)),
		Len:  l, Cap: l,
	}
	golist := *(*[]C.Sass_Import_Entry)(unsafe.Pointer(&hdr))

	for i, head := range ctx.Headers.h {
		ent := C.sass_make_import_entry(
			nil,
			C.CString(head.Content),
			nil)
		cent := (C.Sass_Import_Entry)(ent)
		golist[i] = cent
	}
	return list
}