good morning!!!!

Skip to content
Snippets Groups Projects
Commit b3f13da9 authored by Garet Halliday's avatar Garet Halliday
Browse files

GoPrayer -> prayer.Go

parent 81124724
No related branches found
No related tags found
No related merge requests found
......@@ -3,15 +3,15 @@ package main
//go:generate go run .
//go:generate cat ./maps/maps.go
import (
"gfx.cafe/util/temple/lib/prayer"
"log"
"gfx.cafe/util/temple"
"gfx.cafe/util/temple/lib/sanctum"
)
func main() {
temple.RegisterTemplateDir(".")
temple.Prepare(&sanctum.GoPrayer{
temple.Prepare(&prayer.Go{
Input: "mapn",
Obj: map[string]any{
"Count": 10,
......@@ -19,7 +19,7 @@ func main() {
Args: nil,
Output: "./maps/maps.go",
})
temple.Prepare(&sanctum.GoPrayer{
temple.Prepare(&prayer.Go{
Input: "sync_map",
Obj: nil,
Args: nil,
......
......@@ -3,6 +3,7 @@ package main
import (
_ "embed"
"fmt"
"gfx.cafe/util/temple/lib/prayer"
"gfx.cafe/util/temple/lib/sanctum"
"github.com/iancoleman/strcase"
"github.com/spf13/afero"
......@@ -77,7 +78,7 @@ func main() {
if err != nil {
panic(err)
}
t.Prepare(&sanctum.GoPrayer{
t.Prepare(&prayer.Go{
Input: "types",
Obj: ty,
......@@ -105,7 +106,7 @@ func main() {
v["Types"] = ty["Types"]
v["Name"] = strcase.ToCamel(fmt.Sprintf("%s_%s", stateName, directionName))
t.Prepare(&sanctum.GoPrayer{
t.Prepare(&prayer.Go{
Input: "packets",
Obj: v,
......
package sanctum
package prayer
import (
"fmt"
......@@ -6,7 +6,7 @@ import (
"path/filepath"
)
type GoPrayer struct {
type Go struct {
// Input specifies which template to use.
Input string
// Obj is the data that will be passed into the template.
......@@ -20,19 +20,19 @@ type GoPrayer struct {
Output string
}
func (g *GoPrayer) Template() string {
func (g *Go) Template() string {
return g.Input
}
func (g *GoPrayer) Object() any {
func (g *Go) Object() any {
return g.Obj
}
func (g *GoPrayer) Arguments() []any {
func (g *Go) Arguments() []any {
return g.Args
}
func (g *GoPrayer) Format(bytes []byte) ([]byte, error) {
func (g *Go) Format(bytes []byte) ([]byte, error) {
pkg := g.Package
if pkg == "" {
pkg = filepath.Base(filepath.Dir(g.Output))
......@@ -43,8 +43,8 @@ func (g *GoPrayer) Format(bytes []byte) ([]byte, error) {
))
}
func (g *GoPrayer) FileName() string {
func (g *Go) FileName() string {
return g.Output
}
var _ Prayer = (*GoPrayer)(nil)
var _ Prayer = (*Go)(nil)
package prayer
type Prayer interface {
Template() string
Object() any
Arguments() []any
Format([]byte) ([]byte, error)
FileName() string
}
package sanctum
package prayer
type RawPrayer struct {
type Raw struct {
// Input specifies which template to use.
Input string
// Obj is the data that will be passed into the template.
......@@ -12,24 +12,24 @@ type RawPrayer struct {
Output string
}
func (r *RawPrayer) Template() string {
func (r *Raw) Template() string {
return r.Input
}
func (r *RawPrayer) Object() any {
func (r *Raw) Object() any {
return r.Obj
}
func (r *RawPrayer) Arguments() []any {
func (r *Raw) Arguments() []any {
return r.Args
}
func (r *RawPrayer) Format(bytes []byte) ([]byte, error) {
func (r *Raw) Format(bytes []byte) ([]byte, error) {
return bytes, nil
}
func (r *RawPrayer) FileName() string {
func (r *Raw) FileName() string {
return r.Output
}
var _ Prayer = (*RawPrayer)(nil)
var _ Prayer = (*Raw)(nil)
package sanctum
package prayer
import "os/exec"
import (
"os/exec"
)
type RustPrayer struct {
type Rust struct {
// Input specifies which template to use.
Input string
// Obj is the data that will be passed into the template.
......@@ -14,19 +16,19 @@ type RustPrayer struct {
Output string
}
func (r *RustPrayer) Template() string {
func (r *Rust) Template() string {
return r.Input
}
func (r *RustPrayer) Object() any {
func (r *Rust) Object() any {
return r.Obj
}
func (r *RustPrayer) Arguments() []any {
func (r *Rust) Arguments() []any {
return r.Args
}
func (r *RustPrayer) Format(bytes []byte) ([]byte, error) {
func (r *Rust) Format(bytes []byte) ([]byte, error) {
fmt := exec.Command("rustfmt")
in, err := fmt.StdinPipe()
if err != nil {
......@@ -43,8 +45,8 @@ func (r *RustPrayer) Format(bytes []byte) ([]byte, error) {
return fmt.Output()
}
func (r *RustPrayer) FileName() string {
func (r *Rust) FileName() string {
return r.Output
}
var _ Prayer = (*RustPrayer)(nil)
var _ Prayer = (*Rust)(nil)
......@@ -2,6 +2,7 @@ package sanctum
import (
"fmt"
"gfx.cafe/util/temple/lib/prayer"
"log"
"path/filepath"
"strings"
......@@ -23,17 +24,7 @@ type Sanctum struct {
}
type Foyer struct {
Prayers []Prayer
}
type Prayer interface {
Template() string
Object() any
Arguments() []any
Format([]byte) ([]byte, error)
FileName() string
Prayers []prayer.Prayer
}
var defaultFuncs = template.FuncMap{
......@@ -181,7 +172,7 @@ func (t *Sanctum) RegisterFuncVar(s string, val any) {
}
// Prepare queues a Prayer for execution
func (t *Sanctum) Prepare(p Prayer) {
func (t *Sanctum) Prepare(p prayer.Prayer) {
if p != nil {
t.foyer.Prayers = append(t.foyer.Prayers, p)
}
......
package temple
import (
"gfx.cafe/util/temple/lib/prayer"
"gfx.cafe/util/temple/lib/preset"
"gfx.cafe/util/temple/lib/sanctum"
)
......@@ -38,7 +39,7 @@ func RegisterFuncVar(s string, val any) {
Sanctum.RegisterFuncVar(s, val)
}
func Prepare(p sanctum.Prayer) {
func Prepare(p prayer.Prayer) {
Sanctum.Prepare(p)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment