Permalink
Browse files

Reuse go.talks templates and static files.

Update server to use templates and static files directly from
code.google.com/p/go.talks/present.

Move talks to talks.godoc.org so we can match the directory structure of
the present tool without conflicting with godoc.org's own directory
structure.
  • Loading branch information...
1 parent a95021c commit fbaa19e90387e1a4f7563bf2f7f0eb6a1571c9ad @garyburd garyburd committed Feb 7, 2013
View
@@ -20,11 +20,10 @@ Development Environment Setup
-----------------------------
- Install and run [Redis 2.6.x](http://redis.io/download). The redis.conf file included in the Redis distribution is suitable for development.
-- Install [Go](http://golang.org/doc/install) and configure [GOPATH](http://golang.org/doc/code.html).
+- Install Go from source and update to tip.
- Install and run the server:
go get github.com/garyburd/gopkgdoc/gddo-server
- cd `go list -f '{{.Dir}}' github.com/garyburd/gopkgdoc/gddo-server`
gddo-server
License
View
@@ -22,6 +22,7 @@ import (
"flag"
"fmt"
"go/build"
+ "html/template"
"io"
"io/ioutil"
"log"
@@ -35,6 +36,7 @@ import (
"sync"
"time"
+ "code.google.com/p/go.talks/pkg/present"
"github.com/garyburd/gopkgdoc/database"
"github.com/garyburd/gopkgdoc/doc"
"github.com/garyburd/indigo/server"
@@ -328,7 +330,20 @@ func servePresentation(resp web.Response, req *web.Request) error {
presMu.Unlock()
}
- return executeTemplate(resp, path.Ext(p)[1:]+".html", 200, pres)
+ t := presentTemplates[path.Ext(p)]
+ data := struct {
+ *present.Doc
+ Template *template.Template
+ PlayEnabled bool
+ }{
+ pres.Doc,
+ t,
+ false,
+ }
+
+ return t.Execute(
+ resp.Start(web.StatusOK, web.Header{web.HeaderContentType: {"text/html; charset=utf8"}}),
+ &data)
}
func defaultBase(path string) string {
@@ -419,8 +434,8 @@ func main() {
}
if err := parsePresentTemplates([][]string{
- {"article.html", "presentCommon.html"},
- {"slide.html", "presentCommon.html"},
+ {".article", "article.tmpl", "action.tmpl"},
+ {".slide", "slides.tmpl", "action.tmpl"},
}); err != nil {
log.Fatal(err)
}
@@ -446,13 +461,21 @@ func main() {
}
r := web.NewRouter()
+ r.Add("/favicon.ico").Get(web.FileHandler(filepath.Join(*baseDir, "static", "favicon.ico"), nil))
+ r.Add("/static/<path:.*>").Get(web.DirectoryHandler(filepath.Join(*presentBaseDir, "static"), sfo))
+ r.Add("/play.js").Get(web.CatFilesHandler(sfo, filepath.Join(*presentBaseDir, "js"), "jquery.js", "playground.js"))
+ r.Add("/<path:.+>").GetFunc(servePresentation)
+
+ h := web.NewHostRouter()
+ h.Add("talks.<:.*>", r)
+
+ r = web.NewRouter()
r.Add("/").GetFunc(serveHome)
r.Add("/-/about").GetFunc(serveAbout)
r.Add("/-/go").GetFunc(serveGoIndex)
r.Add("/-/index").GetFunc(serveIndex)
r.Add("/-/refresh").PostFunc(serveRefresh)
r.Add("/-/static/<path:.*>").Get(web.DirectoryHandler(filepath.Join(*baseDir, "static"), sfo))
- r.Add("/-/talk/<path:.+>").GetFunc(servePresentation)
r.Add("/robots.txt").Get(web.FileHandler(filepath.Join(*baseDir, "static", "robots.txt"), nil))
r.Add("/humans.txt").Get(web.FileHandler(filepath.Join(*baseDir, "static", "humans.txt"), nil))
r.Add("/favicon.ico").Get(web.FileHandler(filepath.Join(*baseDir, "static", "favicon.ico"), nil))
@@ -461,7 +484,8 @@ func main() {
r.Add("/a/index").Get(web.RedirectHandler("/-/index", 301))
r.Add("/C").Get(web.RedirectHandler("http://golang.org/doc/articles/c_go_cgo.html", 301))
r.Add("/<path:.+>").GetFunc(servePackage)
- h := web.ErrorHandler(handleError, web.FormAndCookieHandler(1000, false, r))
+
+ h.Add("<:.*>", web.ErrorHandler(handleError, web.FormAndCookieHandler(1000, false, r)))
listener, err := net.Listen("tcp", *httpAddr)
if err != nil {
View
@@ -398,10 +398,10 @@ var templates = map[string]interface {
Execute(io.Writer, interface{}) error
}{}
-func joinTemplateDir(files []string) []string {
+func joinTemplateDir(baseDir string, files []string) []string {
result := make([]string, len(files))
for i := range files {
- result[i] = filepath.Join(*baseDir, "template", files[i])
+ result[i] = filepath.Join(baseDir, "templates", files[i])
}
return result
}
@@ -431,7 +431,7 @@ func parseHTMLTemplates(sets [][]string) error {
"staticFile": staticFileFn,
"templateName": func() string { return templateName },
})
- if _, err := t.ParseFiles(joinTemplateDir(set)...); err != nil {
+ if _, err := t.ParseFiles(joinTemplateDir(*baseDir, set)...); err != nil {
return err
}
t = t.Lookup("ROOT")
@@ -449,7 +449,7 @@ func parseTextTemplates(sets [][]string) error {
t.Funcs(ttemp.FuncMap{
"comment": commentTextFn,
})
- if _, err := t.ParseFiles(joinTemplateDir(set)...); err != nil {
+ if _, err := t.ParseFiles(joinTemplateDir(*baseDir, set)...); err != nil {
return err
}
t = t.Lookup("ROOT")
@@ -461,24 +461,19 @@ func parseTextTemplates(sets [][]string) error {
return nil
}
+var presentTemplates = make(map[string]*htemp.Template)
+
func parsePresentTemplates(sets [][]string) error {
for _, set := range sets {
t := present.Template()
- t.Funcs(htemp.FuncMap{
- "gaAccount": gaAccountFn,
- "staticFile": staticFileFn,
- "elem": func(e present.Elem) (htemp.HTML, error) { return elemFn(t, e) },
- "headerLevel": headerLevelFn,
- "relativeTime": relativeTime,
- })
- if _, err := t.ParseFiles(joinTemplateDir(set)...); err != nil {
+ if _, err := t.ParseFiles(joinTemplateDir(*presentBaseDir, set[1:])...); err != nil {
return err
}
- t = t.Lookup("ROOT")
+ t = t.Lookup("root")
if t == nil {
- return fmt.Errorf("ROOT template not found in %v", set)
+ return fmt.Errorf("root template not found in %v", set)
}
- templates[set[0]] = t
+ presentTemplates[set[0]] = t
}
return nil
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit fbaa19e

Please sign in to comment.