Skip to content

Instantly share code, notes, and snippets.

@yosssi
Created September 23, 2014 07:11
Show Gist options
  • Select an option

  • Save yosssi/70ea023495531ea1a01b to your computer and use it in GitHub Desktop.

Select an option

Save yosssi/70ea023495531ea1a01b to your computer and use it in GitHub Desktop.
20140923-ace-01
= doctype html
html
head
title Ace Sample
body
= yield main
h3 This is an include file!
= content main
h1 Ace Sample
h2 Hello Ace!
= include inc
h3 {{.AA}}
package main
import (
"bytes"
"fmt"
"net/http"
"text/template"
"github.com/yosssi/ace"
"github.com/yosssi/gohtml"
)
func handler(w http.ResponseWriter, r *http.Request) {
tpl, err := ace.Load("base", "inner", nil)
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