Example #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)
}
Example #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
}
Example #3
0
func compileTemplateFromString(context *pongo2.Context, source *string) (*string, error) {
	template, err := pongo2.FromString(*source)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Error building template from source\nerror:\n  %s", err.Error()))
	}

	compiled, err := template.Execute(*context)
	if err != nil {
		log.Error("Error loading template from source\n\nerror:\n  %s", err.Error())
		return nil, err
	} else {
		log.Trace("-- %s --\n%s\n----", "compiled", compiled)
		return &compiled, nil
	}
}