move astgen files into a __htmgo folder
This commit is contained in:
parent
a58cb051e8
commit
2bc62b8ce6
9 changed files with 71 additions and 49 deletions
|
|
@ -257,22 +257,19 @@ func writePartialsFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
builder := NewCodeBuilder(nil)
|
builder := NewCodeBuilder(nil)
|
||||||
builder.AppendLine(`// Package partials THIS FILE IS GENERATED. DO NOT EDIT.`)
|
builder.AppendLine(`// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.`)
|
||||||
builder.AppendLine("package load")
|
builder.AppendLine("package __htmgo")
|
||||||
builder.AddImport("github.com/maddalax/htmgo/framework/h")
|
builder.AddImport("github.com/maddalax/htmgo/framework/h")
|
||||||
builder.AddImport("github.com/labstack/echo/v4")
|
builder.AddImport("github.com/labstack/echo/v4")
|
||||||
|
|
||||||
moduleName := GetModuleName()
|
moduleName := GetModuleName()
|
||||||
for _, partial := range partials {
|
for _, partial := range partials {
|
||||||
if partial.Import == "partials/load" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
builder.AddImport(fmt.Sprintf(`%s/%s`, moduleName, partial.Import))
|
builder.AddImport(fmt.Sprintf(`%s/%s`, moduleName, partial.Import))
|
||||||
}
|
}
|
||||||
|
|
||||||
buildGetPartialFromContext(builder, partials)
|
buildGetPartialFromContext(builder, partials)
|
||||||
|
|
||||||
WriteFile(filepath.Join("partials", "load", "generated.go"), func(content *ast.File) string {
|
WriteFile(filepath.Join("__htmgo", "partials-generated.go"), func(content *ast.File) string {
|
||||||
return builder.String()
|
return builder.String()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -299,8 +296,8 @@ func formatRoute(path string) string {
|
||||||
func writePagesFile() {
|
func writePagesFile() {
|
||||||
|
|
||||||
builder := NewCodeBuilder(nil)
|
builder := NewCodeBuilder(nil)
|
||||||
builder.AppendLine(`// Package pages THIS FILE IS GENERATED. DO NOT EDIT.`)
|
builder.AppendLine(`// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.`)
|
||||||
builder.AppendLine("package pages")
|
builder.AppendLine("package __htmgo")
|
||||||
builder.AddImport("github.com/labstack/echo/v4")
|
builder.AddImport("github.com/labstack/echo/v4")
|
||||||
|
|
||||||
pages, _ := findPublicFuncsReturningHPage("pages")
|
pages, _ := findPublicFuncsReturningHPage("pages")
|
||||||
|
|
@ -310,8 +307,11 @@ func writePagesFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
if page.Import != "" && page.Package != "pages" {
|
if page.Import != "" {
|
||||||
builder.AddImport(page.Import)
|
moduleName := GetModuleName()
|
||||||
|
builder.AddImport(
|
||||||
|
fmt.Sprintf(`%s/%s`, moduleName, page.Import),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -321,9 +321,6 @@ func writePagesFile() {
|
||||||
|
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
call := fmt.Sprintf("%s.%s", page.Package, page.FuncName)
|
call := fmt.Sprintf("%s.%s", page.Package, page.FuncName)
|
||||||
if page.Package == "pages" {
|
|
||||||
call = page.FuncName
|
|
||||||
}
|
|
||||||
|
|
||||||
body += fmt.Sprintf(`
|
body += fmt.Sprintf(`
|
||||||
f.GET("%s", func(ctx echo.Context) error {
|
f.GET("%s", func(ctx echo.Context) error {
|
||||||
|
|
@ -343,7 +340,7 @@ func writePagesFile() {
|
||||||
|
|
||||||
builder.Append(builder.BuildFunction(f))
|
builder.Append(builder.BuildFunction(f))
|
||||||
|
|
||||||
WriteFile("pages/generated.go", func(content *ast.File) string {
|
WriteFile("__htmgo/pages-generated.go", func(content *ast.File) string {
|
||||||
return builder.String()
|
return builder.String()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -369,5 +366,22 @@ func GenAst(flags ...process.RunFlag) error {
|
||||||
}
|
}
|
||||||
writePartialsFile()
|
writePartialsFile()
|
||||||
writePagesFile()
|
writePagesFile()
|
||||||
|
|
||||||
|
WriteFile("__htmgo/setup-generated.go", func(content *ast.File) string {
|
||||||
|
return `
|
||||||
|
// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.
|
||||||
|
package __htmgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Register(e *echo.Echo) {
|
||||||
|
RegisterPartials(e)
|
||||||
|
RegisterPages(e)
|
||||||
|
}
|
||||||
|
`
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,22 @@
|
||||||
// Package partials THIS FILE IS GENERATED. DO NOT EDIT.
|
package __htmgo
|
||||||
package load
|
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"htmgo-site/pages"
|
||||||
|
"htmgo-site/partials"
|
||||||
|
)
|
||||||
import "github.com/maddalax/htmgo/framework/h"
|
import "github.com/maddalax/htmgo/framework/h"
|
||||||
import "github.com/labstack/echo/v4"
|
|
||||||
import "htmgo-site/partials"
|
func RegisterPages(f *echo.Echo) {
|
||||||
|
f.GET("/docs", func(ctx echo.Context) error {
|
||||||
|
cc := ctx.(*h.RequestContext)
|
||||||
|
return h.HtmlView(ctx, pages.DocsPage(cc))
|
||||||
|
})
|
||||||
|
f.GET("/", func(ctx echo.Context) error {
|
||||||
|
cc := ctx.(*h.RequestContext)
|
||||||
|
return h.HtmlView(ctx, pages.IndexPage(cc))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func GetPartialFromContext(ctx echo.Context) *h.Partial {
|
func GetPartialFromContext(ctx echo.Context) *h.Partial {
|
||||||
path := ctx.Request().URL.Path
|
path := ctx.Request().URL.Path
|
||||||
|
|
@ -6,9 +6,9 @@ import (
|
||||||
"github.com/maddalax/htmgo/framework/h"
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
"github.com/maddalax/htmgo/framework/service"
|
"github.com/maddalax/htmgo/framework/service"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
"htmgo-site/__htmgo"
|
||||||
"htmgo-site/internal/markdown"
|
"htmgo-site/internal/markdown"
|
||||||
"htmgo-site/pages"
|
"htmgo-site/pages"
|
||||||
"htmgo-site/partials/load"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -42,8 +42,9 @@ func main() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
load.RegisterPartials(e)
|
__htmgo.RegisterPartials(e)
|
||||||
pages.RegisterPages(e)
|
__htmgo.RegisterPages(e)
|
||||||
|
|
||||||
pages.RegisterMarkdown(e, "md", MarkdownAssets, func(ctx echo.Context, path string) error {
|
pages.RegisterMarkdown(e, "md", MarkdownAssets, func(ctx echo.Context, path string) error {
|
||||||
return pages.MarkdownHandler(ctx.(*h.RequestContext), path)
|
return pages.MarkdownHandler(ctx.(*h.RequestContext), path)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
// Package pages THIS FILE IS GENERATED. DO NOT EDIT.
|
|
||||||
package pages
|
|
||||||
|
|
||||||
import "github.com/labstack/echo/v4"
|
|
||||||
import "github.com/maddalax/htmgo/framework/h"
|
|
||||||
|
|
||||||
func RegisterPages(f *echo.Echo) {
|
|
||||||
f.GET("/docs", func(ctx echo.Context) error {
|
|
||||||
cc := ctx.(*h.RequestContext)
|
|
||||||
return h.HtmlView(ctx, DocsPage(cc))
|
|
||||||
})
|
|
||||||
f.GET("/", func(ctx echo.Context) error {
|
|
||||||
cc := ctx.(*h.RequestContext)
|
|
||||||
return h.HtmlView(ctx, IndexPage(cc))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -3,14 +3,14 @@ version: '3'
|
||||||
tasks:
|
tasks:
|
||||||
run:
|
run:
|
||||||
cmds:
|
cmds:
|
||||||
- go run github.com/maddalax/htmgo/cli@latest run
|
- go run github.com/maddalax/htmgo/cli/htmgo@latest run
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
build:
|
build:
|
||||||
cmds:
|
cmds:
|
||||||
- go run github.com/maddalax/htmgo/cli@latest build
|
- go run github.com/maddalax/htmgo/cli/htmgo@latest build
|
||||||
|
|
||||||
watch:
|
watch:
|
||||||
cmds:
|
cmds:
|
||||||
- go run github.com/maddalax/htmgo/cli@latest watch
|
- go run github.com/maddalax/htmgo/cli/htmgo@latest watch
|
||||||
silent: true
|
silent: true
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
// Package pages THIS FILE IS GENERATED. DO NOT EDIT.
|
// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.
|
||||||
package pages
|
package __htmgo
|
||||||
|
|
||||||
import "github.com/labstack/echo/v4"
|
import "github.com/labstack/echo/v4"
|
||||||
import "github.com/maddalax/htmgo/framework/h"
|
import "github.com/maddalax/htmgo/framework/h"
|
||||||
|
import "todolist/pages"
|
||||||
|
|
||||||
func RegisterPages(f *echo.Echo) {
|
func RegisterPages(f *echo.Echo) {
|
||||||
f.GET("/", func(ctx echo.Context) error {
|
f.GET("/", func(ctx echo.Context) error {
|
||||||
cc := ctx.(*h.RequestContext)
|
cc := ctx.(*h.RequestContext)
|
||||||
return h.HtmlView(ctx, TaskListPage(cc))
|
return h.HtmlView(ctx, pages.TaskListPage(cc))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Package partials THIS FILE IS GENERATED. DO NOT EDIT.
|
// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.
|
||||||
package load
|
package __htmgo
|
||||||
|
|
||||||
import "github.com/maddalax/htmgo/framework/h"
|
import "github.com/maddalax/htmgo/framework/h"
|
||||||
import "github.com/labstack/echo/v4"
|
import "github.com/labstack/echo/v4"
|
||||||
11
todo-list/__htmgo/setup-generated.go
Normal file
11
todo-list/__htmgo/setup-generated.go
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Package __htmgo THIS FILE IS GENERATED. DO NOT EDIT.
|
||||||
|
package __htmgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Register(e *echo.Echo) {
|
||||||
|
RegisterPartials(e)
|
||||||
|
RegisterPages(e)
|
||||||
|
}
|
||||||
|
|
@ -5,10 +5,9 @@ import (
|
||||||
"github.com/maddalax/htmgo/framework/h"
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
"github.com/maddalax/htmgo/framework/service"
|
"github.com/maddalax/htmgo/framework/service"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
"todolist/__htmgo"
|
||||||
"todolist/ent"
|
"todolist/ent"
|
||||||
"todolist/infrastructure/db"
|
"todolist/infrastructure/db"
|
||||||
"todolist/pages"
|
|
||||||
"todolist/partials/load"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -23,8 +22,7 @@ func main() {
|
||||||
LiveReload: true,
|
LiveReload: true,
|
||||||
Register: func(e *echo.Echo) {
|
Register: func(e *echo.Echo) {
|
||||||
e.Static("/public", "./assets/dist")
|
e.Static("/public", "./assets/dist")
|
||||||
load.RegisterPartials(e)
|
__htmgo.Register(e)
|
||||||
pages.RegisterPages(e)
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue