Пример #1
0
func compileTemplateFromFile(context *pongo2.Context, file *string) (*string, error) {
	log.Debug("  Compiling template:\n    %s", *file)

	source, err := util.LoadFileAsString(*file)
	if err != nil {
		log.Error("Error loading template source:\n  %s", *file)
		return nil, err
	}
	log.Trace("-- %s --\n%s\n----", "source", *source)

	return compileTemplateFromString(context, source)
}
Пример #2
0
func loadEnvironment(projectPath string) (*data.Environment, *string, error) {
	// YAML doesn't like the Pongo2 syntax, so we need to do the project file parsing in 2 steps
	log.Debug("  Loading project file as plain string")
	source, err := util.LoadFileAsString(projectPath)
	if err != nil {
		log.Debug("Error loading project from:\n  %s", projectPath)
		return nil, nil, err
	}
	log.Trace("-- %s --\n%s\n----", "project source", *source)

	// Extract data section from project file
	log.Debug("  Extracting environment data")

	environmentSource := regexExtractEnvironment.FindString(*source)
	log.Trace("-- %s --\n%s\n----", "environment source", environmentSource)

	var tmpProject data.Project
	if err := util.LoadYAMLFromString(environmentSource, &tmpProject); err != nil {
		log.Debug("Error parsing environment data from file:\n  %s", projectPath)
		return nil, nil, err
	}

	return &tmpProject.Environment, source, nil
}