Exemplo n.º 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
}
Exemplo n.º 2
0
func (opt *options) SetIncludePath(include string) {
	C.sass_option_set_include_path(opt.optc(), C.CString(include))
}
Exemplo n.º 3
0
func (c *Context) SetIncludePaths(opts *C.struct_Sass_Options) {
	for _, inc := range c.IncludePaths {
		C.sass_option_set_include_path(opts, C.CString(inc))
	}
}
Exemplo n.º 4
0
// SassOptionSetIncludePaths adds additional paths to look for input Sass
func SassOptionSetIncludePath(goopts SassOptions, path string) {
	C.sass_option_set_include_path(goopts, C.CString(path))
}