Skip to content

Commit 0ca228c

Browse files
committed
Put Page into a better shared location
1 parent 32ce0a6 commit 0ca228c

4 files changed

Lines changed: 23 additions & 15 deletions

File tree

auto-docs/docs/store.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"path/filepath"
1616
"strings"
1717

18+
autodocs "github.com/cloudcloud/auto-docs"
1819
"gitlab.com/golang-commonmark/markdown"
1920
)
2021

@@ -25,7 +26,7 @@ var (
2526

2627
func init() {
2728
S.Dirs = []*Dir{}
28-
S.Pages = make(map[string]*Page, 0)
29+
S.Pages = make(map[string]*autodocs.Page, 0)
2930
}
3031

3132
// Dir gives a holder of further nodes.
@@ -38,21 +39,13 @@ type Dir struct {
3839
Text string `json:"text"`
3940
}
4041

41-
// Page is the content structure for an individual page item.
42-
type Page struct {
43-
// Name is the displayable identifier for a page.
44-
Name string `json:"name"`
45-
// Content is the parsed markup of the page.
46-
Content string `json:"content"`
47-
}
48-
4942
// Store captures the doc file references and content.
5043
type Store struct {
5144
// Dirs tracks the structure of pages under their paths.
5245
Dirs []*Dir `json:"pages"`
5346

5447
// Pages captures the content for a full path page.
55-
Pages map[string]*Page `json:"-"`
48+
Pages map[string]*autodocs.Page `json:"-"`
5649

5750
// path is the base that this store is defined for.
5851
path string
@@ -130,15 +123,15 @@ func addToDir(d []*Dir, p, o string) []*Dir {
130123
}
131124

132125
// buildPage
133-
func buildPage(p, d string) (*Page, error) {
126+
func buildPage(p, d string) (*autodocs.Page, error) {
134127
b := tokenise(p)
135128
m := markdown.New(markdown.XHTMLOutput(true))
136129
f, err := ioutil.ReadFile(d)
137130
if err != nil {
138131
return nil, fmt.Errorf("unable to load markdown file: %s", err)
139132
}
140133

141-
return &Page{
134+
return &autodocs.Page{
142135
Name: b[len(b)-1],
143136
Content: m.RenderToString(f),
144137
}, nil

auto-docs/docs/store_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"time"
1010

11+
autodocs "github.com/cloudcloud/auto-docs"
1112
"github.com/stretchr/testify/assert"
1213
)
1314

@@ -47,7 +48,7 @@ func TestUpdateFromPath(t *testing.T) {
4748
for _, a := range x {
4849
s := &Store{
4950
Dirs: []*Dir{},
50-
Pages: map[string]*Page{},
51+
Pages: map[string]*autodocs.Page{},
5152
}
5253
log.SetOutput(a.Buffer)
5354

@@ -175,7 +176,7 @@ func TestAddToDir(t *testing.T) {
175176
}
176177

177178
type pageStruct struct {
178-
ExpPage *Page
179+
ExpPage *autodocs.Page
179180
ExpErr error
180181
InpPag string
181182
InpDir string
@@ -186,7 +187,7 @@ func TestBuildPage(t *testing.T) {
186187
assert := assert.New(t)
187188
x := []pageStruct{
188189
{
189-
ExpPage: &Page{Name: "root", Content: "<h1>root</h1>\n"},
190+
ExpPage: &autodocs.Page{Name: "root", Content: "<h1>root</h1>\n"},
190191
ExpErr: nil,
191192
InpPag: "/root",
192193
InpDir: getTestMarkdownDir() + "root.md",

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
55
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
66
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
77
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
89
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
910
github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
1011
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
@@ -56,6 +57,7 @@ github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtb
5657
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
5758
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
5859
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
60+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5961
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6062
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
6163
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
@@ -75,6 +77,7 @@ github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
7577
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
7678
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7779
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
80+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
7881
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7982
github.com/ugorji/go v1.1.2 h1:JON3E2/GPW2iDNGoSAusl1KDf5TRQ8k8q7Tp097pZGs=
8083
github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=

page.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package autodocs
2+
3+
// Page is a structure to store an individual page that has been
4+
// processed and ready to be displayed.
5+
type Page struct {
6+
// Name is the displayable identifier for the page.
7+
Name string `json:"name"`
8+
9+
// Content contains the parsed content for this page.
10+
Content string `json:"content"`
11+
}

0 commit comments

Comments
 (0)