Skip to content

Commit

Permalink
Merge pull request #1 from home-assistant/fix-template-name
Browse files Browse the repository at this point in the history
Fix template name
  • Loading branch information
pvizeli authored Oct 28, 2020
2 parents 851ad41 + 63bb34c commit 7b03fd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Plugin Observare",
"name": "TempIO",
"build": {
"dockerfile": "Dockerfile",
"args": {
Expand Down
15 changes: 11 additions & 4 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"io/ioutil"
"log"
"strings"
"text/template"
Expand All @@ -15,18 +16,24 @@ func JoinString(a []interface{}, delimiter string) string {
return strings.Join(paramSlice, delimiter)
}

func renderTemplateFile(config *map[string]interface{}, coreFile string) []byte {
func renderTemplateFile(config *map[string]interface{}, file string) []byte {
buf := &bytes.Buffer{}

// read Template
templateFile, err := ioutil.ReadFile(file)
if err != nil {
log.Fatal(err)
}

// helper
funcMap := template.FuncMap{"JoinString": JoinString}

// generate template
coreTemplate := template.New("tempio").Funcs(funcMap)
template.Must(coreTemplate.ParseFiles(coreFile))
coreTemplate := template.New("tempIO").Funcs(funcMap)
template.Must(coreTemplate.Parse(string(templateFile)))

// render
err := coreTemplate.Execute(buf, *config)
err = coreTemplate.Execute(buf, *config)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 7b03fd4

Please sign in to comment.