mirror of
https://github.com/strongdm/comply
synced 2025-12-06 14:24:12 +00:00
Initial commit
This commit is contained in:
52
internal/theme/theme.go
Normal file
52
internal/theme/theme.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package theme
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/template"
|
||||
)
|
||||
|
||||
// SaveTo persists a compliance theme to a destination directory with optional
|
||||
// template value replacements.
|
||||
func SaveTo(themeName string, replace map[string]string, saveDir string) error {
|
||||
for _, name := range AssetNames() {
|
||||
prefix := themeName + "/"
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
outputName := strings.TrimPrefix(name, prefix)
|
||||
assetDir, assetFilename := filepath.Split(outputName)
|
||||
err := os.MkdirAll(filepath.Join(saveDir, assetDir), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// special case for README.md and TODO.md: all other templates
|
||||
// are passed copied verbatim.
|
||||
if name == filepath.Join(themeName, "README.md") || name == filepath.Join(themeName, "TODO.md") {
|
||||
rootMdFile := string(MustAsset(name))
|
||||
|
||||
var w bytes.Buffer
|
||||
rootMdFileTemplate, err := template.New("rootMdFile").Parse(rootMdFile)
|
||||
if err != nil {
|
||||
w.WriteString(fmt.Sprintf("# Error processing template:\n\n%s\n", err.Error()))
|
||||
} else {
|
||||
rootMdFileTemplate.Execute(&w, replace)
|
||||
}
|
||||
body := w.String()
|
||||
err = ioutil.WriteFile(filepath.Join(saveDir, assetDir, assetFilename), []byte(body), os.FileMode(0644))
|
||||
} else {
|
||||
err = ioutil.WriteFile(filepath.Join(saveDir, assetDir, assetFilename), MustAsset(name), os.FileMode(0644))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
1489
internal/theme/themes_bindata.go
Normal file
1489
internal/theme/themes_bindata.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user