mirror of
https://github.com/lxc/distrobuilder.git
synced 2026-02-05 15:46:17 +01:00
42 lines
851 B
Go
42 lines
851 B
Go
package generators
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/lxc/distrobuilder/shared"
|
|
)
|
|
|
|
type common struct {
|
|
logger *logrus.Logger
|
|
cacheDir string
|
|
sourceDir string
|
|
defFile shared.DefinitionFile
|
|
}
|
|
|
|
func (g *common) init(logger *logrus.Logger, cacheDir string, sourceDir string, defFile shared.DefinitionFile, def shared.Definition) {
|
|
g.logger = logger
|
|
g.cacheDir = cacheDir
|
|
g.sourceDir = sourceDir
|
|
g.defFile = defFile
|
|
|
|
render := func(val string) string {
|
|
if !defFile.Pongo {
|
|
return val
|
|
}
|
|
|
|
out, err := shared.RenderTemplate(val, def)
|
|
if err != nil {
|
|
logger.WithField("err", err).Warn("Failed to render template")
|
|
return val
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
if defFile.Pongo {
|
|
g.defFile.Content = render(g.defFile.Content)
|
|
g.defFile.Path = render(g.defFile.Path)
|
|
g.defFile.Source = render(g.defFile.Source)
|
|
}
|
|
}
|