handlers

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2020 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrPayloadNil = errors.New("payload is nil")

ErrPayloadNil prevents panics on invalid payload; nil check helps find non-obvious dependency failures like mismatched dependencies.

Functions

func FontURL

func FontURL(ctx context.Context, usv libsass.SassValue) (*libsass.SassValue, error)

FontURL builds a relative path to the requested font file from the built CSS.

func ImageHeight

func ImageHeight(mainctx context.Context, usv libsass.SassValue) (*libsass.SassValue, error)

ImageHeight takes a file path (or sprite glob) and returns the height in pixels of the image being referenced.

func ImageURL

func ImageURL(ctx context.Context, csv libsass.SassValue) (*libsass.SassValue, error)

ImageURL handles calls to resolve the path to a local image from the built css file path.

func ImageWidth

func ImageWidth(mainctx context.Context, usv libsass.SassValue) (rsv *libsass.SassValue, err error)

ImageWidth takes a file path (or sprite glob) and returns the width in pixels of the image being referenced.

func InlineImage

func InlineImage(mainctx context.Context, usv libsass.SassValue) (rsv *libsass.SassValue, err error)

InlineImage returns a base64 encoded png from the input image

func Sprite

func Sprite(ctx context.Context, usv libsass.SassValue) (rsv *libsass.SassValue, err error)

Sprite returns the source and background position for an image in the spritesheet.

Example
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; }
Example (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; }

func SpriteFile

func SpriteFile(ctx context.Context, usv libsass.SassValue) (rsv *libsass.SassValue, err error)

SpriteFile proxies the sprite glob and image name through.

func SpriteMap

func SpriteMap(mainctx context.Context, usv libsass.SassValue) (*libsass.SassValue, error)

SpriteMap returns a sprite from the passed glob and sprite parameters.

func SpriteNames added in v1.0.5

func SpriteNames(ctx context.Context, usv libsass.SassValue) (*libsass.SassValue, error)

SpriteNames returns the names of all images in a sprite map

func SpritePosition added in v0.9.2

func SpritePosition(mainctx context.Context, usv libsass.SassValue) (rsv *libsass.SassValue, err error)

SpritePosition returns the position of the image in the sprite-map. This is useful for passing directly to background-position

func WarnHandler added in v0.9.2

func WarnHandler(v interface{}, csv libsass.SassValue, rsv *libsass.SassValue) error

WarnHandler captures Sass warnings and redirects to stdout

Types

type Resolver added in v1.0.1

type Resolver interface {
	Do(string) (io.ReadCloser, error)
}

Resolver interface returns a ReadCloser from a path

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL