go-libsass – github.com/wellington/go-libsass Index | Examples | Files

package context

import "github.com/wellington/go-libsass"

Package context provides access to libsass

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

Index

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 MaxSizeT = C.max_size

MaxSizeT is safe way of specifying size_t = -1

var Style map[string]int

Functions

func GetImportList

func GetImportList(cctx *C.struct_Sass_Context) []string

func HeaderBridge

func HeaderBridge(ptr unsafe.Pointer) C.Sass_Import_List

HeaderBridge is called by libsass to find available custom headers

func ImporterBridge

func ImporterBridge(url *C.char, prev *C.char, ptr unsafe.Pointer) C.Sass_Import_List

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

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

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

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

Code:

{
	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

func (ctx *Context) ErrorLine() int

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

func (*Context) FileCompile

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

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

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(opts *C.struct_Sass_Options)

func (*Context) SetHeaders

func (ctx *Context) SetHeaders(opts *C.struct_Sass_Options)

func (*Context) SetImporter

func (ctx *Context) SetImporter(opts *C.struct_Sass_Options)

SetImporter enables custom importer in libsass

func (*Context) SetIncludePaths

func (c *Context) SetIncludePaths(opts *C.struct_Sass_Options)
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 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) Len

func (h *Headers) Len() int

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

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, cur 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 SassCallback

type SassCallback func(ctx *Context, csv UnionSassValue) UnionSassValue

SassCallback defines the callback libsass eventually executes in sprite_sass

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 SassImport

type SassImport C.struct_Sass_Import

SassImport wraps Sass_Import libsass struct

type SassNumber

type SassNumber struct {
	Value float64
	Unit  string
}

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.