libsass

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 5 Imported by: 10

Documentation

Overview

Package libsass a SCSS transpiler to CSS using LibSASS.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Status  int    `json:"status"`
	Column  int    `json:"column"`
	File    string `json:"file"`
	Line    int    `json:"line"`
	Message string `json:"message"`
}

func (Error) Error

func (e Error) Error() string

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

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

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

Jump to

Keyboard shortcuts

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