@@ -2,26 +2,41 @@ package data
22
33import (
44 "fmt"
5+
6+ "github.com/hymkor/go-lazy"
7+
8+ "github.com/divnix/std/flake"
59)
610
711var (
812 targetTemplate = "//%s/%s/%s"
913 actionTemplate = "//%s/%s/%s:%s"
14+ noReadme = "🥺 No Readme available ...\n \n 💡 But hey! You could create one ...\n \n 💪 Start with: `$EDITOR %s`\n \n 👉 It will also be rendered in the docs!"
15+ noDescription = "🥺 Target has no 'meta.description' attribute"
16+ cellsFrom = lazy.Of [string ]{
17+ New : func () string {
18+ if s , err := flake .GetCellsFrom (); err != nil {
19+ return "${cellsFrom}"
20+ } else {
21+ return s
22+ }
23+ },
24+ }
1025)
1126
1227type Root struct {
1328 Cells []Cell
1429}
1530
1631type Cell struct {
17- Cell string `json:"cell"`
18- Readme string `json:"readme"`
32+ Name string `json:"cell"`
33+ Readme * string `json:"readme,omitempty "`
1934 Blocks []Block `json:"cellBlocks"`
2035}
2136
2237type Block struct {
23- Block string `json:"cellBlock"`
24- Readme string `json:"readme"`
38+ Name string `json:"cellBlock"`
39+ Readme * string `json:"readme,omitempty "`
2540 Blocktype string `json:"blockType"`
2641 Targets []Target `json:"targets"`
2742}
@@ -36,11 +51,19 @@ func (a Action) Description() string { return a.Descr }
3651func (a Action ) FilterValue () string { return a .Title () }
3752
3853type Target struct {
39- Target string `json:"name"`
40- Readme string `json:"readme"`
41- Deps []string `json:"deps"`
42- Description string `json:"description"`
43- Actions []Action `json:"actions"`
54+ Name string `json:"name"`
55+ Readme * string `json:"readme,omitempty"`
56+ Deps []string `json:"deps"`
57+ Descr * string `json:"description,omitempty"`
58+ Actions []Action `json:"actions"`
59+ }
60+
61+ func (t Target ) Description () string {
62+ if t .Descr != nil {
63+ return "💡 " + * t .Descr
64+ } else {
65+ return noDescription
66+ }
4467}
4568
4669func (r * Root ) Select (ci , oi , ti int ) (Cell , Block , Target ) {
@@ -55,7 +78,7 @@ func (r *Root) Select(ci, oi, ti int) (Cell, Block, Target) {
5578func (r * Root ) ActionArg (ci , oi , ti , ai int ) string {
5679 c , o , t := r .Select (ci , oi , ti )
5780 a := t .Actions [ai ]
58- return fmt .Sprintf (actionTemplate , c .Cell , o .Block , t .Target , a .Name )
81+ return fmt .Sprintf (actionTemplate , c .Name , o .Name , t .Name , a .Name )
5982}
6083
6184func (r * Root ) ActionTitle (ci , oi , ti , ai int ) string {
@@ -72,22 +95,52 @@ func (r *Root) ActionDescription(ci, oi, ti, ai int) string {
7295
7396func (r * Root ) TargetTitle (ci , oi , ti int ) string {
7497 c , o , t := r .Select (ci , oi , ti )
75- return fmt .Sprintf (targetTemplate , c .Cell , o .Block , t .Target )
98+ return fmt .Sprintf (targetTemplate , c .Name , o .Name , t .Name )
7699}
77100
78101func (r * Root ) TargetDescription (ci , oi , ti int ) string {
79102 _ , _ , t := r .Select (ci , oi , ti )
80- return t .Description
81- }
82- func (r * Root ) Cell (ci , oi , ti int ) string { c , _ , _ := r .Select (ci , oi , ti ); return c .Cell }
83- func (r * Root ) CellHelp (ci , oi , ti int ) string { c , _ , _ := r .Select (ci , oi , ti ); return c .Readme }
84- func (r * Root ) HasCellHelp (ci , oi , ti int ) bool { return r .CellHelp (ci , oi , ti ) != "" }
85- func (r * Root ) Block (ci , oi , ti int ) string { _ , o , _ := r .Select (ci , oi , ti ); return o .Block }
86- func (r * Root ) BlockHelp (ci , oi , ti int ) string { _ , o , _ := r .Select (ci , oi , ti ); return o .Readme }
87- func (r * Root ) HasBlockHelp (ci , oi , ti int ) bool { return r .BlockHelp (ci , oi , ti ) != "" }
88- func (r * Root ) Target (ci , oi , ti int ) string { _ , _ , t := r .Select (ci , oi , ti ); return t .Target }
89- func (r * Root ) TargetHelp (ci , oi , ti int ) string { _ , _ , t := r .Select (ci , oi , ti ); return t .Readme }
90- func (r * Root ) HasTargetHelp (ci , oi , ti int ) bool { return r .TargetHelp (ci , oi , ti ) != "" }
103+ return t .Description ()
104+ }
105+ func (r * Root ) Cell (ci , oi , ti int ) Cell { c , _ , _ := r .Select (ci , oi , ti ); return c }
106+ func (r * Root ) CellName (ci , oi , ti int ) string { return r .Cell (ci , oi , ti ).Name }
107+ func (r * Root ) CellHelp (ci , oi , ti int ) string {
108+ if r .HasCellHelp (ci , oi , ti ) {
109+ return * r .Cell (ci , oi , ti ).Readme
110+ } else {
111+ return fmt .Sprintf (noReadme , fmt .Sprintf ("%s/%s/Readme.md" , cellsFrom .Value (), r .CellName (ci , oi , ti )))
112+ }
113+ }
114+ func (r * Root ) HasCellHelp (ci , oi , ti int ) bool {
115+ c := r .Cell (ci , oi , ti )
116+ return c .Readme != nil
117+ }
118+ func (r * Root ) Block (ci , oi , ti int ) Block { _ , o , _ := r .Select (ci , oi , ti ); return o }
119+ func (r * Root ) BlockName (ci , oi , ti int ) string { return r .Block (ci , oi , ti ).Name }
120+ func (r * Root ) BlockHelp (ci , oi , ti int ) string {
121+ if r .HasBlockHelp (ci , oi , ti ) {
122+ return * r .Block (ci , oi , ti ).Readme
123+ } else {
124+ return fmt .Sprintf (noReadme , fmt .Sprintf ("%s/%s/%s/Readme.md" , cellsFrom .Value (), r .CellName (ci , oi , ti ), r .BlockName (ci , oi , ti )))
125+ }
126+ }
127+ func (r * Root ) HasBlockHelp (ci , oi , ti int ) bool {
128+ b := r .Block (ci , oi , ti )
129+ return b .Readme != nil
130+ }
131+ func (r * Root ) Target (ci , oi , ti int ) Target { _ , _ , t := r .Select (ci , oi , ti ); return t }
132+ func (r * Root ) TargetName (ci , oi , ti int ) string { return r .Target (ci , oi , ti ).Name }
133+ func (r * Root ) TargetHelp (ci , oi , ti int ) string {
134+ if r .HasTargetHelp (ci , oi , ti ) {
135+ return * r .Target (ci , oi , ti ).Readme
136+ } else {
137+ return fmt .Sprintf (noReadme , fmt .Sprintf ("%s/%s/%s/%s.md" , cellsFrom .Value (), r .CellName (ci , oi , ti ), r .BlockName (ci , oi , ti ), r .TargetName (ci , oi , ti )))
138+ }
139+ }
140+ func (r * Root ) HasTargetHelp (ci , oi , ti int ) bool {
141+ t := r .Target (ci , oi , ti )
142+ return t .Readme != nil
143+ }
91144
92145func (r * Root ) Len () int {
93146 sum := 0
0 commit comments