Skip to content

Commit

Permalink
Renames package doc to document (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored Jan 12, 2025
1 parent 8f601d7 commit d626221
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 41 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### Other

* Remove numbering from navigation entries (#16)
* Removes numbering from navigation entries (#16)
* Renames package `doc` to `document` (#17)

## [[v0.1.1]](https://github.com/mlange-42/modo/compare/v0.1.0...v0.1.1)

Expand Down
4 changes: 2 additions & 2 deletions cmd/modo/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"

"github.com/mlange-42/modo"
"github.com/mlange-42/modo/doc"
"github.com/mlange-42/modo/document"
"github.com/mlange-42/modo/format"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -37,7 +37,7 @@ func rootCommand() *cobra.Command {
return err
}

docs, err := doc.FromJson(data)
docs, err := document.FromJson(data)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion doc/json.go → document/document.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package doc
package document

import (
"bytes"
Expand Down
6 changes: 3 additions & 3 deletions doc/json_test.go → document/document_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package doc_test
package document_test

import (
"testing"

"github.com/mlange-42/modo/doc"
"github.com/mlange-42/modo/document"
"github.com/stretchr/testify/assert"
)

Expand All @@ -20,7 +20,7 @@ func TestFromJson(t *testing.T) {
"version": "0.1.0"
}`

docs, err := doc.FromJson([]byte(data))
docs, err := document.FromJson([]byte(data))
assert.Nil(t, err)
assert.NotNil(t, docs)
}
4 changes: 2 additions & 2 deletions format/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package format
import (
"text/template"

"github.com/mlange-42/modo/doc"
"github.com/mlange-42/modo/document"
)

type Format uint8
Expand All @@ -23,5 +23,5 @@ func GetFormatter(f Format) Formatter {
}

type Formatter interface {
WriteAuxiliary(p *doc.Package, dir string, t *template.Template) error
WriteAuxiliary(p *document.Package, dir string, t *template.Template) error
}
12 changes: 6 additions & 6 deletions format/mdbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"strings"
"text/template"

"github.com/mlange-42/modo/doc"
"github.com/mlange-42/modo/document"
)

type MdBookFormatter struct{}

func (f *MdBookFormatter) WriteAuxiliary(p *doc.Package, dir string, t *template.Template) error {
func (f *MdBookFormatter) WriteAuxiliary(p *document.Package, dir string, t *template.Template) error {
if err := f.writeSummary(p, dir, t); err != nil {
return err
}
Expand All @@ -28,7 +28,7 @@ type summary struct {
Modules string
}

func (f *MdBookFormatter) writeSummary(p *doc.Package, dir string, t *template.Template) error {
func (f *MdBookFormatter) writeSummary(p *document.Package, dir string, t *template.Template) error {
summaryPath := path.Join(dir, p.GetName(), "SUMMARY.md")

s := summary{}
Expand Down Expand Up @@ -58,7 +58,7 @@ func (f *MdBookFormatter) writeSummary(p *doc.Package, dir string, t *template.T
return nil
}

func (f *MdBookFormatter) renderPackage(pkg *doc.Package, linkPath []string, out *strings.Builder) {
func (f *MdBookFormatter) renderPackage(pkg *document.Package, linkPath []string, out *strings.Builder) {
newPath := append([]string{}, linkPath...)
newPath = append(newPath, pkg.GetName())
fmt.Fprintf(out, "%-*s- [%s](./%s/_index.md))\n", 2*len(linkPath), "", pkg.GetName(), path.Join(newPath...))
Expand All @@ -70,7 +70,7 @@ func (f *MdBookFormatter) renderPackage(pkg *doc.Package, linkPath []string, out
}
}

func (f *MdBookFormatter) renderModule(mod *doc.Module, linkPath []string, out *strings.Builder) {
func (f *MdBookFormatter) renderModule(mod *document.Module, linkPath []string, out *strings.Builder) {
newPath := append([]string{}, linkPath...)
newPath = append(newPath, mod.GetName())
pathStr := path.Join(newPath...)
Expand All @@ -87,7 +87,7 @@ func (f *MdBookFormatter) renderModule(mod *doc.Module, linkPath []string, out *
}
}

func (f *MdBookFormatter) writeToml(p *doc.Package, dir string, t *template.Template) error {
func (f *MdBookFormatter) writeToml(p *document.Package, dir string, t *template.Template) error {
tomlPath := path.Join(dir, "book.toml")

b := strings.Builder{}
Expand Down
4 changes: 2 additions & 2 deletions format/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package format
import (
"text/template"

"github.com/mlange-42/modo/doc"
"github.com/mlange-42/modo/document"
)

type PlainFormatter struct{}

func (f *PlainFormatter) WriteAuxiliary(p *doc.Package, dir string, t *template.Template) error {
func (f *PlainFormatter) WriteAuxiliary(p *document.Package, dir string, t *template.Template) error {
return nil
}
14 changes: 7 additions & 7 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"text/template"

"github.com/mlange-42/modo/doc"
"github.com/mlange-42/modo/document"
"github.com/mlange-42/modo/format"
)

Expand All @@ -25,7 +25,7 @@ func init() {
}
}

func Render(data doc.Kinded) (string, error) {
func Render(data document.Kinded) (string, error) {
b := strings.Builder{}
err := t.ExecuteTemplate(&b, data.GetKind()+".md", data)
if err != nil {
Expand All @@ -34,7 +34,7 @@ func Render(data doc.Kinded) (string, error) {
return b.String(), nil
}

func RenderPackage(p *doc.Package, dir string, renderFormat format.Format, root bool) error {
func RenderPackage(p *document.Package, dir string, renderFormat format.Format, root bool) error {
pkgPath := path.Join(dir, p.GetName())
if err := mkDirs(pkgPath); err != nil {
return err
Expand Down Expand Up @@ -72,7 +72,7 @@ func RenderPackage(p *doc.Package, dir string, renderFormat format.Format, root
return nil
}

func renderModule(mod *doc.Module, dir string) error {
func renderModule(mod *document.Module, dir string) error {
if err := mkDirs(dir); err != nil {
return err
}
Expand Down Expand Up @@ -101,9 +101,9 @@ func renderModule(mod *doc.Module, dir string) error {
}

func renderList[T interface {
doc.Named
doc.Kinded
doc.Pathed
document.Named
document.Kinded
document.Pathed
}](list []T, dir string) error {
for _, elem := range list {
text, err := Render(elem)
Expand Down
34 changes: 17 additions & 17 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import (
"testing"

"github.com/mlange-42/modo"
"github.com/mlange-42/modo/doc"
"github.com/mlange-42/modo/document"
)

func TestTemplatePackage(t *testing.T) {
pkg := doc.Package{
Kind: doc.NewKind("package"),
Name: doc.NewName("Modo"),
pkg := document.Package{
Kind: document.NewKind("package"),
Name: document.NewName("Modo"),
Summary: "Mojo documentation generator",
Description: "Package description",
Modules: []*doc.Module{
Modules: []*document.Module{
{
Name: doc.NewName("mod1"),
Name: document.NewName("mod1"),
Summary: "Mod1 summary",
},
{
Name: doc.NewName("mod2"),
Name: document.NewName("mod2"),
Summary: "Mod2 summary",
},
},
Packages: []*doc.Package{},
Packages: []*document.Package{},
}

text, err := modo.Render(&pkg)
Expand All @@ -35,24 +35,24 @@ func TestTemplatePackage(t *testing.T) {
}

func TestTemplateModule(t *testing.T) {
mod := doc.Module{
Kind: doc.NewKind("module"),
Name: doc.NewName("modo"),
mod := document.Module{
Kind: document.NewKind("module"),
Name: document.NewName("modo"),
Description: "",
Summary: "a test module",
Aliases: []*doc.Alias{},
Structs: []*doc.Struct{
Aliases: []*document.Alias{},
Structs: []*document.Struct{
{
Name: doc.NewName("TestStruct2"),
Name: document.NewName("TestStruct2"),
Summary: "Struct summary...",
},
{
Name: doc.NewName("TestStruct"),
Name: document.NewName("TestStruct"),
Summary: "Struct summary 2...",
},
},
Traits: []*doc.Trait{},
Functions: []*doc.Function{},
Traits: []*document.Trait{},
Functions: []*document.Function{},
}

text, err := modo.Render(&mod)
Expand Down

0 comments on commit d626221

Please sign in to comment.