Created
September 23, 2014 13:53
-
-
Save yosssi/74cb7804724acb22b2ff to your computer and use it in GitHub Desktop.
20140923-ace-02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| = doctype html | |
| html | |
| head | |
| title Ace Sample | |
| body | |
| = include inc Input "password" "password" "" "Password" "icon-lock" true true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| h3 This is an include file! | |
| h4 {{.Name}} | |
| h4 {{.Type}} | |
| h4 {{.Value}} | |
| h4 {{.Placeholder}} | |
| h4 {{.Icon}} | |
| h4 {{.LoginInput}} | |
| h4 {{.Required}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bytes" | |
| "fmt" | |
| "html/template" | |
| "net/http" | |
| "github.com/yosssi/ace" | |
| "github.com/yosssi/gohtml" | |
| ) | |
| type Input struct { | |
| Name string | |
| Type string | |
| Value string | |
| Placeholder string | |
| Icon string | |
| LoginInput bool | |
| Required bool | |
| } | |
| func handler(w http.ResponseWriter, r *http.Request) { | |
| tpl, err := ace.Load("base", "inner", &ace.Options{ | |
| DynamicReload: true, | |
| FuncMap: template.FuncMap{ | |
| "Input": func(name string, t string, value string, placeholder string, icon string, loginInput bool, required bool) Input { | |
| return Input{ | |
| Name: name, | |
| Type: t, | |
| Value: value, | |
| Placeholder: placeholder, | |
| Icon: icon, | |
| LoginInput: loginInput, | |
| Required: required, | |
| } | |
| }, | |
| }, | |
| }) | |
| if err != nil { | |
| panic(err) | |
| } | |
| if err := tpl.Execute(w, "test"); err != nil { | |
| bf := new(bytes.Buffer) | |
| tpl.Execute(bf, nil) | |
| fmt.Fprintf(w, "<pre>Error:\n%s\nHTML:\n%s</pre>", err.Error(), template.HTMLEscapeString(gohtml.FormatWithLineNo(bf.String()))) | |
| } | |
| } | |
| func main() { | |
| http.HandleFunc("/", handler) | |
| http.ListenAndServe(":8080", nil) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment