示例#1
0
文件: faker.go 项目: rfsbraz/faker
func (faker *Faker) Execute(category, path string) string {
	//We create a template from the required category
	tmpl, err := template.New("t").Parse(data.Load(category, faker.Locale, faker.FallbackLocale, path))

	if err != nil {
		panic(err)
	}

	var buffer bytes.Buffer

	// Execute the first template
	err = tmpl.Execute(&buffer, faker)

	if err != nil {
		panic(err)
	}

	// We iterate trough the string, and process all remaining templates
	//todo: better template detection
	for ; strings.Contains(buffer.String(), "{{"); tmpl, err = template.New("t").Parse(buffer.String()) {
		buffer.Reset()

		// Execute the new template
		err = tmpl.Execute(&buffer, faker)

		if err != nil {
			panic(err)
		}
	}

	return buffer.String()
}
示例#2
0
文件: faker.go 项目: rfsbraz/faker
func (faker *Faker) LoadFrom(path, category string) string {
	return data.Load(category, faker.Locale, faker.FallbackLocale, path)
}