Exemple #1
0
func SassHandler(h SassFunc) libs.SassCallback {
	return func(v interface{}, usv libs.UnionSassValue, rsv *libs.UnionSassValue) error {
		if *rsv == nil {
			*rsv = libs.MakeNil()
		}

		libCtx, ok := v.(*compctx)
		if !ok {
			return errors.New("libsass Context not found")
		}

		ctx := NewCompilerContext(libCtx.compiler)

		// Cast to exported Go types
		req := SassValue{value: usv}
		res, err := h(ctx, req)

		if err != nil {
			// Returns the error to libsass Compiler
			*rsv = libs.MakeError(err.Error())
			// Returning an error does nothing as libsass is in charge of
			// reporting error to user
			return err
		}

		*rsv = res.Val()
		return err
	}
}
Exemple #2
0
// Error takes a Go error and returns a libsass Error
func Error(err error) SassValue {
	return SassValue{value: libs.MakeError(err.Error())}
}