Esempio n. 1
0
func init_templates() {
	root := config.Server["templates"]
	templates["index.html"] = pongo.Must(pongo.FromFile(path.Join(root, "index.html"), nil))
	templates["about.html"] = pongo.Must(pongo.FromFile(path.Join(root, "about.html"), nil))
	templates["history.html"] = pongo.Must(pongo.FromFile(path.Join(root, "history.html"), nil))
	templates["add/page.html"] = pongo.Must(pongo.FromFile(path.Join(root, "add/page.html"), nil))
	templates["add/group.html"] = pongo.Must(pongo.FromFile(path.Join(root, "add/group.html"), nil))
}
Esempio n. 2
0
func (w Wrapper) RenderWithVars(p string, vars TemplateVars) {
	w.Res.Header().Add("Content-type", "text/html")

	tplFile := path.Join(w.App.ViewsRoot, p)

	var tpl *pongo.Template
	if val, ok := tplCache[tplFile]; ok {
		tpl = val
	} else {
		tpl = pongo.Must(pongo.FromFile(tplFile, nil))
	}

	var context = pongo.Context{
		"session": w.Session,
	}

	for k, v := range vars {
		context[k] = v
	}

	out, err := tpl.Execute(&context)
	if err != nil {
		panic(err)
	}
	w.Write(*out)
}
Esempio n. 3
0
func (tpl *DjangoTpl) Display(template string) {
	var tplExample = pongo.Must(pongo.FromFile(template, nil))
	err := tplExample.ExecuteRW(tpl.w, &tpl.ctx)
	if err != nil {
		http.Error(tpl.w, err.Error(), http.StatusInternalServerError)
	}
}
Esempio n. 4
0
/**
 * Handles request for section
 */
func handlePaginatedSection(ctx *web.Context, section string, page string) string {
	config, err := getConfig()
	if err != nil {
		ctx.Abort(500, "Configuration error.")
		return ""
	}
	tpl := pongo.Must(pongo.FromFile(config.TemplateFolder+"/template.html", nil))
	var content, output string
	p, _ := strconv.Atoi(page)
	output, err = getAbstracts(section, p, &config)
	if err != nil {
		ctx.Abort(404, "Page not found. Could not load abstracts")
		return ""
	}
	content = string(blackfriday.MarkdownCommon([]byte(output)))
	menu, err := getMenu(&config)
	if err != nil {
		ctx.Abort(501, "Could not load menu")
		return ""
	}
	var response *string
	response, err = tpl.Execute(&pongo.Context{"content": content, "menu": menu,
		"currentMenu": menu.GetCurrent(section)})
	if err != nil {
		ctx.Abort(501, "")
		return err.Error()
	}
	return *response
}
Esempio n. 5
0
func run_server() error {
	tpl_root = path.Join(configuration.Templates.Path, "templates/")
	templates["index.html"] = pongo.Must(pongo.FromFile(path.Join(tpl_root, "index.html"), nil))

	svr := fmt.Sprintf("%s:%d", configuration.Server.Bind, configuration.Server.Port)
	fmt.Printf("Shortly is listening on %s\n", svr)

	http.HandleFunc("/", root_handler)
	http.HandleFunc("/api/", api_handler)
	http.HandleFunc("/app/", app_handler)

	// Static assets
	media := path.Join(configuration.Templates.Path, "assets/")
	http.Handle("/media/",
		http.StripPrefix("/media/", http.FileServer(http.Dir(media))))

	http.ListenAndServe(svr, nil)

	return nil
}
Esempio n. 6
0
File: pongo.go Progetto: murz/ego
func (te *PongoTemplateEngine) Compile(t string) CompiledTemplate {
	return PongoTemplate{
		tmpl: pongo.Must(pongo.FromFile(t, nil)),
	}
}