-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from lukasjarosch/40-partial-templates
Partial Template Support
- Loading branch information
Showing
13 changed files
with
777 additions
and
8 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
examples/partial_templates/compiled/example/_partials/no_data.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
1 change: 1 addition & 0 deletions
1
examples/partial_templates/compiled/example/_partials/with_data.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# main template | ||
|
||
--- | ||
|
||
|
||
|
||
this partial does not use any data | ||
|
||
|
||
|
||
--- | ||
|
||
{network: | ||
foo: bar | ||
skipper: | ||
use: | ||
- network | ||
example} | ||
|
||
--- | ||
|
||
|
||
|
||
# example | ||
|
||
``` | ||
foo: bar | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module github.com/lukasjarosch/skipper/examples/partial_tempaltes | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/lukasjarosch/skipper v0.0.0-20221027074243-61e46553f948 | ||
github.com/spf13/afero v1.10.0 | ||
) | ||
|
||
replace github.com/lukasjarosch/skipper => ../../ | ||
|
||
require ( | ||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0 // indirect | ||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 // indirect | ||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect | ||
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys v0.10.0 // indirect | ||
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.1 // indirect | ||
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.0 // indirect | ||
github.com/Masterminds/goutils v1.1.1 // indirect | ||
github.com/Masterminds/semver/v3 v3.2.1 // indirect | ||
github.com/Masterminds/sprig/v3 v3.2.3 // indirect | ||
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect | ||
github.com/google/uuid v1.3.1 // indirect | ||
github.com/huandu/xstrings v1.4.0 // indirect | ||
github.com/imdario/mergo v0.3.16 // indirect | ||
github.com/kylelemons/godebug v1.1.0 // indirect | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect | ||
github.com/shopspring/decimal v1.3.1 // indirect | ||
github.com/spf13/cast v1.5.1 // indirect | ||
golang.org/x/crypto v0.14.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
network: | ||
foo: bar |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
target: | ||
skipper: | ||
use: | ||
- network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"path" | ||
|
||
"github.com/lukasjarosch/skipper" | ||
"github.com/spf13/afero" | ||
) | ||
|
||
var ( | ||
fileSystem = afero.NewOsFs() | ||
inventoryPath = "inventory" | ||
classPath = path.Join(inventoryPath, "classes") | ||
targetPath = path.Join(inventoryPath, "targets") | ||
secretPath = path.Join(inventoryPath, "secrets") | ||
templatePath = path.Join(inventoryPath, "..", "templates") | ||
outputPath = "compiled" | ||
|
||
target = "example" | ||
) | ||
|
||
func main() { | ||
inventory, err := skipper.NewInventory(fileSystem, classPath, targetPath, secretPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Process the inventory, given the target name | ||
data, err := inventory.Data(target, nil, false, false) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
templateOutputPath := path.Join(outputPath, target) | ||
templater, err := skipper.NewTemplater(fileSystem, templatePath, templateOutputPath, nil, []string{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
skipperConfig, err := inventory.GetSkipperConfig(target) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// execute templates ---------------------------------------------------------------------------------- | ||
err = templater.ExecuteAll(skipper.DefaultTemplateContext(data, target), false, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// copy files as specified in the target config (base path is template root) | ||
err = skipper.CopyFilesByConfig(fileSystem, skipperConfig.Copies, templatePath, templateOutputPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{ define "no_data" }} | ||
|
||
this partial does not use any data | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{ define "with_data" }} | ||
|
||
# {{ .TargetName }} | ||
|
||
``` | ||
{{ .Network }} | ||
``` | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# main template | ||
|
||
--- | ||
|
||
{{ template "no_data" }} | ||
|
||
--- | ||
|
||
{{ . }} | ||
|
||
--- | ||
|
||
{{ template "with_data" context "TargetName" .TargetName "Network" .Inventory.network }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters