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 ¶
- type Collect
- func (collect *Collect) VisitDefinitions(con booklit.Definitions) error
- func (collect *Collect) VisitImage(con booklit.Image) error
- func (collect *Collect) VisitLink(con booklit.Link) error
- func (collect *Collect) VisitList(con booklit.List) error
- func (collect *Collect) VisitParagraph(con booklit.Paragraph) error
- func (collect *Collect) VisitPreformatted(con booklit.Preformatted) error
- func (collect *Collect) VisitReference(con *booklit.Reference) error
- func (collect *Collect) VisitSection(con *booklit.Section) error
- func (collect *Collect) VisitSequence(con booklit.Sequence) error
- func (collect *Collect) VisitString(booklit.String) error
- func (collect *Collect) VisitStyled(con booklit.Styled) error
- func (collect *Collect) VisitTable(con booklit.Table) error
- func (collect *Collect) VisitTableOfContents(booklit.TableOfContents) error
- func (collect *Collect) VisitTarget(con booklit.Target) error
- type Evaluate
- func (eval *Evaluate) VisitInvoke(invoke ast.Invoke) error
- func (eval *Evaluate) VisitParagraph(node ast.Paragraph) error
- func (eval *Evaluate) VisitPreformatted(node ast.Preformatted) error
- func (eval *Evaluate) VisitSequence(seq ast.Sequence) error
- func (eval *Evaluate) VisitString(str ast.String) error
- type Resolve
- func (resolve *Resolve) VisitDefinitions(con booklit.Definitions) error
- func (resolve *Resolve) VisitImage(con booklit.Image) error
- func (resolve *Resolve) VisitLink(con booklit.Link) error
- func (resolve *Resolve) VisitList(con booklit.List) error
- func (resolve *Resolve) VisitParagraph(con booklit.Paragraph) error
- func (resolve *Resolve) VisitPreformatted(con booklit.Preformatted) error
- func (resolve *Resolve) VisitReference(con *booklit.Reference) error
- func (resolve *Resolve) VisitSection(con *booklit.Section) error
- func (resolve *Resolve) VisitSequence(con booklit.Sequence) error
- func (resolve *Resolve) VisitString(booklit.String) error
- func (resolve *Resolve) VisitStyled(con booklit.Styled) error
- func (resolve *Resolve) VisitTable(con booklit.Table) error
- func (resolve *Resolve) VisitTableOfContents(booklit.TableOfContents) error
- func (resolve *Resolve) VisitTarget(con booklit.Target) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collect ¶
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
VisitImage does nothing.
func (*Collect) VisitParagraph ¶
VisitParagraph visits each line.
func (*Collect) VisitPreformatted ¶
func (collect *Collect) VisitPreformatted(con booklit.Preformatted) error
VisitPreformatted visits each line.
func (*Collect) VisitReference ¶
VisitReference does nothing.
func (*Collect) VisitSection ¶
VisitSection visits the section's title, body, and partials, followed by each child section which is visited with their own *Collect.
func (*Collect) VisitSequence ¶
VisitSequence visits each content in the sequence.
func (*Collect) VisitString ¶
VisitString does nothing.
func (*Collect) VisitStyled ¶
VisitStyled visits the content and partials.
func (*Collect) VisitTable ¶ added in v0.6.0
VisitTable visits each table cell.
func (*Collect) VisitTableOfContents ¶
func (collect *Collect) VisitTableOfContents(booklit.TableOfContents) error
VisitTableOfContents does nothing.
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 ¶
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 ¶
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 ¶
VisitSequence visits each node within the sequence.
type Resolve ¶
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
VisitImage does nothing.
func (*Resolve) VisitParagraph ¶
VisitParagraph visits each line.
func (*Resolve) VisitPreformatted ¶
func (resolve *Resolve) VisitPreformatted(con booklit.Preformatted) error
VisitPreformatted visits each line.
func (*Resolve) VisitReference ¶
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 ¶
VisitSection visits the section's title, body, and partials, followed by each child section which is visited with their own *Resolve.
func (*Resolve) VisitSequence ¶
VisitSequence visits each content in the sequence.
func (*Resolve) VisitString ¶
VisitString does nothing.
func (*Resolve) VisitStyled ¶
VisitStyled visits the content and partials.
func (*Resolve) VisitTable ¶ added in v0.6.0
VisitTable visits each table cell.
func (*Resolve) VisitTableOfContents ¶
func (resolve *Resolve) VisitTableOfContents(booklit.TableOfContents) error
VisitTableOfContents does nothing.