libsass

package
v0.0.0-...-fa3d426 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2016 License: MIT Imports: 16 Imported by: 0

README

libsass

Circle CI Build status

Libsass provides Go bindings for the speedy sass/libsass project.

To build, setup Go

go build

To test

go test
FAQ

Rebuilding libsass on each go compilation is very slow. Optionally, it is possible to link against a system installed libsass. To leverage a system installed libsass, use -tags dev.

go build -tags dev
go test -tags dev

Documentation

Overview

Package context wraps access to libsass. Higher level abstractions are used to make the package more like Go than C. For low level access see: http://godoc.org/github.com/wellington/go-libsass/libs

For more info, see https://github.com/sass/libsass

Index

Examples

Constants

View Source
const (
	NESTED_STYLE = iota
	EXPANDED_STYLE
	COMPACT_STYLE
	COMPRESSED_STYLE
)

Constants/enums for the output style.

Variables

View Source
var (
	ErrImportNotFound = errors.New("Import unreachable or not found")
)
View Source
var (
	ErrSassNumberNoUnit = errors.New("SassNumber has no units")
)
View Source
var Style map[string]int
View Source
var TestCallback = testCallback(func(_ interface{}, _ SassValue, _ *SassValue) error {
	return nil
})

TestCallback implements libs.SassCallback. TestCallback is a useful place to start when developing new handlers.

Functions

func Handler

func Handler(h HandlerFunc) libs.SassCallback

Handler accepts a HandlerFunc and returns SassCallback for sending to libsass. The third argument must be a pointer and the function must return an error.

func Mixins

func Mixins(ctx *Context)

Mixins registers the default list of supported mixins

func RegisterHandler

func RegisterHandler(sign string, callback HandlerFunc)

RegisterHandler sets the passed signature and callback to the handlers array.

func RegisterHeader

func RegisterHeader(body string)

RegisterHeader fifo

func ToScss

func ToScss(r io.Reader, w io.Writer) error

ToScss converts Sass to Scss with libsass sass2scss.h

func Unmarshal

func Unmarshal(arg SassValue, v ...interface{}) error

Decode converts Sass Value to Go compatible data types.

func Version

func Version() string

Version reports libsass version information

Types

type Context

type Context struct {
	// Options
	OutputStyle  int
	Precision    int
	Comments     bool
	IncludePaths []string
	// Input directories
	FontDir  string
	ImageDir string
	// Output/build directories
	BuildDir  string
	GenImgDir string

	// HTTP supporting code
	HTTPPath                    string
	In, Src, Out, Map, MainFile string
	Status                      int //libsass status code

	// Place to keep cookies, so Go doesn't garbage collect them before C
	// is done with them
	Cookies []Cookie

	// Imports is a map of overridden imports. When Sass attempts to
	// import a path matching on in this map, it will include the import
	// found in the map before looking for a file on the system.
	Imports Imports
	// Headers are a map of strings to start any Sass project with. Any
	// header listed here will be present before any other Sass code is
	// compiled.
	Headers Headers

	// ResolvedImports is the list of files libsass used to compile this
	// Sass sheet.
	ResolvedImports []string

	// Attach additional data to a context for use by custom
	// handlers/mixins
	Payload interface{}
	// contains filtered or unexported fields
}

Context handles the interactions with libsass. Context exposes libsass options that are available.

func NewContext

func NewContext() *Context

func (*Context) Compile

func (ctx *Context) Compile(in io.Reader, out io.Writer) error

Compile reads in and writes the libsass compiled result to out. Options and custom functions are applied as specified in Context.

Example
in := bytes.NewBufferString(`div {
			  color: red(blue);
			  background: foo();
			}`)

var out bytes.Buffer
ctx := Context{
	//Customs: []string{"foo()"},
}
if ctx.Cookies == nil {
	ctx.Cookies = make([]Cookie, 1)
}
ctx.Cookies[0] = Cookie{
	Sign: "foo()",
	Fn: func(v interface{}, usv libs.UnionSassValue, rsv *libs.UnionSassValue) error {
		res, _ := Marshal("no-repeat")
		*rsv = res.Val()
		return nil
	},
	Ctx: &ctx,
}
err := ctx.Compile(in, &out)
if err != nil {
	panic(err)
}

fmt.Print(out.String())
Output:

func (*Context) Error

func (ctx *Context) Error() string

func (*Context) ErrorLine

func (ctx *Context) ErrorLine() int

ErrorLine attempts to resolve the file associated with a stdin:#

func (*Context) FileCompile

func (ctx *Context) FileCompile(path string, out io.Writer) error

func (*Context) Init

func (ctx *Context) Init(goopts libs.SassOptions) libs.SassOptions

Init validates options in the struct and returns a Sass Options.

func (*Context) ProcessSassError

func (ctx *Context) ProcessSassError(bs []byte) error

ProcessSassError reads the original libsass error and creates helpful debuggin information for debuggin that error.

func (*Context) RelativeImage

func (p *Context) RelativeImage() string

Rel creates relative paths between the build directory where the CSS lives and the image directory that is being linked. This is not compatible with generated images like sprites.

func (*Context) Reset

func (ctx *Context) Reset()

Reset returns removes all error state information.

func (*Context) SetFunc

func (ctx *Context) SetFunc(goopts libs.SassOptions)

SetFunc assigns the registered methods to SassOptions. Functions are called when the compiler encounters the registered signature.

func (*Context) SetHeaders

func (ctx *Context) SetHeaders(opts libs.SassOptions)

func (*Context) SetImporters

func (ctx *Context) SetImporters(opts libs.SassOptions)

SetImporters accepts a SassOptions and adds the registered importers in the context.

type Cookie struct {
	Sign string
	Fn   libs.SassCallback
	Ctx  interface{}
}

Cookie is used for passing context information to libsass. Cookie is passed to custom handlers when libsass executes them through the go bridge.

type HandlerFunc

type HandlerFunc func(v interface{}, req SassValue, res *SassValue) error

HandlerFunc describes the method signature for registering a Go function to be called by libsass.

type Header struct {
	Content string
}

type Headers

type Headers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Headers) Add

func (h *Headers) Add(s string)

func (*Headers) Has

func (h *Headers) Has(s string) bool

func (*Headers) Len

func (h *Headers) Len() int

type Import

type Import struct {
	Body io.ReadCloser

	Prev string
	Path string
	// contains filtered or unexported fields
}

Import contains Rel and Abs path and a string of the contents representing an import.

func (Import) ModTime

func (i Import) ModTime() time.Time

ModTime returns modification time

type Imports

type Imports struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Imports is a map with key of "path/to/file"

func (*Imports) Add

func (p *Imports) Add(prev string, path string, bs []byte) error

Add registers an import in the context.Imports

func (*Imports) Del

func (p *Imports) Del(path string)

Del removes the import from the context.Imports

func (*Imports) Get

func (p *Imports) Get(prev, path string) ([]byte, error)

Get retrieves import bytes by path

func (*Imports) Init

func (p *Imports) Init()

Init sets up a new Imports map

func (*Imports) Len

func (p *Imports) Len() int

Len counts the number of entries in context.Imports

func (*Imports) Update

func (p *Imports) Update(name string)

Update attempts to create a fresh Body from the given path Files last modified stamps are compared against import timestamp

type SassError

type SassError struct {
	Status, Line, Column int
	File, Message        string
}

SassError represents an error object returned from Sass. SassError stores useful information for bubbling up libsass errors.

type SassValue

type SassValue struct {
	// contains filtered or unexported fields
}

func Error

func Error(err error) SassValue

Error takes a Go error and returns a libsass Error

func Marshal

func Marshal(v interface{}) (SassValue, error)

func NewSassValue

func NewSassValue() SassValue

func Warn

func Warn(s string) SassValue

Warn takes a string and causes a warning in libsass

func (SassValue) Val

func (sv SassValue) Val() libs.UnionSassValue

Directories

Path Synopsis
libs is a direct mapping to libsass C API.
libs is a direct mapping to libsass C API.

Jump to

Keyboard shortcuts

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