當前位置: 首頁>>代碼示例>>Golang>>正文


Golang pongo2.MustNewLocalFileSystemLoader函數代碼示例

本文整理匯總了Golang中github.com/flosch/pongo2.MustNewLocalFileSystemLoader函數的典型用法代碼示例。如果您正苦於以下問題:Golang MustNewLocalFileSystemLoader函數的具體用法?Golang MustNewLocalFileSystemLoader怎麽用?Golang MustNewLocalFileSystemLoader使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MustNewLocalFileSystemLoader函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestBaseDirectory

func TestBaseDirectory(t *testing.T) {
	mustStr := "Hello from template_tests/base_dir_test/"

	fs := pongo2.MustNewLocalFileSystemLoader("")
	s := pongo2.NewSet("test set with base directory", fs)
	s.Globals["base_directory"] = "template_tests/base_dir_test/"
	if err := fs.SetBaseDir(s.Globals["base_directory"].(string)); err != nil {
		t.Fatal(err)
	}

	matches, err := filepath.Glob("./template_tests/base_dir_test/subdir/*")
	if err != nil {
		t.Fatal(err)
	}
	for _, match := range matches {
		if "windows" == runtime.GOOS {
			match = strings.Replace(match, "template_tests\\base_dir_test\\", "", -1)
		} else {
			match = strings.Replace(match, "template_tests/base_dir_test/", "", -1)
		}

		tpl, err := s.FromFile(match)
		if err != nil {
			t.Fatal(err)
		}
		out, err := tpl.Execute(nil)
		if err != nil {
			t.Fatal(err)
		}
		if out != mustStr {
			t.Errorf("%s: out ('%s') != mustStr ('%s')", match, out, mustStr)
		}
	}
}
開發者ID:runner-mei,項目名稱:pongo2,代碼行數:34,代碼來源:pongo2_template_test.go

示例2: BenchmarkCache

func BenchmarkCache(b *testing.B) {
	cacheSet := pongo2.NewSet("cache set", pongo2.MustNewLocalFileSystemLoader(""))
	for i := 0; i < b.N; i++ {
		tpl, err := cacheSet.FromCache("template_tests/complex.tpl")
		if err != nil {
			b.Fatal(err)
		}
		err = tpl.ExecuteWriterUnbuffered(tplContext, ioutil.Discard)
		if err != nil {
			b.Fatal(err)
		}
	}
}
開發者ID:runner-mei,項目名稱:pongo2,代碼行數:13,代碼來源:pongo2_template_test.go

示例3: BenchmarkExecuteComplexWithoutSandbox

func BenchmarkExecuteComplexWithoutSandbox(b *testing.B) {
	s := pongo2.NewSet("set without sandbox", pongo2.MustNewLocalFileSystemLoader(""))
	tpl, err := s.FromFile("template_tests/complex.tpl")
	if err != nil {
		b.Fatal(err)
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		err = tpl.ExecuteWriterUnbuffered(tplContext, ioutil.Discard)
		if err != nil {
			b.Fatal(err)
		}
	}
}
開發者ID:runner-mei,項目名稱:pongo2,代碼行數:14,代碼來源:pongo2_template_test.go

示例4: BenchmarkParallelExecuteComplexWithoutSandbox

func BenchmarkParallelExecuteComplexWithoutSandbox(b *testing.B) {
	s := pongo2.NewSet("set without sandbox", pongo2.MustNewLocalFileSystemLoader(""))
	tpl, err := s.FromFile("template_tests/complex.tpl")
	if err != nil {
		b.Fatal(err)
	}
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			err := tpl.ExecuteWriterUnbuffered(tplContext, ioutil.Discard)
			if err != nil {
				b.Fatal(err)
			}
		}
	})
}
開發者ID:runner-mei,項目名稱:pongo2,代碼行數:16,代碼來源:pongo2_template_test.go

示例5: BenchmarkCompileAndExecuteComplexWithoutSandbox

func BenchmarkCompileAndExecuteComplexWithoutSandbox(b *testing.B) {
	buf, err := ioutil.ReadFile("template_tests/complex.tpl")
	if err != nil {
		b.Fatal(err)
	}
	preloadedTpl := string(buf)

	s := pongo2.NewSet("set without sandbox", pongo2.MustNewLocalFileSystemLoader(""))

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		tpl, err := s.FromString(preloadedTpl)
		if err != nil {
			b.Fatal(err)
		}

		err = tpl.ExecuteWriterUnbuffered(tplContext, ioutil.Discard)
		if err != nil {
			b.Fatal(err)
		}
	}
}
開發者ID:runner-mei,項目名稱:pongo2,代碼行數:22,代碼來源:pongo2_template_test.go

示例6: Test

	"github.com/flosch/pongo2"

	. "gopkg.in/check.v1"
)

// Hook up gocheck into the "go test" runner.

func Test(t *testing.T) { TestingT(t) }

type TestSuite struct {
	tpl *pongo2.Template
}

var (
	_          = Suite(&TestSuite{})
	testSuite2 = pongo2.NewSet("test suite 2", pongo2.MustNewLocalFileSystemLoader(""))
)

func parseTemplate(s string, c pongo2.Context) string {
	t, err := testSuite2.FromString(s)
	if err != nil {
		panic(err)
	}
	out, err := t.Execute(c)
	if err != nil {
		panic(err)
	}
	return out
}

func parseTemplateFn(s string, c pongo2.Context) func() {
開發者ID:henrylee2cn,項目名稱:pongo2,代碼行數:31,代碼來源:pongo2_test.go

示例7:

			Expect(err).ToNot(HaveOccurred())
			Expect(string(out)).To(ContainSubstring("Example login page"))
			Expect(string(out)).To(ContainSubstring("<title>"))
			Expect(string(out)).To(ContainSubstring("/login"))
		})
	})

	Context("Fallback loading works", func() {
		var (
			loader      pongo2.TemplateLoader
			templateSet *pongo2.TemplateSet
		)

		BeforeEach(func() {
			defaultLoader := pongo2.MustNewLocalFileSystemLoader("")

			loader = NewMemoryTemplateLoaderWithFallback(overwrite_test.Asset, defaultLoader)
			templateSet = pongo2.NewSet("testing", loader)
		})

		It("should be validly parsed", func() {
			fallbackTemplate, err := templateSet.FromFile("fallback/file.tpl")
			Expect(err).ToNot(HaveOccurred())

			out, err := fallbackTemplate.Execute(pongo2.Context{})

			Expect(err).ToNot(HaveOccurred())
			Expect(string(out)).To(ContainSubstring("fallback"))

			originalTemplate, err := templateSet.FromFile("file.tpl")
開發者ID:sharpner,項目名稱:pobin,代碼行數:30,代碼來源:loader_test.go


注:本文中的github.com/flosch/pongo2.MustNewLocalFileSystemLoader函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。