Documentation
¶
Index ¶
- func WithDebug() func(c *Compiler) error
- func WithDefaultCSSRefiners() func(c *Compiler) error
- func WithDefaultImageRefiners() func(c *Compiler) error
- func WithDefaultOptions() func(c *Compiler) error
- func WithInclude(paths ...string) func(c *Compiler) error
- func WithLogger(l *log.Logger) func(c *Compiler) error
- func WithParallelTasks(max int) func(c *Compiler) error
- func WithRefiners(refiners ...Refiner) func(c *Compiler) error
- type Compiler
- type Iterator
- type IteratorFunc
- type RefineJavascript
- type RefineMinify
- type RefineRaster
- type RefineSASS
- type RefineSCSS
- type RefineText
- type Refiner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithDefaultCSSRefiners ¶
WithDefaultCSSRefiners sets up SASS and SCSS compilers and a CSS minifier.
func WithDefaultImageRefiners ¶
WithDefaultImageRefiners sets up refiners for SVG, JPEG, PNG, and Webp images.
func WithDefaultOptions ¶
WithDefaultOptions configures standard compiler behavior.
func WithInclude ¶
WithInclude adds an additional path to look for includes, when neccessary.
func WithLogger ¶
WithLogger overrides the default Compiler logger.
func WithParallelTasks ¶
WithParallelTasks sets the maximum number of simultaneous refiners. Higher number speeds up the compilation but consumes more resources. Default value is 50.
func WithRefiners ¶
WithRefiners links refiners to the compiler. They will run in the order added for each file.
Types ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler packs resources for distribution.
func NewCompiler ¶
NewCompiler creates a configured compiler.
type Iterator ¶
Iterator returns a walking function through paths pointing to files and folders.
func NewIterator ¶
NewIterator sets up an Iterator. If the Ignore list is empty, fills it with default values.
func (*Iterator) AllowPath ¶
AllowPath returns true, if the path does not match any of the Ignore patterns.
func (*Iterator) Walk ¶
func (i *Iterator) Walk(f IteratorFunc) error
Walk calls the IteratorFunc for every discovered object.
type IteratorFunc ¶
IteratorFunc is run on every Iterator cycle. First returned error stops the Iterator.
type RefineJavascript ¶
type RefineJavascript struct {
// contains filtered or unexported fields
}
RefineJavascript compiles a Javascript file to ESNext.
func (*RefineJavascript) Debug ¶
func (rf *RefineJavascript) Debug(destination, source string) error
Debug preserves the comments and keeps Javascript readable.
func (*RefineJavascript) Match ¶
func (rf *RefineJavascript) Match(p string) bool
Match returns true if pattern fits the file path.
func (*RefineJavascript) Refine ¶
func (rf *RefineJavascript) Refine(destination, source string) error
Refine runs the compilation and minification.
type RefineMinify ¶
type RefineMinify struct { MatchPath *regexp.Regexp Minifier minify.MinifierFunc // contains filtered or unexported fields }
RefineMinify interfaces with the popular Minifier library.
func (*RefineMinify) Match ¶
func (rf *RefineMinify) Match(p string) bool
Match returns true if pattern fits the file path.
func (*RefineMinify) Refine ¶
func (rf *RefineMinify) Refine(destination, source string) error
Refine applies a minifier to source and writes the result to destination.
type RefineRaster ¶
type RefineRaster struct { MatchPath *regexp.Regexp Encode func(io.Writer, image.Image) error Decode func(io.Reader) (image.Image, error) // contains filtered or unexported fields }
RefineRaster provides basic image compression.
func (*RefineRaster) Match ¶
func (rf *RefineRaster) Match(p string) bool
Match returns true if pattern fits the file path.
func (*RefineRaster) Refine ¶
func (rf *RefineRaster) Refine(destination, source string) error
Refine scales the image and reduces its quality for web distribution.
type RefineSASS ¶
type RefineSASS struct {
RefineSCSS
}
RefineSASS compiles SASS files to minified CSS.
func (*RefineSASS) Debug ¶
func (rf *RefineSASS) Debug(destination, source string) error
Debug leaves comments, keeps track of source, and preserves readability of the resulting CSS.
func (*RefineSASS) Match ¶
func (rf *RefineSASS) Match(p string) bool
Match returns true if pattern fits the file path.
func (*RefineSASS) Refine ¶
func (rf *RefineSASS) Refine(destination, source string) error
Refine process SASS source into a minified CSS file.
type RefineSCSS ¶
type RefineSCSS struct {
Paths []string
}
RefineSCSS compiles SCSS files to minified CSS.
func (*RefineSCSS) Debug ¶
func (rf *RefineSCSS) Debug(destination, source string) error
Debug leaves comments, keeps track of source, and preserves readability of the resulting CSS.
func (*RefineSCSS) Match ¶
func (rf *RefineSCSS) Match(p string) bool
Match returns true if pattern fits the file path.
func (*RefineSCSS) Refine ¶
func (rf *RefineSCSS) Refine(destination, source string) error
Refine process SASS source into a minified CSS file.
func (*RefineSCSS) Rename ¶
func (rf *RefineSCSS) Rename(p string) string
Rename switches a SASS asset to a CSS asset.
type RefineText ¶
type RefineText struct { MatchPath *regexp.Regexp Search *regexp.Regexp Replace string // contains filtered or unexported fields }
RefineText searches and replaces snippets in text files. Handy for simple file manipulations.
func (*RefineText) Match ¶
func (rf *RefineText) Match(p string) bool
Match returns true if pattern fits the file path.
func (*RefineText) Refine ¶
func (rf *RefineText) Refine(destination, source string) error
Refine writes the contents of source to destination while replacing certain text snippets.
type Refiner ¶
type Refiner interface { // Match will activate the refiner on matching paths. Match(path string) (ok bool) // Some refiners transform one asset into another, like SASS => CSS. Rename(oldPath string) (newPath string) // Change the content from source to destination. Refine(destination, source string) error // Same as Refine, but keep the changed files as readable as possible. Debug(destination, source string) error }
Refiner converts one type of asset into another or optimizes the content.