Documentation
¶
Overview ¶
Package mapfolder knows where each part of a capability lives in its folder and writes the contents that link to its entries: index.md with the promise, overview and links, and one file of entries per kind. It splits a capability's single text into its folder and formats a map's folders, never changing an entry's text.
Index ¶
- Constants
- Variables
- func AddEntry(dir, title string, k Kind, entry string) (int, int, error)
- func Anchor(heading string) string
- func CapabilityDir(slug string) string
- func Contents(headings []string) []string
- func Format(file, text string) (string, error)
- func FormatIndex(text string, kinds []Kind) (string, error)
- func HeadingProblem(heading string) string
- func Index(frontMatter, title, overview string, kinds []Kind) string
- func IndexLink(k Kind) string
- func KindFile(title string, kind Kind, entries []string) string
- func SafeHeading(s string) string
- type ErrOldLayout
- type Folder
- type FormatError
- type Kind
- type LineError
- type Problem
- type Snapshot
- type SplitError
- type Unsafe
Constants ¶
const ( Dir = ".physa" ProductDir = Dir + "/product" CapabilitiesDir = Dir + "/capabilities" )
Where the map lives, relative to the repo's root.
const ( IndexFile = "index.md" RulesFile = "rules.md" DecisionsFile = "decisions.md" QuestionsFile = "questions.md" )
The files of a capability's folder.
Variables ¶
var Kinds = []Kind{Rule, Decision, Question}
Kinds lists every kind in index.md's order.
var Products = []string{Dir + "/product.md", ProductDir + "/" + IndexFile}
Products are where a map's product is, in the old layout and in folders; either means a map.
var Readme string
Readme is .physa/README.md's text, the map's fallback for agents without the CLI (design 01 section 6). It carries the slice skill's judgment, the folder layout and how to cut one entry out by its slug. The text lives in readme.md.
Functions ¶
func AddEntry ¶
AddEntry appends entry, one entry's text, last under ## Entries of the kind file of the capability folder dir whose title is title, and regenerates that file's contents. A kind file the folder lacks is made, and index.md then links it. It returns the first and last line (from 1) the entry takes in its file. A file outside its format, with the entry appended, is an error naming the file and wrapping its *FormatError, whose line counts in that appended text; the folder is then as it was. When index.md cannot link a kind file just made, that file is left for the caller's Snapshot to remove.
func Anchor ¶
Anchor is the link anchor GitHub makes from a heading: lowercase, every character other than a letter, a digit, a space, a hyphen or an underscore dropped, and each space turned into a hyphen. Repeated hyphens stay.
func CapabilityDir ¶
CapabilityDir is the folder of the capability named slug.
func Contents ¶
Contents is a kind file's contents: one line per entry, in entry order, each the heading verbatim linked to its anchor.
func Format ¶
Format rebuilds the folder file named file and normalises its spacing: a kind file's contents are regenerated from its entries, and index.md keeps its links (FormatIndex sets them). Every byte of an entry, from its heading to its last non-blank line, is kept. A file outside its format is a *FormatError.
func FormatIndex ¶
FormatIndex formats index.md with a link to each of kinds' files.
func HeadingProblem ¶
HeadingProblem says why a heading cannot make a stable contents line (brackets, angle brackets and asterisks break it), or is empty.
func Index ¶
Index renders index.md: the front matter block with its --- lines, the title, the overview paragraph and a link to each of kinds' files, in the order rules, decisions, questions.
func KindFile ¶
KindFile renders a kind file: its title, the contents generated from the entries, and each entry's text (its heading line through its last body line) verbatim, one blank line apart.
func SafeHeading ¶
SafeHeading is s without the characters HeadingProblem rejects, its words one space apart.
Types ¶
type ErrOldLayout ¶
type ErrOldLayout struct {
Path string // slash-separated, relative to the root
}
ErrOldLayout says a map is still in the single-file layout, naming the first old file found.
func (ErrOldLayout) Error ¶
func (e ErrOldLayout) Error() string
type Folder ¶
type Folder struct {
Files map[string]string // file name, such as "index.md", to its text
Source map[string][]int // file name to, per line, the line of the single text it came from; 0 when generated
}
Folder is one capability's folder, split from its single text.
func Split ¶
Split turns one capability written as a single text (front matter, a "# " title, an optional overview paragraph, then "## Rules", "## Decisions" and "## Questions" sections of "### " entries) into its folder: index.md, plus one kind file for each kind with entries. Entry text is kept byte for byte. Without an overview the promise is the overview (its Source the promise's line), so every index has one. A text not in that shape is a *SplitError.
type FormatError ¶
type FormatError = LineError
type Kind ¶
type Kind int
Kind says which kind of entry an entry is, and so which file holds it.
The entry kinds, in the order their files are linked from index.md.
func KindOfFile ¶
KindOfFile says which kind a file name holds; false for any other name.
type LineError ¶
LineError is a spot where a text is not in its file's shape: a SplitError for a single text, a FormatError for a folder file.
type Problem ¶
type Problem struct {
Path string // slash-separated, relative to the root
Line int
Message string
}
Problem is a file FormatMap left unchanged, with the line that stopped it.
func FormatMap ¶
FormatMap formats every file in the map's folders under root: the product and each capability, with index links to the kind files each folder has. It returns the slash-separated paths whose text would change, and writes them only when write is true; it never creates or deletes a file. A file outside its format is left as it is and reported as a Problem, and the others are still formatted. A map still in the single-file layout is an ErrOldLayout, found before anything is formatted.
type Snapshot ¶
Snapshot is the files directly in a folder, by name, as they were when Take read them.
type SplitError ¶
type SplitError = LineError
SplitError and FormatError name LineError for Split and Format.
type Unsafe ¶
Unsafe is an entry SafeFiles took out of a folder, with why.
func SafeFiles ¶
SafeFiles is a folder's files by name, as Split gives them, with each entry taken out whose heading the map check would reject: an empty one, one HeadingProblem names, and one with the anchor of the title, a section or an earlier heading of its file. A kind file left with no entries goes, and index.md's links follow. Every other byte is kept.