Documentation ¶
Index ¶
- Constants
- Variables
- func FileHandler(gen string) http.Handler
- func FromBuildArgs(dst io.Writer, dstmap string, src io.Reader, gba *BuildArgs) (libsass.Compiler, error)
- func HTTPHandler(gba *BuildArgs, httpPath string) func(w http.ResponseWriter, r *http.Request)
- func Init(handle io.Writer)
- func IsSass(r io.Reader) bool
- func LoadAndBuild(path string, gba *BuildArgs, pMap *SafePartialMap) error
- func ToScssReader(r io.Reader) (io.ReadCloser, error)
- type Build
- type BuildArgs
- type Parser
- type Replace
- type Response
- type SafePartialMap
- type WatchOptions
- type Watcher
Examples ¶
Constants ¶
const MaxTopLevel int = 20
MaxTopLevel sets the default size of the slice holding the top level files for a sass partial in SafePartialMap.M
Variables ¶
var ( // Debug future ability to toggle the logging level and destination. Debug *log.Logger )
var ErrPartialMap = errors.New("No partial map found")
ErrPartialMap when no partial map is found
Functions ¶
func FileHandler ¶ added in v0.7.0
FileHandler starts a file server serving files out of the specified build directory.
func FromBuildArgs ¶ added in v1.0.0
func FromBuildArgs(dst io.Writer, dstmap string, src io.Reader, gba *BuildArgs) (libsass.Compiler, error)
FromBuildArgs creates a compiler from BuildArgs
func HTTPHandler ¶ added in v0.7.0
HTTPHandler starts a CORS enabled web server that takes as input Sass and outputs CSS.
func IsSass ¶ added in v0.7.0
IsSass determines if the given reader is Sass (not Scss). This is predicted by the presence of semicolons
func LoadAndBuild ¶
func LoadAndBuild(path string, gba *BuildArgs, pMap *SafePartialMap) error
LoadAndBuild kicks off parser and compiling. It expands directories to recursively locate Sass files TODO: make this function testable
func ToScssReader ¶ added in v0.7.0
func ToScssReader(r io.Reader) (io.ReadCloser, error)
ToScssReader ...
Types ¶
type Build ¶ added in v1.0.0
type Build struct {
// contains filtered or unexported fields
}
Build holds a set of read only arguments to the builder. Channels from this are used to communicate between the workers and loaders executing builds.
func NewBuild ¶ added in v1.0.0
func NewBuild(args *BuildArgs, pMap *SafePartialMap) *Build
NewBuild accepts arguments to reate a new Builder
Example ¶
ps := []string{"test/sass/file.scss"} args := &BuildArgs{} args.WithPaths(ps) b := NewBuild(args, NewPartialMap()) err := b.Run() if err != nil { log.Fatal(err) }
Output: div { color: black; }
type BuildArgs ¶
type BuildArgs struct { Payload context.Context ImageDir string // BuildDir is the base build directory used. When recursive // file matching is involved, this directory will be used as the // parent. BuildDir string Includes []string // Project is the source for Sass files and is searched // recursively for those files Project string Font string Gen string Style int Comments bool CacheBust string // emit source map files alongside css files SourceMap bool // indicates the working directory which wt is run in WorkDir string // contains filtered or unexported fields }
BuildArgs holds universal arguments for a build that the parser uses during the initial build and the filewatcher passes back to the parser on any file changes.
type Parser ¶
type Parser struct { Idx int Chop []Replace Pwd, Input, MainFile string SassDir, BuildDir, ProjDir string Imports libsass.Imports ImageDir string Includes []string Output []byte Line map[int]string LineKeys []int PartialMap *SafePartialMap // contains filtered or unexported fields }
Parser represents a parser engine that returns parsed and imported code from the input useful for doing text manipulation before passing to libsass.
type Response ¶ added in v0.7.0
type Response struct { Contents string `json:"contents"` Start time.Time `json:"start"` Elapsed string `json:"elapsed"` Error string `json:"error"` Version string `json:"version"` }
Response is the object returned on HTTP responses from wellington
type SafePartialMap ¶
SafePartialMap is a thread safe map of partial sass files to top level files. The file watcher will detect changes in a partial and kick off builds for all top level files that contain that partial.
func NewPartialMap ¶
func NewPartialMap() *SafePartialMap
NewPartialMap creates a initialized SafeParitalMap with with capacity 100
func (*SafePartialMap) Add ¶ added in v1.0.1
func (p *SafePartialMap) Add(key string, paths []string)
Add places a path in the partial map
func (*SafePartialMap) AddRelation ¶
func (p *SafePartialMap) AddRelation(mainfile string, subfile string)
AddRelation links a partial Sass file with the top level file by adding a thread safe entry into partialMap.M.
type WatchOptions ¶ added in v1.0.0
type WatchOptions struct { PartialMap *SafePartialMap Paths []string BArgs *BuildArgs }
WatchOptions containers the necessary parameters to run the file watcher
func NewWatchOptions ¶ added in v1.0.0
func NewWatchOptions() *WatchOptions
NewWatchOptions returns a new WatchOptions
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher holds all data needed to kick off a build of the css when a file changes. FileWatcher is the object that triggers builds when a file changes. PartialMap contains a mapping of partials to top level files. Dirs contains all directories that have top level files. GlobalBuildArgs contains build args that apply to all sass files.
func NewWatcher ¶
func NewWatcher(opts *WatchOptions) (*Watcher, error)
NewWatcher returns a new watcher pointer