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 NewCompilerContext(c Compiler) context.Context
- func RegisterHandler(sign string, callback HandlerFunc)
- func RegisterHeader(body string)
- func RegisterSassFunc(sign string, fn SassFunc)
- func SassHandler(h SassFunc) libs.SassCallback
- func ToScss(r io.Reader, w io.Writer) error
- func Unmarshal(arg SassValue, v ...interface{}) error
- func Version() string
- type Compiler
- type Func
- type FuncOpt
- func BasePath(basePath string) FuncOpt
- func BuildDir(path string) FuncOpt
- func CacheBust(t string) FuncOpt
- func Comments(b bool) FuncOpt
- func FontDir(path string) FuncOpt
- func HTTPPath(u string) FuncOpt
- func ImgBuildDir(path string) FuncOpt
- func ImgDir(path string) FuncOpt
- func ImportsOption(imports *Imports) FuncOpt
- func IncludePaths(includes []string) FuncOpt
- func LineComments(b bool) FuncOpt
- func OutputStyle(style int) FuncOpt
- func Path(path string) FuncOpt
- func Payload(load context.Context) FuncOpt
- func Precision(prec int) FuncOpt
- func SourceMap(b bool, path, sourceMapRoot string) FuncOpt
- func WithSyntax(mode Syntax) FuncOpt
- 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 Pather
- type ResolverCallback
- type SassError
- type SassFunc
- type SassValue
- type Syntax
Examples ¶
Constants ¶
const ( NESTED_STYLE = iota EXPANDED_STYLE COMPACT_STYLE COMPRESSED_STYLE )
Constants/enums for the output style.
Variables ¶
var ( ErrPayloadEmpty = errors.New("empty payload") ErrNoCompile = errors.New("No compile has occurred") )
var ErrCompilerNotFound = errors.New("compiler not found")
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 NewCompilerContext ¶
func RegisterHandler ¶
func RegisterHandler(sign string, callback HandlerFunc)
RegisterHandler sets the passed signature and callback to the handlers array.
func RegisterSassFunc ¶
RegisterSassFunc assigns the passed Func to the specified signature sign
func SassHandler ¶
func SassHandler(h SassFunc) libs.SassCallback
SassHandler contains callback context for running code within a libsass handler
Types ¶
type Compiler ¶
type Compiler interface {
// Run does a synchronous build via cgo. It is thread safe, but there is
// no guarantee that the cgo calls will always be that way.
Run() error
// Imports returns the imports used for a compile. This is built
// at parser time in libsass
Imports() []string
// Option allows the configuration of the compiler. The option is
// unexported to encourage use of preconfigured option functions.
Option(...FuncOpt) error
// CacheBust specifies the cache bust method used by the compiler
// Available options: ts, sum
CacheBust() string
// LineComments specifies whether line comments were inserted into
// output CSS
LineComments() bool
// Payload returns the attached spritewell information attached
// to the compiler context
Payload() context.Context
// Syntax represents the style of code Sass or SCSS
Syntax() Syntax
}
Compiler interface is used to translate input Sass network, filepath, or otherwise and transforms it to CSS. The interface includes methods for adding imports and specifying build options necessary to do the transformation.
Example (Stdin) ¶
src := bytes.NewBufferString(`div { p { color: red; } }`)
comp, err := New(os.Stdout, src)
if err != nil {
log.Fatal(err)
}
err = comp.Run()
if err != nil {
log.Fatal(err)
}
Output: div p { color: red; }
func CompFromCtx ¶
CompFromCtx retrieves a compiler from a passed context
type Func ¶
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 FuncOpt ¶
type FuncOpt func(*sass) error
FuncOpt enables configuration of compiler initialization
func BasePath ¶
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 HTTPPath ¶
HTTPPath prefixes all sprites and generated images with this uri. Enabling wellington to serve images when used in HTTP mode
func ImgBuildDir ¶
ImgBuildDir specifies the destination directory for images
func ImportsOption ¶
ImportsOption specifies configuration for import resolution
func IncludePaths ¶
IncludePaths adds additional directories to search for Sass files
func LineComments ¶
LineComments removes the line by line playby of the Sass compiler
func OutputStyle ¶
OutputStyle controls the presentation of the CSS available option: nested, expanded, compact, compressed
func Path ¶
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 Payload ¶
Payload gives access to sprite and image information for handlers to perform spriting functions.
func Precision ¶
Precision specifies the number of points beyond the decimal place is preserved during math calculations.
func SourceMap ¶
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.
func WithSyntax ¶
type Funcs ¶
func (*Funcs) Bind ¶
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 ¶
HandlerFunc describes the method signature for registering a Go function to be called by libsass.
type Headers ¶
func NewHeaders ¶
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 ¶
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 ¶
func NewImports() *Imports
func NewImportsWithAbsResolver ¶
func NewImportsWithAbsResolver(resolver libs.ImportResolver) *Imports
func NewImportsWithResolver ¶
func NewImportsWithResolver(resolver libs.ImportResolver) *Imports
func (*Imports) Bind ¶
func (p *Imports) Bind(opts libs.SassOptions)
Bind accepts a SassOptions and adds the registered importers in the context.
type Pather ¶
type Pather interface {
ImgDir() string
BuildDir() string
HTTPPath() string
ImgBuildDir() string
FontDir() string
}
Pather describes the file system paths necessary for a project
type ResolverCallback ¶
type ResolverCallback struct {
// contains filtered or unexported fields
}
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
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
customfunc
command
|
|
|
custompreamble
command
Create a preamble for every CSS file
|
Create a preamble for every CSS file |
|
options
command
|
|
|
libs is a direct mapping to libsass C API.
|
libs is a direct mapping to libsass C API. |