Пример #1
0
func (ctx *Context) FileCompile(path string, out io.Writer) error {
	defer ctx.Reset()
	gofc := libs.SassMakeFileContext(path)
	goopts := libs.SassFileContextGetOptions(gofc)
	ctx.Init(goopts)
	//os.PathListSeparator
	incs := strings.Join(ctx.IncludePaths, string(os.PathListSeparator))
	libs.SassOptionSetIncludePath(goopts, incs)
	libs.SassFileContextSetOptions(gofc, goopts)
	gocc := libs.SassFileContextGetContext(gofc)
	gocompiler := libs.SassMakeFileCompiler(gofc)
	libs.SassCompilerParse(gocompiler)
	ctx.ResolvedImports = libs.GetImportList(gocc)
	libs.SassCompilerExecute(gocompiler)
	defer libs.SassDeleteCompiler(gocompiler)

	goout := libs.SassContextGetOutputString(gocc)
	io.WriteString(out, goout)
	ctx.Status = libs.SassContextGetErrorStatus(gocc)
	errJSON := libs.SassContextGetErrorJSON(gocc)
	// Yet another property for storing errors
	err := ctx.ProcessSassError([]byte(errJSON))
	if err != nil {
		return err
	}
	if ctx.Error() != "" {
		// TODO: this is weird, make something more idiomatic*/
		return errors.New(ctx.Error())
	}

	return nil
}
Пример #2
0
func (ctx *compctx) FileCompile(path string, out io.Writer, srcmap io.Writer) error {
	defer ctx.Reset()
	gofc := libs.SassMakeFileContext(path)
	goopts := libs.SassFileContextGetOptions(gofc)
	ctx.Init(goopts)
	//os.PathListSeparator
	incs := strings.Join(ctx.IncludePaths, string(os.PathListSeparator))
	libs.SassOptionSetIncludePath(goopts, incs)

	libs.SassFileContextSetOptions(gofc, goopts)
	gocc := libs.SassFileContextGetContext(gofc)
	ctx.context = gocc
	gocompiler := libs.SassMakeFileCompiler(gofc)
	libs.SassCompilerParse(gocompiler)
	ctx.ResolvedImports = libs.GetImportList(gocc)
	libs.SassCompilerExecute(gocompiler)
	defer libs.SassDeleteCompiler(gocompiler)

	goout := libs.SassContextGetOutputString(gocc)
	if out == nil {
		return errors.New("out writer required")
	}
	_, err := io.WriteString(out, goout)
	if err != nil {
		return err
	}
	ctx.Status = libs.SassContextGetErrorStatus(gocc)
	errJSON := libs.SassContextGetErrorJSON(gocc)
	mapout := libs.SassContextGetSourceMapString(gocc)

	if srcmap != nil && ctx.includeMap && len(mapout) > 0 {
		_, err := io.WriteString(srcmap, mapout)
		if err != nil {
			return err
		}
	}
	// Yet another property for storing errors
	err = ctx.ProcessSassError([]byte(errJSON))
	if err != nil {
		return err
	}
	if ctx.Error() != "" {
		// TODO: this is weird, make something more idiomatic*/
		return errors.New(ctx.Error())
	}

	return nil
}