Ejemplo n.º 1
0
Archivo: scss.go Proyecto: siongui/pali
func main() {
	scssPath := flag.String("scsspath", "default value", "Path of SCSS file to be compiled")
	scssDir := flag.String("scssdir", "default value", "Include Dir of SCSS files")
	cssPath := flag.String("csspath", "default value", "Path of output CSS file")
	flag.Parse()

	// open input sass/scss file to be compiled
	fi, err := os.Open(*scssPath)
	if err != nil {
		panic(err)
	}
	defer fi.Close()

	// create output css file
	fo, err := os.Create(*cssPath)
	if err != nil {
		panic(err)
	}
	defer fo.Close()

	// options for compilation
	p := libsass.IncludePaths([]string{*scssDir})
	s := libsass.OutputStyle(libsass.COMPRESSED_STYLE)

	// create a new compiler with options
	comp, err := libsass.New(fo, fi, p, s)
	if err != nil {
		panic(err)
	}

	// start compile
	if err := comp.Run(); err != nil {
		panic(err)
	}
}
Ejemplo n.º 2
0
func main() {
	const sassdir = "src/style/"

	// open input sass/scss file to be compiled
	fi, err := os.Open(sassdir + "style.scss")
	if err != nil {
		panic(err)
	}
	defer fi.Close()

	// create output css file
	fo, err := os.Create("style.css")
	if err != nil {
		panic(err)
	}
	defer fo.Close()

	// options for compilation
	p := libsass.IncludePaths([]string{sassdir})
	s := libsass.OutputStyle(libsass.COMPRESSED_STYLE)

	// create a new compiler with options
	comp, err := libsass.New(fo, fi, p, s)
	if err != nil {
		panic(err)
	}

	// start compile
	if err := comp.Run(); err != nil {
		panic(err)
	}
}
Ejemplo n.º 3
0
func loadAndBuild(sassFile string, gba *BuildArgs, partialMap *SafePartialMap, out io.WriteCloser, sout io.WriteCloser, buildDir string) error {
	defer func() {
		// BuildDir lets us know if we should closer out. If no buildDir,
		// specified out == os.Stdout and do not close. If buildDir != "",
		// then out must be something we should close.
		// This is important, since out can be many things and inspecting
		// them could be race unsafe.
		if len(buildDir) > 0 {
			out.Close()
			sout.Close()
		}
	}()

	// FIXME: move this elsewhere or make it so it doesn't need to be set
	imgdir := gba.ImageDir
	if len(imgdir) == 0 {
		imgdir = filepath.Dir(sassFile)
	}

	comp, err := libsass.New(out, nil,
		// Options overriding defaults
		libsass.Path(sassFile),
		libsass.ImgDir(imgdir),
		libsass.BuildDir(buildDir),
		libsass.Payload(gba.Payload),
		libsass.Comments(gba.Comments),
		libsass.OutputStyle(gba.Style),
		libsass.FontDir(gba.Font),
		libsass.ImgBuildDir(gba.Gen),
		libsass.IncludePaths(gba.Includes),
		libsass.SourceMap(gba.SourceMap, sout),
	)
	if err != nil {
		return err
	}
	// Start Sass transformation
	err = comp.Run()
	if err != nil {
		return errors.New(color.RedString("%s", err))
	}

	for _, inc := range comp.Imports() {
		partialMap.AddRelation(sassFile, inc)
	}

	// TODO: moves this method to *Build and wait on it to finish
	// go func(file string) {
	select {
	case <-testch:
	default:

	}
	// }(sassFile)
	return nil
}
Ejemplo n.º 4
0
// FromBuildArgs creates a compiler from BuildArgs
func FromBuildArgs(dst io.Writer, dstmap io.Writer, src io.Reader, gba *BuildArgs) (libsass.Compiler, error) {
	if gba == nil {
		return libsass.New(dst, src)
	}
	if gba.Payload == nil {
		gba.init()
	}

	comp, err := libsass.New(dst, src,
		// Options overriding defaults
		// libsass.Path(sassFile), what path should be provided?
		libsass.ImgDir(gba.ImageDir),
		libsass.ImgBuildDir(gba.Gen),
		libsass.BuildDir(gba.BuildDir),
		libsass.Payload(gba.Payload),
		libsass.Comments(gba.Comments),
		libsass.OutputStyle(gba.Style),
		libsass.FontDir(gba.Font),
		libsass.IncludePaths(gba.Includes),
		libsass.CacheBust(gba.CacheBust),
		libsass.SourceMap(gba.SourceMap, dstmap),
	)
	return comp, err
}