Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyExpandHandlers(line string, handlers ...ExpandHandler) string
- func ExpandConfigFromJSONFile(file string) (map[string]string, map[string]string, error)
- func ExpandConfigJSON(r io.Reader) (map[string]string, map[string]string, error)
- func ExpandParseTex(r io.Reader) ([]string, []string, []string, error)
- func IntMin(a, b int) int
- func Join(replace LatexEscapeFunc) func(sep string, args ...interface{}) string
- func LatexEscaper(replace LatexEscapeFunc) func(args ...interface{}) string
- func LatexTemplate(t *template.Template, replace LatexEscapeFunc) *template.Template
- func MergeStringMaps(m1, m2 map[string]string) map[string]string
- func ParseTemplates(replace LatexEscapeFunc, delimLeft, delimRight string, filenames ...string) (*template.Template, error)
- func ParseVarValList(pairs []string) (map[string]string, error)
- func ParseVarValPair(s string) (string, string, error)
- func TemplateConstFromJSONFile(file string) (map[string]string, error)
- func TemplateConstJSON(r io.Reader) (map[string]string, error)
- func Verb(del string, args ...interface{}) (string, error)
- func WriteExpandHandlers(w io.Writer, line string, handlers ...ExpandHandler) (int, error)
- type CSVReader
- type ColKeyError
- type Collection
- type CollectionSource
- type Column
- type ConstHandler
- type ExpandHandler
- type LatexEscapeFunc
- type MemoryCollection
- type RowHandler
Constants ¶
const ( // NoColEntry is returned by several methods of Column to indicate that a // key was not found. NoColEntry = "NO VALUE" )
Variables ¶
var ( // DefaultReplacers describes the default replacer pairs. Note that certain // replacements like \textbackslash must have a leading space. DefaultReplacers = []string{ "&", `\&`, "%", `\%`, "$", `\$`, "#", `\#`, "_", `\_`, "{", `\{`, "}", `\}`, "~", `\textasciitilde `, "^", `\textasciicircum `, `\`, `\textbackslash `, } )
Functions ¶
func ApplyExpandHandlers ¶
func ApplyExpandHandlers(line string, handlers ...ExpandHandler) string
ApplyExpandHandlers applies the handlers one after the other to the original line.
func ExpandConfigFromJSONFile ¶
ExpandConfigFromJSONFile is like ExpandConfigJSON and reads the content from a file.
func ExpandConfigJSON ¶
ExpandConfigJSON parses a config file. The config files must be a dictionary mapping "const" to a dictionary of string variable / value pairs and mapping "rows" to a dictionary of string variable / value pairs.
func ExpandParseTex ¶
ExpandParseTex splits the tex file into the three parts: Head, everything before the line "%begin gummibaum repeat", body everything between "%begin gummibaum repeat" and "%end gummibaum repeat" and foot everything after "%end gummibaum repeat".
func Join ¶
func Join(replace LatexEscapeFunc) func(sep string, args ...interface{}) string
Join concatenates the elements of args to create a single string. The separator string sep is placed between elements in the resulting string. The function parameterized by a LatexEscapeFunc (that can be nil) that is used to prepare each arg.
func LatexEscaper ¶
func LatexEscaper(replace LatexEscapeFunc) func(args ...interface{}) string
LatexEscaper returns a function that escapes an arbitrary number of arguments with the specified escaping function.
func LatexTemplate ¶
func LatexTemplate(t *template.Template, replace LatexEscapeFunc) *template.Template
LatexTemplate adds the functions "latex", "verb", and "join" to the template. This function must be called before the template is parsed.
func MergeStringMaps ¶
MergeStringMaps combines two string maps. The result is a new map (both maps are unchanged) containing all entries from m1 and m2. If a key is present in both maps the value from m2 is used.
func ParseTemplates ¶
func ParseTemplates(replace LatexEscapeFunc, delimLeft, delimRight string, filenames ...string) (*template.Template, error)
ParseTemplates parses the templates specified by filenames. See Go template documentation for ParseTemplates for details. The functions "latex", "verb" and "join" are added. The replace function is used to escape special characters, if it is nil no replacement takes place. Delims defines which delimiters are used. The default {{ and }} are not nice for latex, so we replace them. #( and #) seem to be a good idea. This is what happens when you use the empty string as delims.
func ParseVarValList ¶
ParseVarValList parses a list of var=val pairs (each entry in pairs one such pair). The vars are mapped to the value. For syntax errors an error != nil is returned.
func ParseVarValPair ¶
ParseVarValPair parses a string of the form var=val. It returns var and val. For syntax errors an error != nil is returned.
func TemplateConstFromJSONFile ¶
TemplateConstFromJSONFile is like TemplateConstJSON and reads the content from a file.
func TemplateConstJSON ¶
TemplateConstJSON parses a constant json file, it must be a dictionary mapping strings (replace identifiers) by constant values.
func Verb ¶
Verb returns a LaTeX verb environment with the given delimiter. For example Verb("|", "foo & bar") yields to \verb|foo & bar|. An error is returned if the delimiter is contained in the input string or if delimiter has a length != 1.
func WriteExpandHandlers ¶
WriteExpandHandlers works as ApplyExpandHandlers but writes the result to a writer. It returns the number of bytes written and any error that occurred.
Types ¶
type CSVReader ¶
CSVReader implements CollectionSource by reading content as csv.
func NewCSVFileReader ¶
NewCSVFileReader returns a new csv reader given a file path.
func NewCSVReader ¶
NewCSVReader returns a new csv reader given the reader source and the separator (usually comma). If head is true the first column is assumed to be the head column and must be present.
This function exhaustively reads all data from the reader in memory.
type ColKeyError ¶ added in v1.2.0
type ColKeyError struct {
Message string
}
ColKeyError is an error returned by several methods of Column to indicate that a ky was not found.
func NewColKeyError ¶ added in v1.2.0
func NewColKeyError(msgTemplate string, a ...interface{}) ColKeyError
NewColKeyError returns a new ColKeyError.
func (ColKeyError) Error ¶ added in v1.2.0
func (err ColKeyError) Error() string
type Collection ¶
Collection groups together several columns with the same head (row names).
func NewCollection ¶
func NewCollection(source CollectionSource) (*Collection, error)
NewCollection returns a new Collection initialized with all entries from the source.
It returns any error from source.
type CollectionSource ¶
CollectionSource is everything that returns entries in the form of a column based data model.
Head describes the row names and can be nil in which case no names are given. Entries returns all columns.
For example Head might return ["first-name", "last-name"] and Entries might return [["John", "Doe"], ["Jane"]]. The second column does not have a field "last-name".
type Column ¶
Column represents a column in a collection. It has the head of the entries (that comes from the collection and all data entries as strings). Map is a mapping from head name (row names) to the data entry and is created in NewColumn.
Head and Entries should have the same size, but are allowed to have different sizes. In this case the map contains an entry for each row name in min(len(Head), mint(Entries)).
func (*Column) At ¶
At returns the i-th entry. If i is not a valid position in entries an error of type ColKeyError is returned. GetPos is similar to At but does not return an error.
func (*Column) Element ¶
Element returns either the element on position key if key is an int or the mapping at key if key is a string. If it is neither an of type ColKeyError error is returned. If the position / key is invalid an error of type ColKeyError is returned. Get is similar to Element but does not return an error if key is invalid.
func (*Column) Get ¶
Get returns either the element on position key if key is an int or the mapping at key if key is a string. If it is neither NoColEntry is returned. If the position / key is invalid NoColEntry is returned. Element is similar to Get but returns an error if key is invalid.
func (*Column) GetKey ¶
GetKey returns the item with the given key where key is row name. If the key is not found NoColEntry is returned. Value is similar to GetKey but returns an error if key is not found.
type ConstHandler ¶
type ConstHandler struct {
// contains filtered or unexported fields
}
ConstHandler replaces place holders with constant values.
func NewConstHandler ¶
func NewConstHandler(mapper map[string]string, replaceFunc LatexEscapeFunc) *ConstHandler
NewConstHandler returns a new ConstHandler give the mapping place holder to constant value (for example "NAME" mapped to "John"). replaceFunc is a function to escape LaTeX special characters. If it is nil no replacements will take place.
func (*ConstHandler) HandleLine ¶
func (h *ConstHandler) HandleLine(line string) string
type ExpandHandler ¶
ExpandHandler is used for the expand mode to process a single line. A handler transforms a line and returns the new line.
type LatexEscapeFunc ¶
LatexEscapeFunc is any function that replaces LaTeX special character within a text. Usually it should be clear how to do this, but LaTeX is a very rich language and I want to keep it extendable.
func EscapeWithDefaults ¶
func EscapeWithDefaults(additional []string) LatexEscapeFunc
EscapeWithDefaults returns an escape function that uses the content from DefaultReplacers and combines it with the replacers from additional. Example: ["&", "\\&"] would replace each occurrence of & with \&. This replacement is already done by the DefaultReplacers though.
func LatexEscapeFromList ¶
func LatexEscapeFromList(mapping []string) LatexEscapeFunc
LatexEscapeFromList returns a replacement function given a map of substitution pairs. Example: ["&", "\\&"] would replace each occurrence of & with \&. A list of default replacers can be found in DefaultReplacers, EscapeWithDefaults can be used to extend that list.
type MemoryCollection ¶
MemoryCollection implements CollectionSource with a predefined set of content.
func NewMemoryCollection ¶
func NewMemoryCollection(head []string, columns [][]string) *MemoryCollection
NewMemoryCollection returns a new MemoryCollection given the data.
func (*MemoryCollection) Entries ¶
func (c *MemoryCollection) Entries() ([][]string, error)
Entries returns all columns.
func (*MemoryCollection) Head ¶
func (c *MemoryCollection) Head() ([]string, error)
Head returns the head.
type RowHandler ¶
type RowHandler struct {
// contains filtered or unexported fields
}
RowHandler replaces placeholders with values from a given column. It is not save for concurrent use with different columns, use WithColumn to create new RewHandlers with a new column and then run replacement on those instances concurrently. WithColumn must be called before using HandleLine.
func NewRowHandler ¶
func NewRowHandler(replaceVarMap map[string]string, replaceFunc LatexEscapeFunc) *RowHandler
NewRowHandler returns a new RowHandler. replaceVarMap must be a mapping mapping replace names to row names, for example "REPL-TOKEN" --> "token". WithColumn must be called before HandleLine can be used.
func (*RowHandler) HandleLine ¶
func (h *RowHandler) HandleLine(line string) string
HandleLine applies the actual replacement by substituting values for the current column. If the current column is nil this method panics, a column must be set before with WithColumn.
func (*RowHandler) WithColumn ¶
func (h *RowHandler) WithColumn(c *Column) *RowHandler
WithColumn returns a new row handler with the column set.