vugu: github.com/vugu/vugu/vugufmt Index | Files

package vugufmt

import "github.com/vugu/vugu/vugufmt"

Package vugufmt provides gofmt-like functionality for vugu files.

Index

Package Files

diff.go doc.go fmterror.go formatter.go gofmt.go goimports.go tokenstack.go

func UseGoFmt Uses

func UseGoFmt(simplifyAST bool) func(*Formatter)

UseGoFmt sets the formatter to use gofmt on x-go blocks. Set simplifyAST to true to simplify the AST. This is false by default for gofmt, and is the same as passing in -s for it.

func UseGoImports Uses

func UseGoImports(f *Formatter)

UseGoImports sets the formatter to use goimports on x-go blocks.

type FmtError Uses

type FmtError struct {
    Msg      string
    FileName string
    Line     int
    Column   int
}

FmtError is a formatting error.

func (FmtError) Error Uses

func (e FmtError) Error() string

type Formatter Uses

type Formatter struct {
    // ScriptFormatters maps script blocks to formatting
    // functions.
    // For each type of script block,
    // we can run it through the supplied function.
    // If the function returns error, we should
    // not accept the output written to the writer.
    // You can add your own custom one for JS, for
    // example. If you want to use gofmt or goimports,
    // see how to apply options in NewFormatter.
    ScriptFormatters map[string]func([]byte) ([]byte, *FmtError)
    // StyleFormatter handles CSS blocks.
    StyleFormatter func([]byte) ([]byte, *FmtError)
}

Formatter allows you to format vugu files.

func NewFormatter Uses

func NewFormatter(opts ...func(*Formatter)) *Formatter

NewFormatter creates a new formatter. Pass in vugufmt.UseGoFmt to use gofmt. Pass in vugufmt.UseGoImports to use goimports.

func (*Formatter) Diff Uses

func (f *Formatter) Diff(filename string, input io.Reader, output io.Writer) (bool, error)

Diff will show differences between input and what Format() would do. It will return (true, nil) if there is a difference, (false, nil) if there is no difference, and (*, notnil) when the difference can't be determined. filename is optional, but helps with generating useful output.

func (*Formatter) FormatHTML Uses

func (f *Formatter) FormatHTML(filename string, in io.Reader, out io.Writer) *FmtError

FormatHTML formats script and css nodes.

func (*Formatter) FormatScript Uses

func (f *Formatter) FormatScript(scriptType string, scriptContent []byte) ([]byte, *FmtError)

FormatScript formats script text nodes.

func (*Formatter) FormatStyle Uses

func (f *Formatter) FormatStyle(styleContent []byte) ([]byte, *FmtError)

FormatStyle formats script text nodes.

Package vugufmt imports 13 packages (graph) and is imported by 1 packages. Updated 2019-04-12. Refresh now. Tools for package owners.