예제 #1
0
func (c *Context) FileCompile(path string, out io.Writer) error {
	defer c.Reset()
	cpath := C.CString(path)
	fc := C.sass_make_file_context(cpath)
	defer C.sass_delete_file_context(fc)
	fcopts := C.sass_file_context_get_options(fc)
	goopts := (*SassOptions)(fcopts)
	opts := c.Init(goopts)
	//os.PathListSeparator
	incs := strings.Join(c.IncludePaths, string(os.PathListSeparator))
	C.sass_option_set_include_path(opts, C.CString(incs))
	C.sass_file_context_set_options(fc, opts)
	cc := C.sass_file_context_get_context(fc)
	compiler := C.sass_make_file_compiler(fc)
	C.sass_compiler_parse(compiler)
	c.ResolvedImports = GetImportList(cc)
	C.sass_compiler_execute(compiler)
	defer C.sass_delete_compiler(compiler)
	cout := C.GoString(C.sass_context_get_output_string(cc))
	io.WriteString(out, cout)
	c.Status = int(C.sass_context_get_error_status(cc))
	errJson := C.sass_context_get_error_json(cc)
	err := c.ProcessSassError([]byte(C.GoString(errJson)))
	if err != nil {
		return err
	}
	if c.error() != "" {
		/*lines := bytes.Split(bs, []byte("\n"))
		var out string
		for i := -7; i < 7; i++ {
			if i+c.Errors.Line >= 0 && i+c.Errors.Line < len(lines) {
				out += fmt.Sprintf("%s\n", string(lines[i+c.Errors.Line]))
			}
		}
		// TODO: this is weird, make something more idiomatic*/
		return errors.New(c.error())
	}

	return nil
}
예제 #2
0
// SassMakeFileContext maps to C.sass_make_file_context
func SassMakeFileContext(gos string) SassFileContext {
	s := C.CString(gos)
	fctx := C.sass_make_file_context(s)
	return (SassFileContext)(fctx)
}