Esempio n. 1
0
func TestRegImageURL(t *testing.T) {
	contents := `
div {
    background: image-url("139.png");
}`
	in := bytes.NewBufferString(contents)
	var out bytes.Buffer
	comp, err := setupComp(t, in, &out)
	if err != nil {
		t.Error(err)
	}
	e := `div {
  background: url('../img/139.png'); }
`
	if e != out.String() {
		t.Errorf("got:\n%s\nwanted:\n%s", out.String(), e)
	}
	out.Reset()
	comp.Option(libsass.CacheBust("ts"))

	in.WriteString(contents)
	err = comp.Run()
	if err != nil {
		t.Fatal(err)
	}
	info, err := os.Stat("../test/img/139.png")
	if err != nil {
		t.Fatal(err)
	}
	qry, err := modHash(info)
	if err != nil {
		t.Fatal(err)
	}
	e = fmt.Sprintf(`div {
  background: url('../img/139.png%s'); }
`, qry)

	if e != out.String() {
		t.Errorf("got: %s\nwanted: %s", out.String(), e)
	}

	out.Reset()
	comp.Option(libsass.CacheBust("sum"))

	in.WriteString(contents)
	err = comp.Run()
	if err != nil {
		t.Fatal(err)
	}
	e = `div {
  background: url('../img/139.png?194da102'); }
`

	if e != out.String() {
		t.Errorf("got: %s\nwanted: %s", out.String(), e)
	}

}
Esempio n. 2
0
func TestImageUrl_bustsmallfile(t *testing.T) {
	// Ensure cache busting works for files smaller than header buffer
	contents := `
div {
    background: image-url("pixel/1x1.png");
}`
	in := bytes.NewBufferString(contents)
	var out bytes.Buffer
	comp, err := setupComp(t, in, &out)
	if err != nil {
		t.Error(err)
	}
	// This is annoying, but no way to configure compiler
	in.WriteString(contents)
	out.Reset()
	comp.Option(libsass.CacheBust("sum"))
	err = comp.Run()
	if err != nil {
		t.Fatal(err)
	}
	e := `div {
  background: url('../img/pixel/1x1.png?7b29fcd7'); }
`
	if e != out.String() {
		t.Errorf("got:\n%s\nwanted:\n%s", out.String(), e)
	}
}
Esempio n. 3
0
func TestFontURL(t *testing.T) {
	contents := `
$path: font-url($raw: true, $path: "arial.eot");
@font-face {
  src: font-url("arial.eot");
  src: url("#{$path}");
}`
	in := bytes.NewBufferString(contents)
	var out bytes.Buffer
	comp, err := setupComp(t, in, &out)
	if err != nil {
		t.Fatal(err)
	}
	e := `@font-face {
  src: url("../font/arial.eot");
  src: url("../font/arial.eot"); }
`

	if e != out.String() {
		t.Errorf("got: %s wanted: %s", out.String(), e)
	}

	comp.Option(libsass.CacheBust("ts"))
	in.WriteString(contents)
	out.Reset()
	err = comp.Run()
	if err != nil {
		t.Fatal(err)
	}

	info, err := os.Stat("../test/font/arial.eot")
	if err != nil {
		t.Fatal(err)
	}
	qs, err := modHash(info)
	if err != nil {
		t.Fatal(err)
	}

	e = fmt.Sprintf(`@font-face {
  src: url("../font/arial.eot%s");
  src: url("../font/arial.eot%s"); }
`, qs, qs)
	if e != out.String() {
		t.Errorf("got: %s wanted: %s", out.String(), e)
	}

}
Esempio 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
}