コード例 #1
0
func ExampleSprite_position() {
	in := bytes.NewBufferString(`
$map: sprite-map("*.png", 10px); // One argument
div {
  background-position: sprite-position($map, "140");
}

div.retina {
  background-position: 10px ceil(nth(sprite-position($map, "140"), 2) /2 );
}`)

	comp, err := libsass.New(os.Stdout, in,
		libsass.Payload(payload.New()),
		libsass.ImgDir("../test/img"),
		libsass.BuildDir("../test/build"),
		libsass.ImgBuildDir("../test/build/img"),
	)
	if err != nil {
		log.Fatal(err)
	}

	err = comp.Run()
	if err != nil {
		log.Fatal(err)
	}

	// Output:
	// div {
	//   background-position: 0px, -149px; }
	//
	// div.retina {
	//   background-position: 10px -74px; }
}
コード例 #2
0
func TestSpriteHTTP(t *testing.T) {
	in := bytes.NewBufferString(`
$map: sprite-map("*.png", 10px);
div {
  background: sprite($map, "140");
}`)

	var out bytes.Buffer
	comp, err := libsass.New(&out, in,
		libsass.OutputStyle(libsass.NESTED_STYLE),
		libsass.BuildDir("../test/build"),
		libsass.ImgDir("../test/img"),
		libsass.FontDir("../test/font"),
		libsass.Payload(payload.New()),
		libsass.ImgBuildDir("../test/build/img"),
		libsass.HTTPPath("http://foo.com"),
	)
	if err != nil {
		t.Fatal(err)
	}

	if err := comp.Run(); err != nil {
		t.Fatal(err)
	}

	e := `div {
  background: url("http://foo.com/build/b9d55f.png") 0px -149px; }
`
	if e != out.String() {
		t.Errorf("got:\n%s\nwanted:\n%s", out.String(), e)
	}

}
コード例 #3
0
func setupComp(t *testing.T, r io.Reader, out io.Writer) (libsass.Compiler, error) {

	comp, err := libsass.New(out, r,
		libsass.OutputStyle(libsass.NESTED_STYLE),
		libsass.BuildDir("../test/build"),
		libsass.ImgDir("../test/img"),
		libsass.FontDir("../test/font"),
		libsass.Payload(payload.New()),
		libsass.ImgBuildDir("../test/build/img"),
	)
	if err != nil {
		t.Fatal(err)
	}
	testSprite(t, comp)

	done := make(chan struct{})
	go func() {
		select {
		case <-time.After(5 * time.Second):
			t.Fatal("setupComp timeout")
		case <-done:
			return
		}
	}()

	err = comp.Run()
	close(done)
	return comp, err
}
コード例 #4
0
func TestCompileStdin_imports(t *testing.T) {

	in := bytes.NewBufferString(`@import "compass";
@import "compass/utilities/sprite/base";

`)

	var buf bytes.Buffer
	comp, err := libsass.New(&buf, in, libsass.Payload(payload.New()))
	if err != nil {
		t.Fatal(err)
	}

	if err := comp.Run(); err != nil {
		t.Fatal(err)
	}

	out := buf.String()
	if e := ``; e != out {
		t.Fatalf("mismatch expected:\n%s\nwas:\n%s\n", e, out)
	}
}
コード例 #5
0
func TestFuncSpriteFile(t *testing.T) {

	comp, err := libsass.New(nil, nil,
		libsass.Payload(payload.New()),
		libsass.ImgDir("../test/img"),
		libsass.BuildDir("../test/build"),
		libsass.ImgBuildDir("../test/build/img"),
	)
	if err != nil {
		t.Fatal(err)
	}

	// Add real arguments when sass lists can be [un]marshalled
	lst := []interface{}{"*.png", "139"}
	usv, err := libsass.Marshal(lst)
	if err != nil {
		t.Fatal(err)
	}

	rsv, err := SpriteFile(libsass.NewCompilerContext(comp), usv)
	if err != nil {
		t.Fatal(err)
	}
	var glob, path string
	err = libsass.Unmarshal(*rsv, &glob, &path)
	if err != nil {
		t.Error(err)
	}

	if e := "*.png"; e != glob {
		t.Errorf("got: %s wanted: %s", e, glob)
	}

	if e := "139"; e != path {
		t.Errorf("got: %s wanted: %s", e, path)
	}

}
コード例 #6
0
func ExampleSprite() {
	in := bytes.NewBufferString(`
$map: sprite-map("*.png", 10px); // One argument
div {
  background: sprite($map, "140");
}`)

	comp, err := libsass.New(os.Stdout, in,
		libsass.Payload(payload.New()),
		libsass.ImgDir("../test/img"),
		libsass.BuildDir("../test/build"),
		libsass.ImgBuildDir("../test/build/img"),
	)
	if err != nil {
		log.Fatal(err)
	}
	if err := comp.Run(); err != nil {
		log.Fatal(err)
	}

	// Output:
	// div {
	//   background: url("img/b9d55f.png") 0px -149px; }
}
コード例 #7
0
// Init initializes the payload, this should really go away
func (b *BuildArgs) init() {
	b.Payload = payload.New()
}