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 BasePath(basePath string) options
- func BuildDir(path string) options
- func Comments(b bool) options
- func FontDir(path string) options
- func HTTPPath(u string) options
- func Handler(h HandlerFunc) libs.SassCallback
- func ImgBuildDir(path string) options
- func ImgDir(path string) options
- func IncludePaths(includes []string) options
- func OutputStyle(style int) options
- func Path(path string) options
- func Payload(load interface{}) options
- func Precision(prec int) options
- func RegisterHandler(sign string, callback HandlerFunc)
- func RegisterHeader(body string)
- func SourceMap(b bool) options
- func ToScss(r io.Reader, w io.Writer) error
- func Unmarshal(arg SassValue, v ...interface{}) error
- func Version() string
- type Compiler
- 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()
- type Func
- type Funcs
- type HandlerFunc
- type Header
- type Headers
- type Import
- type Imports
- func (p *Imports) Add(prev string, path string, bs []byte) error
- func (p *Imports) Bind(opts libs.SassOptions)
- func (i *Imports) Close()
- func (p *Imports) Del(path string)
- func (p *Imports) Get(prev, path string) ([]byte, error)
- func (p *Imports) Init()
- func (p *Imports) Len() int
- func (p *Imports) Update(name string)
- type Sass
- 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 ErrNoCompile = errors.New("No compile has occurred")
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 BasePath ¶ added in v1.0.0
func BasePath(basePath string) options
BasePath sets the internal path provided to handlers requiring a base path for http calls. This is useful for hosted solutions that need to provided absolute paths to assets.
func BuildDir ¶ added in v1.0.0
func BuildDir(path string) options
BuildDir only used for spriting, how terrible!
func Comments ¶ added in v1.0.0
func Comments(b bool) options
Comments toggles whether comments should be included in the output
func FontDir ¶ added in v1.0.0
func FontDir(path string) options
FontDir specifies where to find fonts
func HTTPPath ¶ added in v1.0.1
func HTTPPath(u string) options
HTTPPath prefixes all sprites and generated images with this uri. Enabling wellington to serve images when used in HTTP mode
func Handler ¶ added in v0.9.2
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 ImgBuildDir ¶ added in v1.0.0
func ImgBuildDir(path string) options
ImgBuildDir specifies where to place images
func ImgDir ¶ added in v1.0.0
func ImgDir(path string) options
ImgDir specifies where to locate images for spriting
func IncludePaths ¶ added in v1.0.0
func IncludePaths(includes []string) options
IncludePaths adds additional directories to search for Sass files
func OutputStyle ¶ added in v1.0.0
func OutputStyle(style int) options
func Path ¶ added in v1.0.0
func Path(path string) options
Path specifies a file to read instead of using the provided io.Reader. This activates file compiling that includes line numbers in the resulting output.
func Precision ¶ added in v1.0.0
func Precision(prec int) options
Precision specifies the number of points beyond the decimal place is preserved during math calculations.
func RegisterHandler ¶
func RegisterHandler(sign string, callback HandlerFunc)
RegisterHandler sets the passed signature and callback to the handlers array.
func SourceMap ¶ added in v1.0.0
func SourceMap(b bool) options
SourceMap behaves differently depending on compiler used. For compile, it will embed sourcemap into the source. For file compile, it will include a separate file with the source map.
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 // Funcs is a slice of Sass function handlers. Registry these globally // by calling RegisterHandler Funcs *Funcs // 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(); }`) ctx := NewContext() ctx.Funcs.Add(Func{ 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, os.Stdout) if err != nil { log.Fatal(err) }
Output: div { color: 0; background: no-repeat; }
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.
type Func ¶ added in v1.0.0
type Func 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 Funcs ¶ added in v1.0.0
func (*Funcs) Bind ¶ added in v1.0.0
func (fs *Funcs) Bind(goopts libs.SassOptions)
SetFunc assigns the registered methods to SassOptions. Functions are called when the compiler encounters the registered signature.
type HandlerFunc ¶ added in v0.9.2
HandlerFunc describes the method signature for registering a Go function to be called by libsass.
type Headers ¶
func NewHeaders ¶ added in v1.0.0
func NewHeaders() *Headers
NewHeaders instantiates a Headers for prefixing Sass to input See: https://github.com/sass/libsass/wiki/API-Sass-Importer
func (*Headers) Bind ¶ added in v1.0.0
func (hdrs *Headers) Bind(opts libs.SassOptions)
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"
func NewImports ¶ added in v1.0.0
func NewImports() *Imports
func (*Imports) Bind ¶ added in v1.0.0
func (p *Imports) Bind(opts libs.SassOptions)
Bind accepts a SassOptions and adds the registered importers in the context.
type Sass ¶ added in v1.0.0
type Sass struct {
// contains filtered or unexported fields
}
Sass implements compiler interface for Sass and Scss stylesheets. To configure the compiler, use the options method.
type SassError ¶
SassError represents an error object returned from Sass. SassError stores useful information for bubbling up libsass errors.
type SassValue ¶ added in v0.9.2
type SassValue struct {
// contains filtered or unexported fields
}
func NewSassValue ¶ added in v0.9.2
func NewSassValue() SassValue
func (SassValue) Val ¶ added in v0.9.2
func (sv SassValue) Val() libs.UnionSassValue