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 ¶
- Constants
- Variables
- func Handler(h HandlerFunc) libs.SassCallback
- func Mixins(ctx *Context)
- func RegisterHandler(sign string, callback HandlerFunc)
- func RegisterHeader(body string)
- func ToScss(r io.Reader, w io.Writer) error
- func Unmarshal(arg SassValue, v ...interface{}) error
- func Version() string
- type Context
- func (ctx *Context) Compile(in io.Reader, out io.Writer) error
- func (ctx *Context) Error() string
- func (ctx *Context) ErrorLine() int
- func (ctx *Context) FileCompile(path string, out io.Writer) error
- func (ctx *Context) Init(goopts libs.SassOptions) libs.SassOptions
- func (ctx *Context) ProcessSassError(bs []byte) error
- func (p *Context) RelativeImage() string
- func (ctx *Context) Reset()
- func (ctx *Context) SetFunc(goopts libs.SassOptions)
- func (ctx *Context) SetHeaders(opts libs.SassOptions)
- func (ctx *Context) SetImporters(opts libs.SassOptions)
- type Cookie
- type HandlerFunc
- type Header
- type Headers
- type Import
- type Imports
- type SassError
- type SassValue
Examples ¶
Constants ¶
const ( NESTED_STYLE = iota EXPANDED_STYLE COMPACT_STYLE COMPRESSED_STYLE )
Constants/enums for the output style.
Variables ¶
var (
ErrImportNotFound = errors.New("Import unreachable or not found")
)
var (
ErrSassNumberNoUnit = errors.New("SassNumber has no units")
)
var Style map[string]int
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 RegisterHandler ¶
func RegisterHandler(sign string, callback HandlerFunc)
RegisterHandler sets the passed signature and callback to the handlers array.
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 ¶
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) Init ¶
func (ctx *Context) Init(goopts libs.SassOptions) libs.SassOptions
Init validates options in the struct and returns a Sass Options.
func (*Context) ProcessSassError ¶
ProcessSassError reads the original libsass error and creates helpful debuggin information for debuggin that error.
func (*Context) RelativeImage ¶
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 ¶
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 ¶
HandlerFunc describes the method signature for registering a Go function to be called by libsass.
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.
type Imports ¶
Imports is a map with key of "path/to/file"
type SassError ¶
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 NewSassValue ¶
func NewSassValue() SassValue
func (SassValue) Val ¶
func (sv SassValue) Val() libs.UnionSassValue