Example #1
0
File: sass.go Project: pascalj/sass
func Compile(input string, options *SassOptions) (compiled string, err error) {
	ctx := newSassCtx()
	ctx.source_string = C.CString(input)
	ctx.options = newCSassOptions(options)
	defer C.free(unsafe.Pointer(ctx.source_string))

	C.sass_compile(ctx)

	if ctx.error_status > 0 {
		return "", errors.New(C.GoString(ctx.error_message))
	}
	return C.GoString(ctx.output_string), nil
}
Example #2
0
func Compile(goCtx *Context) {
	// set up the underlying C context struct
	cCtx := C.sass_new_context()
	cCtx.source_string = C.CString(goCtx.SourceString)
	defer C.free(unsafe.Pointer(cCtx.source_string))
	cCtx.options.output_style = C.int(goCtx.Options.OutputStyle)
	if goCtx.Options.SourceComments {
		cCtx.options.source_comments = C.int(1)
	} else {
		cCtx.options.source_comments = C.int(0)
	}
	cCtx.options.include_paths = C.CString(strings.Join(goCtx.Options.IncludePaths, ":"))
	defer C.free(unsafe.Pointer(cCtx.options.include_paths))
	cCtx.options.image_path = C.CString(goCtx.Options.ImagePath)
	defer C.free(unsafe.Pointer(cCtx.options.image_path))
	// call the underlying C compile function to populate the C context
	C.sass_compile(cCtx)
	// extract values from the C context to populate the Go context object
	goCtx.OutputString = C.GoString(cCtx.output_string)
	goCtx.ErrorStatus = int(cCtx.error_status)
	goCtx.ErrorMessage = C.GoString(cCtx.error_message)
	// don't forget to free the C context!
	C.sass_free_context(cCtx)
}