libsass

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2015 License: MIT Imports: 15 Imported by: 0

README

libsass

Circle CI Build status

Libsass provides Go bindings for the speedy sass/libsass project.

To build, setup Go

go build

To test

go test
FAQ

Rebuilding libsass on each go compilation is very slow. Optionally, it is possible to link against a system installed libsass. To leverage a system installed libsass, use -tags dev.

go build -tags dev
go test -tags dev

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

Examples

Constants

View Source
const (
	NESTED_STYLE = iota
	EXPANDED_STYLE
	COMPACT_STYLE
	COMPRESSED_STYLE
)

Constants/enums for the output style.

Variables

View Source
var (
	ErrImportNotFound = errors.New("Import unreachable or not found")
)
View Source
var ErrNoCompile = errors.New("No compile has occurred")
View Source
var (
	ErrSassNumberNoUnit = errors.New("SassNumber has no units")
)
View Source
var Style map[string]int
View Source
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 Payload added in v1.0.0

func Payload(load interface{}) options

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 RegisterHeader

func RegisterHeader(body string)

RegisterHeader fifo

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.

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 SassValue, v ...interface{}) error

Decode converts Sass Value to Go compatible data types.

func Version

func Version() string

Version reports libsass version information

Types

type Compiler added in v1.0.0

type Compiler interface {
	Run() error
	Imports() []string
	Options(...options) error
}

func New added in v1.0.0

func New(dst io.Writer, src io.Reader, opts ...options) (Compiler, error)

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

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
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) Error added in v0.9.3

func (ctx *Context) Error() string

func (*Context) ErrorLine

func (ctx *Context) ErrorLine() int

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

func (*Context) FileCompile

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

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

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.

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

type Funcs struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewFuncs added in v1.0.0

func NewFuncs(ctx *Context) *Funcs

func (*Funcs) Add added in v1.0.0

func (fs *Funcs) Add(f Func)

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.

func (*Funcs) Close added in v1.0.0

func (fs *Funcs) Close()

type HandlerFunc added in v0.9.2

type HandlerFunc func(v interface{}, req SassValue, res *SassValue) error

HandlerFunc describes the method signature for registering a Go function to be called by libsass.

type Header struct {
	Content string
	// contains filtered or unexported fields
}

type Headers

type Headers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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) Add

func (h *Headers) Add(s string)

func (*Headers) Bind added in v1.0.0

func (hdrs *Headers) Bind(opts libs.SassOptions)

func (*Headers) Close added in v1.0.0

func (hdrs *Headers) Close()

func (*Headers) Has added in v0.9.2

func (h *Headers) Has(s string) bool

func (*Headers) Len

func (h *Headers) Len() int

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.

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 NewImports added in v1.0.0

func NewImports() *Imports

func (*Imports) Add

func (p *Imports) Add(prev string, path string, bs []byte) error

Add registers an import in the context.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.

func (*Imports) Close added in v1.0.0

func (i *Imports) Close()

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 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.

func (*Sass) Imports added in v1.0.0

func (c *Sass) Imports() []string

Imports returns the full list of partials used to build the output stylesheet.

func (*Sass) Options added in v1.0.1

func (c *Sass) Options(opts ...options) error

func (*Sass) Run added in v1.0.0

func (c *Sass) Run() error

Run starts transforming S[c|a]ss to CSS

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 SassValue added in v0.9.2

type SassValue struct {
	// contains filtered or unexported fields
}

func Error

func Error(err error) SassValue

Error takes a Go error and returns a libsass Error

func Marshal

func Marshal(v interface{}) (SassValue, error)

func NewSassValue added in v0.9.2

func NewSassValue() SassValue

func Warn

func Warn(s string) SassValue

Warn takes a string and causes a warning in libsass

func (SassValue) Val added in v0.9.2

func (sv SassValue) Val() libs.UnionSassValue

Directories

Path Synopsis
libs is a direct mapping to libsass C API.
libs is a direct mapping to libsass C API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL