stages

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package stages implements the three stages for processing Booklit documents:

The first stage is Evaluate, which interprets a node to generate content while calling plugin functions.

The second stage is Collect, which traverses all content and sets tags defined by Targets.

The third and final stage is Resolve, which traverses all content and resolves References to their tags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collect

type Collect struct {
	Section *booklit.Section
}

Collect is a booklit.Visitor that collects all tag targets and sets them on the section.

func (*Collect) VisitDefinitions added in v0.6.0

func (collect *Collect) VisitDefinitions(con booklit.Definitions) error

VisitDefinitions visits each subject and definition.

func (*Collect) VisitImage added in v0.6.0

func (collect *Collect) VisitImage(con booklit.Image) error

VisitImage does nothing.

func (collect *Collect) VisitLink(con booklit.Link) error

VisitLink visits the link's content.

func (*Collect) VisitList

func (collect *Collect) VisitList(con booklit.List) error

VisitList visits each item in the list.

func (*Collect) VisitParagraph

func (collect *Collect) VisitParagraph(con booklit.Paragraph) error

VisitParagraph visits each line.

func (*Collect) VisitPreformatted

func (collect *Collect) VisitPreformatted(con booklit.Preformatted) error

VisitPreformatted visits each line.

func (*Collect) VisitReference

func (collect *Collect) VisitReference(con *booklit.Reference) error

VisitReference does nothing.

func (*Collect) VisitSection

func (collect *Collect) VisitSection(con *booklit.Section) error

VisitSection visits the section's title, body, and partials, followed by each child section which is visited with their own *Collect.

func (*Collect) VisitSequence

func (collect *Collect) VisitSequence(con booklit.Sequence) error

VisitSequence visits each content in the sequence.

func (*Collect) VisitString

func (collect *Collect) VisitString(booklit.String) error

VisitString does nothing.

func (*Collect) VisitStyled

func (collect *Collect) VisitStyled(con booklit.Styled) error

VisitStyled visits the content and partials.

func (*Collect) VisitTable added in v0.6.0

func (collect *Collect) VisitTable(con booklit.Table) error

VisitTable visits each table cell.

func (*Collect) VisitTableOfContents

func (collect *Collect) VisitTableOfContents(booklit.TableOfContents) error

VisitTableOfContents does nothing.

func (*Collect) VisitTarget

func (collect *Collect) VisitTarget(con booklit.Target) error

VisitTarget sets an anchored tag on the Section.

type Evaluate

type Evaluate struct {
	// The section which acts as the evaluation context. The section's plugins
	// are used for evaluating Invoke nodes.
	Section *booklit.Section

	// The evaluated content after calling (ast.Node).Visit.
	Result booklit.Content
}

Evaluate is an ast.Visitor that builds up the booklit.Content for a given section.

func (*Evaluate) VisitInvoke

func (eval *Evaluate) VisitInvoke(invoke ast.Invoke) error

VisitInvoke uses reflection to evaluate the corresponding method on the section's plugins, trying them in order.

If no method is found, booklit.UndefinedFunctionError is returned.

If the method's arity does not match the Invoke's arguments, an error is returned.

The method must return either no value, a booklit.Content, an error, or (booklit.Content, error). Other return types will result in an error.

If a PrettyError is returned, it is returned without wrapping.

If an error is returned, it is wrapped in a booklit.FailedFunctionError.

If a booklit.Content is returned, it will be appended to Result.

func (*Evaluate) VisitParagraph

func (eval *Evaluate) VisitParagraph(node ast.Paragraph) error

VisitParagraph visits each line in the paragraph and builds up a booklit.Paragraph containing each evaluated line.

Any lines which evaluate to a nil result are skipped, i.e. a Invoke which performed side effects and returned nothing. If the paragraph is empty as a result, the Result is unaffected.

If the Result contains a single non-flow content, it is unwrapped and appended to the Result.

Otherwise, i.e. a normal paragraph of flow content, the paragraph is appended to the Result.

func (*Evaluate) VisitPreformatted

func (eval *Evaluate) VisitPreformatted(node ast.Preformatted) error

VisitPreformatted behaves similarly to VisitParagraph, but with no special-case for block content, and it appends a booklit.Preformatted instead.

func (*Evaluate) VisitSequence

func (eval *Evaluate) VisitSequence(seq ast.Sequence) error

VisitSequence visits each node within the sequence.

func (*Evaluate) VisitString

func (eval *Evaluate) VisitString(str ast.String) error

VisitString appends the string's text to the result using booklit.Append.

type Resolve

type Resolve struct {
	AllowBrokenReferences bool

	Section *booklit.Section
}

Resolve is a booklit.Visitor that locates the target tag for each booklit.Reference.

func (*Resolve) VisitDefinitions added in v0.6.0

func (resolve *Resolve) VisitDefinitions(con booklit.Definitions) error

VisitDefinitions visits each subject and definition.

func (*Resolve) VisitImage added in v0.6.0

func (resolve *Resolve) VisitImage(con booklit.Image) error

VisitImage does nothing.

func (resolve *Resolve) VisitLink(con booklit.Link) error

VisitLink visits the link's content.

func (*Resolve) VisitList

func (resolve *Resolve) VisitList(con booklit.List) error

VisitList visits each item in the list.

func (*Resolve) VisitParagraph

func (resolve *Resolve) VisitParagraph(con booklit.Paragraph) error

VisitParagraph visits each line.

func (*Resolve) VisitPreformatted

func (resolve *Resolve) VisitPreformatted(con booklit.Preformatted) error

VisitPreformatted visits each line.

func (*Resolve) VisitReference

func (resolve *Resolve) VisitReference(con *booklit.Reference) error

VisitReference finds the referenced tag through Section.FindTag.

If 1 tag is found, it is assigned on the Reference.

If 0 tags are found and AllowBrokenReferences is false, booklit.UnknownTagError is returned.

If more than one tag is returned and AllowBrokenReferences is false, booklit.AmbiguousReferenceError is returned.

If AllowBrokenReferences is true, a made-up tag is assigned on the Reference instead of returning either of the above errors.

func (*Resolve) VisitSection

func (resolve *Resolve) VisitSection(con *booklit.Section) error

VisitSection visits the section's title, body, and partials, followed by each child section which is visited with their own *Resolve.

func (*Resolve) VisitSequence

func (resolve *Resolve) VisitSequence(con booklit.Sequence) error

VisitSequence visits each content in the sequence.

func (*Resolve) VisitString

func (resolve *Resolve) VisitString(booklit.String) error

VisitString does nothing.

func (*Resolve) VisitStyled

func (resolve *Resolve) VisitStyled(con booklit.Styled) error

VisitStyled visits the content and partials.

func (*Resolve) VisitTable added in v0.6.0

func (resolve *Resolve) VisitTable(con booklit.Table) error

VisitTable visits each table cell.

func (*Resolve) VisitTableOfContents

func (resolve *Resolve) VisitTableOfContents(booklit.TableOfContents) error

VisitTableOfContents does nothing.

func (*Resolve) VisitTarget

func (resolve *Resolve) VisitTarget(con booklit.Target) error

VisitTarget visits the target's title and content.

Jump to

Keyboard shortcuts

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