api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serialize

func Serialize(docs *Documentation) (string, error)

Serialize is ...

func SortNodesByName added in v0.1.0

func SortNodesByName(node *Node)

SortNodesByName recursively sorts all child nodes in the node hierarchy by node Name

Types

type ContentSelector

type ContentSelector struct {
	// URI of a document
	Source string `yaml:"source,omitempty"`
	// Optional filtering expression that selects content from the document content
	// Omiting this file will select the whole document content.
	Selector *string `yaml:"selector,omitempty"`
}

ContentSelector specifies a document node content target

type Documentation

type Documentation struct {
	// Root is the root node of this documentation structure
	Root *Node `yaml:"root"`
	// Variables are a set of key-value entries, where the key is the variable name
	// and the value is a node template. Nodes defined as variables can be resused
	// by reference throughout the documentation structure to minimise duplicate
	// node definitions. A reference to a variable is in the format `$variable-name`,
	// where `varaible-name` is a key in this Variables map structure.
	//
	// Note: WiP - proposed, not implemented yet.
	Variables map[string]*Node `yaml:"variables,omitempty"`
	// LocalityDomain defines the scope of the downloadable resources
	// for this structure
	LocalityDomain *LocalityDomain `yaml:"localityDomain,omitempty"`
}

Documentation is a documentation structure that can be serialized and deserialized and parsed into a model supporting the tasks around building a concrete documentaiton bundle.

func Parse

func Parse(b []byte) (*Documentation, error)

Parse is ...

type LinkSubstitute added in v0.2.0

type LinkSubstitute struct {
	Text        *string `yaml:"text,omitempty"`
	Destination *string `yaml:"destination,omitempty"`
	Title       *string `yaml:"title,omitempty"`
}

LinkSubstitute comprises subtitutes for various link details commonly found in markup

type LinkSubstitutes added in v0.2.0

type LinkSubstitutes map[string]*LinkSubstitute

LinkSubstitutes is the mapping between absolute links and substitutions for them

type LinksMatchers added in v0.2.0

type LinksMatchers struct {
	// Include is a list of regular expressions that will be matched to every
	// link that is candidate for download to determine whether it is
	// eligible. The links to match are absolute.
	// Include can be used in conjunction with Exclude when it is easier/
	// preferable to deny all resources and allow selectively.
	// Include can be used in conjunction with localityDomain to add
	// additional resources not in the domain.
	Include []string `yaml:"include,omitempty"`
	// Exclude is a list of regular expression that will be matched to every
	// link that is candidate for download to determine whether it is
	// not eligible. The links to match are absolute.
	// Use Exclude to further constrain the set of downloaded resources
	// that are in a locality domain.
	Exclude []string `yaml:"exclude,omitempty"`
}

LinksMatchers defines links exclusion/inclusion patterns

type LocalityDomain

type LocalityDomain struct {
	LocalityDomainMap `yaml:",inline"`
	// DownloadSubstitutes is an optional map of resource names in this
	// locality domain and their substitutions. Use it to override the
	// default downloads naming:
	// - An exact download name mapped to a download resource will be used
	//   to name that resources when downloaded.
	// - An expression with substitution variables can be used
	//   to change the default pattern for generating donwloaded resouce
	//   names, which is $uuid.
	//   The supported variables are:
	//   - $name: the original name of the resouce
	//   - $path: the original path of the resource in this domain (may be empty)
	//   - $uuid: the identifier generated f=or the downloaded resource
	//   - $ext:  the extension of the original resource (may be "")
	//   Example expression: $name-$uuid
	DownloadSubstitutes map[string]string `yaml:"downloadSubstitutes,omitempty"`
}

LocalityDomain contains the entries defining a locality domain scope. Each entry is a mapping between a domain, such as github.com/gardener/gardener, and a path in it that defines "local" resources. Documents referenced by documentation node structure are always part of the locality domain. Other resources referenced by those documents are checked against the path hierarchy of locality domain entries to determine how they will be processed.

type LocalityDomainMap added in v0.2.0

type LocalityDomainMap map[string]*LocalityDomainValue

LocalityDomainMap maps domains such as github.com/gardener/gardener to LocalityDomainValues

type LocalityDomainValue

type LocalityDomainValue struct {
	// Version sets the version of the resources that will
	// be referenced in this domain. Download targets and
	// absolute links in documents referenced by the structure
	// will be rewritten to match this version
	Version string `yaml:"version"`
	// Path is the relative path inside a domain that contains
	// resources considered 'local' that will be downloaded.
	Path          string `yaml:"path"`
	LinksMatchers `yaml:",inline"`
}

LocalityDomainValue encapsulates the memebers of a LocalityDomain entry value

type Node

type Node struct {

	// Name is the name of this node. If omited, the name is the resource name from
	// Source as reported by an eligible ResourceHandler's Name() method.
	// Node with multiple Source entries require name.
	Name string `yaml:"name,omitempty"`
	// A reference to the parent of this node, unless it is the root. Unexported and
	// assigned internally when the node structure is resolved. Not marshalled.
	// Title is the title for a node displayed to human users
	Title string `yaml:"title,omitempty"`
	// Source is a sequence of path specifications to locate the resources
	// that represent this document node. There must be at minimum one. When
	// they are multiple, the resulting document is an aggregation of the
	// material located at each path.
	//
	// A source path specification entries are in the following format:
	// `path[#{semantic-block-selector}]`, where:
	// - `path` is a valid resource locator for a document.
	// - `semantic-block-selector`is an expression that selects semantic block
	//   elements from the document similiar to CSS selectors (Note: WiP - proposed,
	//	 not implemented yet.).
	//
	// Examples:
	// - A single file
	//   `source: ["path/a/b/c/file.md"]`
	//
	// - Two files in order to construct a new document
	//   `source: ["path1/a/b/c/file1.md",
	//             "path2/e/f/g/file2.md"]`
	//
	// - A file and the section under the first heading level 1 from another file
	//   in that order to construct a new document.
	//   Note: WiP - proposed, not implemented yet.
	//   `source: ["path1/a/b/c/file1.md",
	//             "path2/e/f/g/file2.md#{h1:first-of-type}"]`
	ContentSelectors []ContentSelector `yaml:"contentSelectors,omitempty"`
	// Nodes is an array of nodes that are subnodes (children) of this node
	//
	// Note: For a non-strict alternative for specifying child nodes, refer to
	//       `NodesSelector`
	Nodes []*Node `yaml:"nodes,omitempty"`
	// NodesSelector is a structure modeling an existing structure of documents at a
	// location that can be further filtered by their metadata propertis and set as
	// child nodes to this node. This is an alternative to explicitly setting child
	// nodes structure resource paths with `Nodes`.
	// Note: WiP - proposed, not implemented yet.
	NodeSelector *NodeSelector `yaml:"nodesSelector,omitempty"`
	// Properties are a map of arbitary, key-value pairs to model custom,
	// untyped node properties. They could be used to instruct specific ResourceHandlers
	// and the serialization of the Node. For example the properyies member could be
	// used to set the front-matter to markdowns for front-matter aware builders such
	// as Hugo.
	Properties map[string]interface{} `yaml:"properties,omitempty"`

	*LocalityDomain `yaml:"localityDomain,omitempty"`

	// LinksSubstitutes is an optional map of links and their
	// substitutions. Use it to override the default handling of those
	// links in documents referenced by this node's contentSelector:
	// - An empty substitution string ("") removes a link markdown.
	//   It leaves only its text component in the document for links
	//   and nothing for images.
	//   This applies only to markdown for links and images.
	// - A fixed string that will replace the whole original link
	//   destination.
	// The keys in the substitution map are matched against documents
	// links as exact string matches. The document links are converted to
	// their absolute form for the match
	// TODO: update this doc
	LinksSubstitutes LinkSubstitutes `yaml:"linksSubstitutes,omitempty"`
	// contains filtered or unexported fields
}

Node is a recursive, tree data structure representing documentation model.

func FindNodeByContentSource

func FindNodeByContentSource(nodeContentSource string, node *Node) *Node

FindNodeByContentSource traverses up and then all around the tree paths in the node's documentation strcuture, looking for a node that has contentSource path nodeContentSource

func (*Node) AddStats added in v0.3.0

func (n *Node) AddStats(s ...*Stat)

AddStats appends Stats

func (*Node) GetRootNode

func (n *Node) GetRootNode() *Node

GetRootNode returns the root node in the parents path for a node object n

func (*Node) GetStats added in v0.3.0

func (n *Node) GetStats() []*Stat

GetStats returns statistics for this node

func (*Node) Parent

func (n *Node) Parent() *Node

Parent returns the parent node (if any) of this node n

func (*Node) Parents

func (n *Node) Parents() []*Node

Parents returns the path of nodes from this nodes parent to the root of the hierarchy

func (*Node) Peers added in v0.1.0

func (n *Node) Peers() []*Node

Peers returns the peer nodes of the node

func (*Node) RelativePath

func (n *Node) RelativePath(to *Node) string

RelativePath returns the relative path between two nodes on the same tree, formatted with `..` for ancestors path if any and `.` for current node in relative path to descendant. The function can also calculate path to a node on another branch

func (*Node) SetParent

func (n *Node) SetParent(node *Node)

SetParent returns the parent node (if any) of this node n

func (*Node) SetParentsDownwards

func (n *Node) SetParentsDownwards()

SetParentsDownwards walks recursively the hierarchy under this node to set the parent property.

type NodeSelector

type NodeSelector struct {
	// Path is a resource locator to a set of files, i.e. to a resource container.
	Path string `yaml:"path"`
	// Depth a maximum depth of the recursion. If omitted or less than 0, the
	// constraint is not considered
	Depth int64 `yaml:"depth,omitempty"`
	// Annotation is an optional expression, filtering documents located at `Path`
	// by their metadata properties. Markdown metadata is commonly provisioned as
	// `front-matter` block at the head of the document delimited by comment
	// tags (`---`).
	Annotation string `yaml:"annotation,omitempty"`
}

NodeSelector is an specification for selecting subnodes (children) for a node. The order in which the documents are selected is not guaranteed. The interpreters of NodeSelectors can make use of the resource metadata or other sources to construct and populate child Nodes dynamically.

Example:

  • Select all documents located at path/a/b/c that have front-matter property `type` with value `faq`: ``` nodesSelector: { path: "path/a/b/c", annotation: "type:faq" } ``` will select markdown documents located at path/a/b/c with front-matter: --- type: faq ---

Note: WiP - proposed, not implemented yet.

type Stat added in v0.3.0

type Stat struct {
	Title   string
	Figures string
	Details []string
}

Stat represents a category recorded by StatsRecorder

Jump to

Keyboard shortcuts

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