コード例 #1
0
ファイル: views.go プロジェクト: rossjones/golemwiki
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))
}
コード例 #2
0
ファイル: wrapper.go プロジェクト: schleumer/go-mvc
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)
}
コード例 #3
0
ファイル: django.go プロジェクト: vuleetu/gorouter
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)
	}
}
コード例 #4
0
ファイル: site.go プロジェクト: rredpoppy/gosite
/**
 * 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
}
コード例 #5
0
ファイル: helper.go プロジェクト: NovemberFoxtrot/jedie
func include(cfg *config, vars pongo.Context) func(*string) (*string, error) {
	return func(loc *string) (*string, error) {
		inc := filepath.ToSlash(filepath.Join(cfg.includes, *loc))
		tpl, err := pongo.FromFile(inc, include(cfg, vars))
		if err != nil {
			return nil, err
		}
		return tpl.Execute(&vars)
	}
}
コード例 #6
0
ファイル: template.go プロジェクト: sfreiberg/shepherd
func (t *Template) CreateTemplate() (string, error) {
	tpl, err := pongo.FromFile(t.Source, nil)
	if err != nil {
		return "", err
	}
	ctx := pongo.Context(t.Context)
	out, err := tpl.Execute(&ctx)
	if err != nil {
		return "", err
	}
	return *out, nil
}
コード例 #7
0
ファイル: views.go プロジェクト: rossjones/golemwiki
func renderTemplate(tmpl string, ctx pongo.Context, w http.ResponseWriter) {
	//err := templates[tmpl].ExecuteRW(w, &ctx)
	t, err := pongo.FromFile(path.Join(config.Server["templates"], tmpl), nil)
	//err := templates[tmpl].ExecuteRW(w, &ctx)

	// Add some general items to context from the config
	for k, v := range config.Wiki {
		ctx["_"+k] = v
	}

	ctx["_groups"] = get_all_groups()
	err = t.ExecuteRW(w, &ctx)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
コード例 #8
0
ファイル: server.go プロジェクト: rossjones/shortly
func renderTemplate(tmpl string, ctx pongo.Context, w http.ResponseWriter) {
	// When in debug, we will load the templates each time so we can modify them
	// without restarting
	if configuration.App.Debug {
		t, err := pongo.FromFile(path.Join(tpl_root, tmpl), nil)
		err = t.ExecuteRW(w, &ctx)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		return
	}

	err := templates[tmpl].ExecuteRW(w, &ctx)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
コード例 #9
0
ファイル: server.go プロジェクト: rossjones/shortly
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
}
コード例 #10
0
ファイル: pongo.go プロジェクト: murz/ego
func (te *PongoTemplateEngine) Compile(t string) CompiledTemplate {
	return PongoTemplate{
		tmpl: pongo.Must(pongo.FromFile(t, nil)),
	}
}