From 846db9c5fda0eb1f876f9093a7b718ab7c4d1c84 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 3 Nov 2018 15:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A8=A1=E6=9D=BF=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=8F=98=E9=87=8F=E7=A4=BA=E4=BE=8B=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TODO.MD | 2 +- geg/os/gview/object/object.go | 28 ++++++++++++++++++++++++++++ geg/other/test.go | 31 ++++++++++++++----------------- geg/other/web/index.html | 1 - 4 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 geg/os/gview/object/object.go delete mode 100644 geg/other/web/index.html diff --git a/TODO.MD b/TODO.MD index 655f52fc1..82e852f79 100644 --- a/TODO.MD +++ b/TODO.MD @@ -40,7 +40,7 @@ - https://github.com/namreg/godown - https://github.com/Masterminds/sprig 1. gform参考 https://gohouse.github.io/gorose/dist/index.html 进行改进 -1. 模板引擎增加对对象的支持(参考https://segmentfault.com/q/1010000016829214); +1. 模板引擎增加对象的支持(参考https://segmentfault.com/q/1010000016829214); diff --git a/geg/os/gview/object/object.go b/geg/os/gview/object/object.go new file mode 100644 index 000000000..b2695df6a --- /dev/null +++ b/geg/os/gview/object/object.go @@ -0,0 +1,28 @@ +package main + +import ( + "gitee.com/johng/gf/g" +) + +type T struct { + Name string +} + +func (t *T) Hello(name string) string { + return "Hello " + name +} + +func (t *T) Test() string { + return "This is test" +} + +func main() { + t := &T{"John"} + v := g.View() + content := `{{.t.Hello "there"}}, my name's {{.t.Name}}. {{.t.Test}}.` + if r, err := v.ParseContent(content, g.Map{"t" : t}); err != nil { + g.Dump(err) + } else { + g.Dump(r) + } +} diff --git a/geg/other/test.go b/geg/other/test.go index 45b1e4ff3..d14d8b912 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -1,24 +1,21 @@ package main import ( - "gitee.com/johng/gf/g/frame/gmvc" - "gitee.com/johng/gf/g/net/ghttp" + "html/template" + "log" + "os" ) -type ControllerIndex struct { - gmvc.Controller -} -func (c *ControllerIndex) Info() { - c.View.Assign("title", "Go Frame 第一个网站") - c.View.Assigns(map[string]interface{}{ - "name" : "很开心", - "score" : 100, - }) - c.View.Display("web/index.html") + +type Person string + +func (p Person) Label() string { + return "This is " + string(p) } + func main() { - s := ghttp.GetServer() - s.SetServerRoot("/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/other/web/") - s.BindController("/", new(ControllerIndex)) - s.SetPort(8199) - s.Run() + tmpl, err := template.New("").Parse(`{{sum 1 2 3}}`) + if err != nil { + log.Fatalf("Parse: %v", err) + } + tmpl.Execute(os.Stdout, nil) } \ No newline at end of file diff --git a/geg/other/web/index.html b/geg/other/web/index.html deleted file mode 100644 index 28d14454c..000000000 --- a/geg/other/web/index.html +++ /dev/null @@ -1 +0,0 @@ -123456789