package libsass

import "github.com/bep/golibsass/libsass"

Package libsass a SCSS transpiler to CSS using LibSASS.

Index

Examples

Types

type Options

type Options struct {
	// Default is nested.
	OutputStyle OutputStyle

	// Precision of floating point math.
	Precision int

	// File paths to use to resolve imports.
	IncludePaths []string

	// ImportResolver can be used to supply a custom import resolver, both to redirect
	// to another URL or to return the body.
	ImportResolver func(url string, prev string) (newURL string, body string, resolved bool)

	// Used to indicate "old style" SASS for the input stream.
	SassSyntax bool

	SourceMapOptions SourceMapOptions
}

type OutputStyle

type OutputStyle int
const (
	NestedStyle OutputStyle = iota
	ExpandedStyle
	CompactStyle
	CompressedStyle
)

func ParseOutputStyle

func ParseOutputStyle(s string) OutputStyle

ParseOutputStyle will convert s into OutputStyle. Case insensitive, returns NestedStyle for unknown values.

type Result

type Result struct {
	CSS string

	// If source maps are configured.
	SourceMapFilename string
	SourceMapContent  string
}

type SourceMapOptions

type SourceMapOptions struct {
	Filename       string
	Root           string
	InputPath      string
	OutputPath     string
	Contents       bool
	OmitURL        bool
	EnableEmbedded bool
}

type Transpiler

type Transpiler interface {
	Execute(src string) (Result, error)
}
Example

Code:play 

package main

import (
	"fmt"
	"log"

	"github.com/bep/golibsass/libsass"
)

func main() {
	transpiler, err := libsass.New(libsass.Options{OutputStyle: libsass.CompressedStyle})
	if err != nil {
		log.Fatal(err)
	}

	result, err := transpiler.Execute(`
$font-stack:    Helvetica, sans-serif;
$primary-color: #333;

body {
  font: 100% $font-stack;
  color: $primary-color;
}
`)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.CSS)
}

Output:

body{font:100% Helvetica,sans-serif;color:#333}

func New

func New(options Options) (Transpiler, error)

New creates a new libsass transpiler configured with the given options.

Source Files

transpiler.go

Directories

PathSynopsis
libsass/libsasserrorsPackage libsasserrors holds the error types used by the libsass package.
Version
v1.2.0 (latest)
Published
Aug 28, 2024
Platform
linux/amd64
Imports
4 packages
Last checked
2 weeks ago

Tools for package owners.