• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang pongo2.Must函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/flosch/pongo2.Must函数的典型用法代码示例。如果您正苦于以下问题:Golang Must函数的具体用法?Golang Must怎么用?Golang Must使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Must函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestMisc

func (s *TestSuite) TestMisc(c *C) {
	// Must
	// TODO: Add better error message (see issue #18)
	c.Check(
		func() { pongo2.Must(testSuite2.FromFile("template_tests/inheritance/base2.tpl")) },
		PanicMatches,
		`\[Error \(where: fromfile\) in .*template_tests/inheritance/doesnotexist.tpl | Line 1 Col 12 near 'doesnotexist.tpl'\] open .*template_tests/inheritance/doesnotexist.tpl: no such file or directory`,
	)

	// Context
	c.Check(parseTemplateFn("", pongo2.Context{"'illegal": nil}), PanicMatches, ".*not a valid identifier.*")

	// Registers
	c.Check(func() { pongo2.RegisterFilter("escape", nil) }, PanicMatches, ".*is already registered.*")
	c.Check(func() { pongo2.RegisterTag("for", nil) }, PanicMatches, ".*is already registered.*")

	// ApplyFilter
	v, err := pongo2.ApplyFilter("title", pongo2.AsValue("this is a title"), nil)
	if err != nil {
		c.Fatal(err)
	}
	c.Check(v.String(), Equals, "This Is A Title")
	c.Check(func() {
		_, err := pongo2.ApplyFilter("doesnotexist", nil, nil)
		if err != nil {
			panic(err)
		}
	}, PanicMatches, `\[Error \(where: applyfilter\)\] Filter with name 'doesnotexist' not found.`)
}
开发者ID:henrylee2cn,项目名称:pongo2,代码行数:29,代码来源:pongo2_test.go


示例2: HomeHandler

func HomeHandler(rw http.ResponseWriter, r *http.Request) {
	session, _ := store.Get(r, cfg.SessionName)
	conf = &oauth2.Config{
		ClientID:     os.Getenv("GOOGLE_CLIENT_ID"),
		ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"),
		RedirectURL:  os.Getenv("GOOGLE_CLIENT_REDIRECT"),
		Scopes: []string{
			"https://www.googleapis.com/auth/plus.login",
			"https://www.googleapis.com/auth/userinfo.email",
			"https://www.googleapis.com/auth/userinfo.profile",
		},
		Endpoint: google.Endpoint,
	}

	if session.Values["googleId"] != nil {
		http.Redirect(rw, r, "/dashboard", 301)
	}
	// Generate google signin url with xsrf token
	url := conf.AuthCodeURL(session.Values["xsrf"].(string))
	tmpl := pongo2.Must(pongo2.FromFile("./templates/home.html"))
	err := tmpl.ExecuteWriter(pongo2.Context{"GoogleAuthUrl": url}, rw)

	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
	}
}
开发者ID:alfonsodev,项目名称:golang-web-seed,代码行数:26,代码来源:main.go


示例3: My

// 	if err != nil {
// 		http.Error(w, err.Error(), http.StatusInternalServerError)
// 	}
// }
func (this *ScheduleController) My() {
	w := this.ResponseWriter
	r := this.Request
	r.ParseForm()
	user := r.FormValue("user")

	page := u.Page{PageSize: 10, ShowPages: 5}

	currentPage := r.FormValue("page")

	log.Println("当前页数", currentPage)
	page.CurrentPage, _ = strconv.Atoi(currentPage)
	page.InitSkipRecords()

	log.Println("过滤多少页", page.SkipRecords)
	log.Println("总页数", page.TotalPages)
	order := m.Order{RUser: user}
	page = order.GetRuserOrders(page)
	page.InitTotalPages()

	context := pongo2.Context{"orderlist": page.Data}

	var tplExample = pongo2.Must(pongo2.FromFile("views/Schedule.my.tpl"))

	err := tplExample.ExecuteWriter(context, w)
	if err != nil {
		log.Println(err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
开发者ID:jjjachyty,项目名称:ibookings,代码行数:34,代码来源:Schedule.go


示例4: Instance

// Instance should return a new Pongo2Render struct per request and prepare
// the template by either loading it from disk or using pongo2's cache.
func (p Pongo2Render) Instance(name string, data interface{}) render.Render {
	var template *pongo2.Template
	filename := path.Join(p.Options.TemplateDir, name)

	// always read template files from disk if in debug mode, use cache otherwise.
	if gin.Mode() == "debug" {
		template = pongo2.Must(pongo2.FromFile(filename))
	} else {
		template = pongo2.Must(pongo2.FromCache(filename))
	}

	return Pongo2Render{
		Template: template,
		Context:  data.(pongo2.Context),
		Options:  p.Options,
	}
}
开发者ID:robvdl,项目名称:pongo2gin,代码行数:19,代码来源:render.go


示例5: renderTemplate

func (m Machine) renderTemplate(templateName string) (string, error) {
	var tpl = pongo2.Must(pongo2.FromFile(path.Join("templates", templateName)))
	result, err := tpl.Execute(pongo2.Context{"machine": m})
	if err != nil {
		return "", err
	}
	return result, err
}
开发者ID:doddo,项目名称:templetation,代码行数:8,代码来源:machine.go


示例6: Instance

func (p PongoDebug) Instance(name string, data interface{}) render.Render {
	t := pongo2.Must(pongo2.FromFile(path.Join(p.Path, name)))
	return Pongo{
		Template: t,
		Name:     name,
		Data:     data,
	}
}
开发者ID:stepan-perlov,项目名称:gin_pongo2,代码行数:8,代码来源:main.go


示例7: getFilledTemplate

// getFilledTemplate returns the filled template as a slice of bytes.
// Initially wanted to use here the stdlib's text/template but ran into issues
// with the if instruction.
// The template looks quite ugly because of the blank lines left by the tags.
// https://code.djangoproject.com/ticket/2594 (WONTFIX)
// https://github.com/flosch/pongo2/issues/94
func getFilledTemplate(ctxt pongo2.Context, tplFile string) ([]byte, error) {
	t := pongo2.Must(pongo2.FromFile(tplFile))
	output, err := t.ExecuteBytes(ctxt)
	if err != nil {
		log.Fatal(err)
	}
	return output, nil
}
开发者ID:jgautheron,项目名称:gocha,代码行数:14,代码来源:changelog.go


示例8: Instance

func (p Pongo2Common) Instance(name string, data interface{}) render.Render {
	tpl := pongo2.Must(pongo2.FromCache(path.Join(p.BasePath, name)))

	return &Pongo2{
		Template: tpl,
		Name:     name,
		Data:     data,
	}
}
开发者ID:daine46,项目名称:gin-pongo2,代码行数:9,代码来源:ginpon.go


示例9: main

func main() {
	kingpin.Parse()
	t := pongo2.Must(pongo2.FromFile(*templatePath))

	err := t.ExecuteWriter(getContext(), os.Stdout)
	if err != nil {
		panic(err)
	}
}
开发者ID:madedotcom,项目名称:pongo-blender,代码行数:9,代码来源:pongo-blender.go


示例10: handleViewer

func handleViewer(res http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	tplData, _ := Asset("viewer.html")
	tpl := pongo2.Must(pongo2.FromString(string(tplData)))
	tpl.ExecuteWriter(pongo2.Context{
		"ipfs_hash": vars["ipfs_hash"],
		"branding":  cfg.Branding,
	}, res)
}
开发者ID:Luzifer,项目名称:ipfs-markdown,代码行数:10,代码来源:main.go


示例11: DashboardHandler

func DashboardHandler(rw http.ResponseWriter, r *http.Request) {
	session, _ := store.Get(r, cfg.SessionName)
	tmpl := pongo2.Must(pongo2.FromFile("./templates/dash.html"))
	if session.Values["googleId"] != "" {
		err := tmpl.ExecuteWriter(pongo2.Context{"GoogleId": session.Values["googleId"]}, rw)
		if err != nil {
			panic(err)
		}
	}

}
开发者ID:alfonsodev,项目名称:golang-web-seed,代码行数:11,代码来源:main.go


示例12: Pongo2

func Pongo2() echo.MiddlewareFunc {
	return func(h echo.HandlerFunc) echo.HandlerFunc {
		return func(ctx *echo.Context) error {
			err := h(ctx)
			if err != nil {
				return err
			}
			templateName := ctx.Get("template")
			if templateName == nil {
				http.Error(
					ctx.Response().Writer(),
					"Template in Context not defined.",
					500)
			}
			var contentType, encoding string
			var isString bool
			ct := ctx.Get("ContentType")
			if ct == nil {
				contentType = ContentHTML
			} else {
				contentType, isString = ct.(string)
				if !isString {
					contentType = ContentHTML
				}
			}
			cs := ctx.Get("charset")
			if cs == nil {
				encoding = defaultCharset
			} else {
				encoding, isString = cs.(string)
				if !isString {
					encoding = defaultCharset
				}
			}
			newContentType := contentType + "; charset=" + encoding
			templateNameValue, isString := templateName.(string)
			if isString {
				templateData := ctx.Get("data")
				var template = pongo2.Must(pongo2.FromFile(path.Join("templates", templateNameValue)))
				ctx.Response().Header().Set(ContentType, newContentType)
				err = template.ExecuteWriter(
					getContext(templateData), ctx.Response().Writer())
				if err != nil {
					http.Error(
						ctx.Response().Writer(), err.Error(), 500)
				}
			}
			return nil
		}
	}
}
开发者ID:gocore,项目名称:echo-pongo2,代码行数:51,代码来源:pongo2.go


示例13: renderTemplate

// Render template among with machine and config struct
func (m Machine) renderTemplate(template string, config Config) (string, error) {

	template = path.Join(config.TemplatePath, template)
	if _, err := os.Stat(template); err != nil {
		return "", errors.New("Template does not exist")
	}

	var tpl = pongo2.Must(pongo2.FromFile(template))
	result, err := tpl.Execute(pongo2.Context{"machine": m, "config": config})
	if err != nil {
		return "", err
	}
	return result, err
}
开发者ID:xnaveira,项目名称:waitron,代码行数:15,代码来源:machine.go


示例14: handleHelpPage

func handleHelpPage(res http.ResponseWriter, r *http.Request) {
	content, err := ioutil.ReadFile("frontend/help.md")
	if err != nil {
		log.WithFields(logrus.Fields{
			"error": fmt.Sprintf("%v", err),
		}).Error("HelpText Load")
		http.Error(res, "An unknown error occured.", http.StatusInternalServerError)
		return
	}

	template := pongo2.Must(pongo2.FromFile("frontend/help.html"))
	ctx := getBasicContext(res, r)
	ctx["helptext"] = string(content)

	template.ExecuteWriter(ctx, res)
}
开发者ID:golang-lib,项目名称:gobuilder,代码行数:16,代码来源:static.go


示例15: Render

// Renders a template
func (t *Templating) Render(context Context, name string) {
	var filename = fmt.Sprintf("%s/%s", t.GetViewsDirectory(), name)

	if _, err := os.Stat(filename); err != nil {
		if os.IsNotExist(err) {
			log.Printf("View '%s' does not exists", filename)
			os.Exit(1)
		}
	}

	var template = pongo2.Must(pongo2.FromFile(filename))
	template.ExecuteWriter(pongo2.Context{
		"request":  context.GetRequest(),
		"response": context.GetResponse(),
	}, context.GetResponse())
}
开发者ID:3lect,项目名称:gofast,代码行数:17,代码来源:templating.go


示例16: Pongo2

func Pongo2() HandlerFunc {
	return func(c *Context) {
		c.Next()

		templateName, templateNameError := c.Get("template")
		templateNameValue, isString := templateName.(string)

		if templateNameError == nil && isString {
			templateData, templateDataError := c.Get("data")
			var template = pongo2.Must(pongo2.FromCache(templateNameValue))
			err := template.ExecuteWriter(getContext(templateData, templateDataError), c.Writer)
			if err != nil {
				http.Error(c.Writer, err.Error(), http.StatusInternalServerError)
			}
		}
	}
}
开发者ID:mehcode,项目名称:ginpongo2,代码行数:17,代码来源:middleware.go


示例17: compileTemplates

func (copter *Copter) compileTemplates() {
	dir := copter.options.Directory

	filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
		rel, err := filepath.Rel(dir, path)
		if err != nil {
			return err
		}

		ext := filepath.Ext(path)

		for _, extension := range copter.options.Extensions {
			if ext == extension {
				name := (rel[0 : len(rel)-len(ext)])
				pongo2.Must(copter.Set.FromCache(filepath.ToSlash(name) + ext))
				break
			}
		}

		return nil
	})
}
开发者ID:plirr,项目名称:copter,代码行数:22,代码来源:copter.go


示例18: NewPongo2ReportRunnerFromString

// NewPongo2ReportRunnerFromString constructor with template string
func NewPongo2ReportRunnerFromString(TemplateString string) *Pongo2ReportRunner {
	var template = pongo2.Must(pongo2.FromString(TemplateString))
	return &Pongo2ReportRunner{
		Template: *template,
	}
}
开发者ID:cfpb,项目名称:rhobot,代码行数:7,代码来源:runner.go


示例19: NewPongo2ReportRunnerFromFile

// NewPongo2ReportRunnerFromFile constructor with template file
func NewPongo2ReportRunnerFromFile(TemplateFilePath string) *Pongo2ReportRunner {
	var template = pongo2.Must(pongo2.FromFile(TemplateFilePath))
	return &Pongo2ReportRunner{
		Template: *template,
	}
}
开发者ID:cfpb,项目名称:rhobot,代码行数:7,代码来源:runner.go


示例20: Write

type NullWriter int

func (NullWriter) Write([]byte) (int, error) {
	return 0, nil
}

type SignatureRequest struct {
	hash      string
	generator generators.BaseGenerator
}

var (
	imageRoot      = "images"
	publicPath     = "public/"
	updateInterval = 10.0
	indexTemplate  = pongo2.Must(pongo2.FromFile("templates/index.tpl"))
)

func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())
}

func createAndSaveSignature(writer http.ResponseWriter, req util.SignatureRequest, generator generators.BaseGenerator) error {
	// Create the signature image
	sig, err := generator.CreateSignature(req.Req)
	if err != nil {
		return err
	}

	// note: queue saving if it causes performance issues?
	// Save the image to disk with the given hash as the file name
开发者ID:cubeee,项目名称:go-sig,代码行数:31,代码来源:web.go



注:本文中的github.com/flosch/pongo2.Must函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang pongo2.MustNewLocalFileSystemLoader函数代码示例发布时间:2022-05-23
下一篇:
Golang pongo2.FromString函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap