format

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package format contains various formatting tools wrapped around text/template

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyFormat Is returned when the format is empty
	ErrEmptyFormat = errors.New("format: cannot compile an empty format")
)
View Source
var UtilFuncs = template.FuncMap{
	"zwsp":     util.AddZwsp,
	"wordEOL":  util.WordEol,
	"escape":   util.EscapeString,
	"stripAll": util.StripAll,
	"eat":      func(...interface{}) string { return "" },
}

UtilFuncs is a standard set of functions added to all Format's template.Template

Functions

This section is empty.

Types

type Format

type Format struct {
	FormatString   string             `xml:",chardata"` // The original format string
	CompiledFormat *template.Template `xml:"-"`         // Our internal template
	// contains filtered or unexported fields
}

Format represents a wrapped template.Template

func (*Format) Compile

func (f *Format) Compile(name string, root *template.Template, funcMaps ...template.FuncMap) error

Compile compiles the given format string into a text.template, evaluating IRC colours if requested, and adding the default functions plus any passed to the template. If the template is invalid or the format has already been compiled, Compile errors. An optional root text/template can be passed, and if so, the compiled format's internal template will be associated with the passed root

func (*Format) Execute

func (f *Format) Execute(data interface{}) (string, error)

Execute runs a compiled Format and returns the resulting string

func (*Format) ExecuteBytes

func (f *Format) ExecuteBytes(data interface{}) ([]byte, error)

ExecuteBytes is like Execute but returns a slice of bytes

type Storage

type Storage struct {
	sync.RWMutex // Lets not have lists explode
	// contains filtered or unexported fields
}

Storage holds data for cross-execution storage

func (*Storage) Delete

func (s *Storage) Delete(name string) string

Delete deletes an entry from the Storage, It will not error if the entry does not exist

func (*Storage) GetBool

func (s *Storage) GetBool(name string, def bool) bool

GetBool returns either the bool stored at `testName` or a default

func (*Storage) GetInt

func (s *Storage) GetInt(name string, def int) int

GetInt returns either the int stored at `testName` or a default

func (*Storage) GetString

func (s *Storage) GetString(name, def string) string

GetString returns either the string stored at `testName` or a default

func (*Storage) SetBool

func (s *Storage) SetBool(name string, data bool) bool

SetBool sets the bool at `testName` to `data`

func (*Storage) SetInt

func (s *Storage) SetInt(name string, i int) int

SetInt sets the int at `testName` to `data`

func (*Storage) SetString

func (s *Storage) SetString(name, data string) string

SetString sets the string at `testName` to `data`

Directories

Path Synopsis
Package transformer implements a platform agnostic way of converting between platform specific formatting styles In order to do this, an intermediate format is used internally and by all implementations of Transformer The format is defined as follows Formatters are first indicated with a sentinel, '$', after which a single character for type follows The only defined types are: b Bold i Italics u Underline s Strikethrough r Reset $ Escaped Sentinel c Colour Colour has a special definition, instead of simply $c, the sentinel and type is followed by six hex characters that together indicate a colour.
Package transformer implements a platform agnostic way of converting between platform specific formatting styles In order to do this, an intermediate format is used internally and by all implementations of Transformer The format is defined as follows Formatters are first indicated with a sentinel, '$', after which a single character for type follows The only defined types are: b Bold i Italics u Underline s Strikethrough r Reset $ Escaped Sentinel c Colour Colour has a special definition, instead of simply $c, the sentinel and type is followed by six hex characters that together indicate a colour.
minecraft
Package minecraft contains a Transformer implementation for the JSON specification of minecraft format strings see https://minecraft.gamepedia.com/Raw_JSON_text_format for a full look at the format itself
Package minecraft contains a Transformer implementation for the JSON specification of minecraft format strings see https://minecraft.gamepedia.com/Raw_JSON_text_format for a full look at the format itself
simple
Package simple implements a Transformer that supports basic replacement based transformations
Package simple implements a Transformer that supports basic replacement based transformations
tokeniser
Package tokeniser implements a tokeniser for the format/transformer intermediate language
Package tokeniser implements a tokeniser for the format/transformer intermediate language

Jump to

Keyboard shortcuts

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