Documentation ¶
Overview ¶
Package linejoin implements a write filter (linejoin.Writer) that joins lines ending with a continuation token.
It was designed to be used with templates, to allow a more natural template layout that does not add too much whitespace to the output.
Example (Buffer) ¶
package main import ( "bitbucket.org/edmccard/linejoin" "bytes" "io" "os" "text/template" ) // This example demonstrates using line-joining by preprocessing a template // through a buffer. const example2 = `{{/*Example*/ \}} {{template "Foo" \}} {{template "Bar" \}} {{define "Foo" \}} Only two lines {{end \}} {{define "Bar" \}} of text. {{end \}} ` func main() { b := new(bytes.Buffer) filter := linejoin.NewWriter(b, ` \}}`, "}}") io.WriteString(filter, example2) t := template.Must(template.New("Example").Parse(b.String())) t.Execute(os.Stdout, nil) }
Output: Only two lines of text.
Example (Template) ¶
package main import ( "bitbucket.org/edmccard/linejoin" "os" "text/template" ) // This example demonstrates using line-joining directly from a template, // by executing the template to a linejoin.Writer. const example = `## {{template "Foo"}}## {{template "Bar"}}## {{define "Foo"}}## Only two lines {{end}}## {{define "Bar"}}## of text. {{end}}## ` func main() { t := template.Must(template.New("Example").Parse(example)) // Create the filter. filter := linejoin.NewWriter(os.Stdout, "##", "") t.Execute(filter, nil) }
Output: Only two lines of text.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer is a filter that joins lines, by deleting any newlines which follow a given continuation token.
The Writer buffers input internally, so clients should call Flush after the last call to Write.
func NewWriter ¶
NewWriter returns a new linejoin.Writer.
output the filter output token the continuation token subst the replacement token
Click to show internal directories.
Click to hide internal directories.