package context
import "github.com/wellington/go-libsass"
Package context provides access to libsass
For more info, see https://github.com/sass/libsass
Index ¶
- Constants
- Variables
- func GetImportList(cctx *C.struct_Sass_Context) []string
- func HeaderBridge(ptr unsafe.Pointer) C.Sass_Import_List
- func ImporterBridge(url *C.char, prev *C.char, ptr unsafe.Pointer) C.Sass_Import_List
- func Mixins(ctx *Context)
- func RegisterHandler(sign string, callback func(ctx *Context, csv UnionSassValue) UnionSassValue)
- func RegisterHeader(body string)
- func ToScss(r io.Reader, w io.Writer) error
- func Unmarshal(arg UnionSassValue, v ...interface{}) error
- func Version() string
- type Context
- func NewContext() *Context
- func (ctx *Context) Compile(in io.Reader, out io.Writer) error
- func (ctx *Context) ErrorLine() int
- func (c *Context) FileCompile(path string, out io.Writer) error
- func (ctx *Context) Init(goopts *SassOptions) *C.struct_Sass_Options
- func (ctx *Context) ProcessSassError(bs []byte) error
- func (p *Context) RelativeImage() string
- func (ctx *Context) Reset()
- func (ctx *Context) SetFunc(opts *C.struct_Sass_Options)
- func (ctx *Context) SetHeaders(opts *C.struct_Sass_Options)
- func (ctx *Context) SetImporter(opts *C.struct_Sass_Options)
- func (c *Context) SetIncludePaths(opts *C.struct_Sass_Options)
- type Cookie
- type Header
- type Headers
- type Import
- type Imports
- func (p *Imports) Add(prev string, cur string, bs []byte) error
- 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 SassCallback
- type SassError
- type SassImport
- type SassNumber
- func (sn SassNumber) Add(sn2 SassNumber) SassNumber
- func (sn SassNumber) Divide(sn2 SassNumber) SassNumber
- func (sn SassNumber) Multiply(sn2 SassNumber) SassNumber
- func (sn SassNumber) Subtract(sn2 SassNumber) SassNumber
- type SassOptions
- type UnionSassValue
- func Error(err error) UnionSassValue
- func GoBridge(cargs UnionSassValue, ptr unsafe.Pointer) UnionSassValue
- func Marshal(v interface{}) (UnionSassValue, error)
- func SampleCB(ctx *Context, usv UnionSassValue) UnionSassValue
- func Warn(s string) UnionSassValue
- func WarnHandler(ctx *Context, csv UnionSassValue) UnionSassValue
Examples ¶
Constants ¶
const ( NESTED_STYLE = iota EXPANDED_STYLE COMPACT_STYLE COMPRESSED_STYLE )
Constants/enums for the output style.
Variables ¶
var MaxSizeT = C.max_size
MaxSizeT is safe way of specifying size_t = -1
Functions ¶
func GetImportList ¶
func HeaderBridge ¶
HeaderBridge is called by libsass to find available custom headers
func ImporterBridge ¶
ImporterBridge is called by C to pass Importer arguments into Go land. A Sass_Import is returned for libsass to resolve.
func Mixins ¶
func Mixins(ctx *Context)
Mixins registers the default list of supported mixins
func RegisterHandler ¶
func RegisterHandler(sign string, callback func(ctx *Context, csv UnionSassValue) UnionSassValue)
RegisterHandler sets the passed signature and callback to the handlers array.
func RegisterHeader ¶
func RegisterHeader(body string)
RegisterHeader fifo
func ToScss ¶
ToScss converts Sass to Scss with libsass sass2scss.h
func Unmarshal ¶
func Unmarshal(arg UnionSassValue, 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 { //Parser Parser OutputStyle int Precision int Comments bool IncludePaths []string // Input directories FontDir, ImageDir string // Output/build directories BuildDir, GenImgDir string // HTTP supporting code HTTPPath string In, Src, Out, Map, MainFile string Status int Errors SassError // Place to keep cookies, so Go doesn't garbage collect them before C // is done with them Cookies []Cookie // Imports has the list of Import files currently present // in the calling context Imports Imports Headers Headers // Has list of compiler included files ResolvedImports []string // Used for callbacks to retrieve sprite information, etc. Imgs, Sprites spritewell.SafeImageMap // 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.
Code:
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{
"foo()", func(c *Context, usv UnionSassValue) UnionSassValue {
res, _ := Marshal("no-repeat")
return res
}, &ctx,
}
err := ctx.Compile(in, &out)
if err != nil {
panic(err)
}
fmt.Print(out.String())
// // Output:
// div {
// color: 0;
// background: no-repeat; }
}
func (*Context) ErrorLine ¶
ErrorLine attempts to resolve the file associated with a stdin:#
func (*Context) FileCompile ¶
func (*Context) Init ¶
func (ctx *Context) Init(goopts *SassOptions) *C.struct_Sass_Options
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 (*Context) SetHeaders ¶
func (*Context) SetImporter ¶
SetImporter enables custom importer in libsass
func (*Context) SetIncludePaths ¶
type Cookie ¶
type Cookie struct { Sign string Fn SassCallback Ctx *Context }
Cookie is used for passing context information to libsass. Cookie is passed to custom handlers when libsass executes them through the go bridge.
type Header ¶
type Header struct { Content string }
type Headers ¶
func (*Headers) Add ¶
func (*Headers) Len ¶
type Import ¶
type Import struct { Body io.ReadCloser // contains filtered or unexported fields }
Import contains Rel and Abs path and a string of the contents representing an import.
func (Import) ModTime ¶
ModTime returns modification time
type Imports ¶
Imports is a map with key of "path/to/file"
func (*Imports) Add ¶
Add registers an import in the context.Imports
func (*Imports) Del ¶
Del removes the import from the context.Imports
func (*Imports) Get ¶
Get retrieves import bytes by path
func (*Imports) Init ¶
func (p *Imports) Init()
Init sets up a new Imports map
func (*Imports) Len ¶
Len counts the number of entries in context.Imports
func (*Imports) Update ¶
Update attempts to create a fresh Body from the given path Files last modified stamps are compared against import timestamp
type SassCallback ¶
type SassCallback func(ctx *Context, csv UnionSassValue) UnionSassValue
SassCallback defines the callback libsass eventually executes in sprite_sass
type SassError ¶
SassError represents an error object returned from Sass. SassError stores useful information for bubbling up libsass errors.
type SassImport ¶
type SassImport C.struct_Sass_Import
SassImport wraps Sass_Import libsass struct
type SassNumber ¶
SassNumber represents numbers with units coming from libsass
func (SassNumber) Add ¶
func (sn SassNumber) Add(sn2 SassNumber) SassNumber
Add sums the two numbers in the first numbers units
func (SassNumber) Divide ¶
func (sn SassNumber) Divide(sn2 SassNumber) SassNumber
Divide takes the quotient of the two numbers in the first unit
func (SassNumber) Multiply ¶
func (sn SassNumber) Multiply(sn2 SassNumber) SassNumber
Multiply takes the multiplication of the two numbers in the first numbers units
func (SassNumber) Subtract ¶
func (sn SassNumber) Subtract(sn2 SassNumber) SassNumber
Subtract minuses the two numbers in the first numbers units
type SassOptions ¶
type SassOptions C.struct_Sass_Options
func NewSassOptions ¶
func NewSassOptions() *SassOptions
type UnionSassValue ¶
type UnionSassValue *C.union_Sass_Value
func Error ¶
func Error(err error) UnionSassValue
Error takes a Go error and returns a libsass Error
func GoBridge ¶
func GoBridge(cargs UnionSassValue, ptr unsafe.Pointer) UnionSassValue
GoBridge is exported to C for linking libsass to Go. This function adheres to the interface provided by libsass.
func Marshal ¶
func Marshal(v interface{}) (UnionSassValue, error)
func SampleCB ¶
func SampleCB(ctx *Context, usv UnionSassValue) UnionSassValue
SampleCB example how a callback is defined
func Warn ¶
func Warn(s string) UnionSassValue
Warn takes a string and causes a warning in libsass
func WarnHandler ¶
func WarnHandler(ctx *Context, csv UnionSassValue) UnionSassValue
WarnHandler captures Sass warnings and redirects to stdout
Source Files ¶
context.go doc.go encoding.go error.go export.go func.go header.go importer.go mixins.go sass_number.go toscss.go version.go
- Version
- v0.9.0
- Published
- Jun 22, 2015
- Platform
- js/wasm
- Imports
- 19 packages
- Last checked
- 19 hours ago –
Tools for package owners.