dossier

package
v0.0.0-...-8b058bf Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	// Metadata about the Document
	FrontMatter FrontMatter
	// The text of the Document in markdown
	Body string
}

A Document is sourced from markdown either embedded in the binary or available via another filesystem.

func FilterByCategory

func FilterByCategory(category string, documents []Document) (filteredDocs []Document)

FilterByCategory returns a slice of Documents which have the specified category.

func FilterByTag

func FilterByTag(tag string, documents []Document) (filteredDocs []Document)

FilterByTag returns a slice of Documents which have the specified tag.

type Dossier

type Dossier struct {
	// The handler for interacting with a filesystem - local, remote, or otherwise.
	AFS *afero.Afero
	// The handler for interacting with documents embedded in the binary itself
	EFS *embed.FS
	// The handler for writing documents to the terminal with style
	TerminalRenderer *glamour.TermRenderer
	// The handler for parsing a markdown document with frontmatter
	MarkdownHandler *front.Matter
	// The cache of parsed documents in the Dossier
	Documents []Document
}

A Dossier contains everything needed to display documentation in the terminal

func (*Dossier) CacheDocuments

func (dossier *Dossier) CacheDocuments(docsFolderPath string)

CacheEmbeddedDocuments searches the Dossier's embedded file system at the specified folder path, parsing all discovered markdown documents and caching them in the Dossier.

func (*Dossier) CompleteShortTitle

func (dossier *Dossier) CompleteShortTitle(match string) (titles []string)

CompleteShortTitle returns the list of short titles which are a valid match for the specified string as a prefix.

func (*Dossier) FormatFrontMatter

func (dossier *Dossier) FormatFrontMatter(format string, docs []Document)

FormatFrontMatter returns either the string representation of the JSON object containing the specified frontmatter or the rendered markdown table representation of the frontmatter to the caller but does not print either itself.

func (*Dossier) InitalizeTerminalRenderer

func (dossier *Dossier) InitalizeTerminalRenderer() (err error)

InitializeTerminalRenderer creates the terminal renderer if it does not already exist and defines how it should behave.

func (*Dossier) InitializeMarkdownHandler

func (dossier *Dossier) InitializeMarkdownHandler()

InitializeMarkdownHandler creates the handler for markdown documents if it does not already exist and defines how it should behave.

func (*Dossier) ListCategories

func (dossier *Dossier) ListCategories(docs []Document) (categories []string)

ListCategories returns a slice of strings containing all of the unique categories used by the Documents in the Dossier's cache.

func (*Dossier) ListTags

func (dossier *Dossier) ListTags(docs []Document) (tags []string)

ListTags returns a slice of strings containing all of the unique tags used by the Documents in the Dossier's cache.

func (*Dossier) ListTitles

func (dossier *Dossier) ListTitles(docs []Document) (titles []Title)

ListTitles returns a slice of Titles (the short and long names) from every Document in the Dossier's cache.

func (*Dossier) Render

func (dossier *Dossier) Render(body string) (output string, err error)

Render initializes the terminal renderer if needed and then uses it to render the body of a markdown document, returning the rendered string for printing to the screen but not printing it itself.

func (*Dossier) RenderDocument

func (dossier *Dossier) RenderDocument(doc Document) (string, error)

RenderDocument returns the terminal-rendered markdown of the specified document but does not print it itself.

func (*Dossier) SelectDocument

func (dossier *Dossier) SelectDocument(shortTitle string) (document Document, err error)

SelectDocument returns the Document which has the specified short title. If no Document matches, it errors.

type DossierI

type DossierI interface {
	// CacheDocuments searches the Dossier's embedded file system at the specified folder path, parsing all discovered
	// markdown documents and caching them in the Dossier.
	CacheDocuments(docsFolderPath string)
	// RenderDocument returns the terminal-rendered markdown of the specified document but does not print it itself.
	RenderDocument(doc Document) (string, error)
	// FormatFrontMatter returns either the string representation of the JSON object containing the specified frontmatter
	// or the rendered markdown table representation of the frontmatter to the caller but does not print either itself.
	FormatFrontMatter(format string, docs []Document)
	// SelectDocument returns the Document which has the specified short title. If no Document matches, it errors.
	SelectDocument(shortTitle string) (document Document, err error)
	// CompleteShortTitle returns the list of short titles which are a valid match for the specified string as a prefix.
	CompleteShortTitle(match string) (titles []string)
	// ListCategories returns a slice of strings containing all of the unique categories used by the Documents in the
	// Dossier's cache.
	ListCategories(docs []Document) (categories []string)
	// ListTags returns a slice of strings containing all of the unique tags used by the Documents in the Dossier's cache.
	ListTags(docs []Document) (tags []string)
}

To implement your own Dossier, you must be able to read markdown documents, render them, list them all, list them filtered by category, list them filtered by tag, and cache them. TODO: Use actually needed methods

type FrontMatter

type FrontMatter struct {
	// The human-readable title for the document and the short name suitable for shell completion
	Title Title
	// A short synopsis of the document's contents
	Description string
	// Whether this document is Conceptual, Narrative, or something else
	Category string
	//  Freeform list of strings to help users filter and find documents
	Tags []string
}

All Documents in a Dossier have required frontmatter; the source markdown document may have other metadata but it *must* have these fields.

type Title

type Title struct {
	// A short downcased string without special characters; used for topic selection
	Short string
	// The full string for the Document's title; human readable
	Long string
}

The Title of a Document has two formats for convenience.

Jump to

Keyboard shortcuts

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