Skip to content

Commit

Permalink
Add template to binary by using go-bindata
Browse files Browse the repository at this point in the history
  • Loading branch information
mono0926 committed Jun 29, 2015
1 parent 61f4f4e commit aa720d7
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 6 deletions.
287 changes: 287 additions & 0 deletions bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,18 @@ func doGenerate(c *cli.Context) {
log.Println("invalid license line")
continue
}
s := generator.GenerateLicense("template/License.plist", name, body)
licenseData, e := Asset("template/License.plist")
assert(e)
s := generator.GenerateLicense(string(licenseData), name, body)
log.Println(s)
ioutil.WriteFile(fmt.Sprintf("%s/%s.plist", outDir, name), []byte(s), 0644)
names = append(names, name)
}
s := generator.GenerateLicenseList("template/LicenseList.plist", "template/LicenseListItem.plist", names)
listData, e := Asset("template/LicenseList.plist")
assert(e)
itemData, e := Asset("template/LicenseListItem.plist")
assert(e)
s := generator.GenerateLicenseList(string(listData), string(itemData), names)
log.Println(s)
ioutil.WriteFile(fmt.Sprintf("%s/LicenseList.plist", outDir), []byte(s), 0644)
}
9 changes: 5 additions & 4 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ func GenerateLicenseList(listPath string, itemPath string, names []string) strin
return generateImpl(listPath, i)
}

func GenerateLicense(t string, title string, body string) string {
func GenerateLicense(src string, title string, body string) string {
l := License{title, body}
return generateImpl(t, l)
return generateImpl(src, l)
}

func generateImpl(t string, item interface{}) string {
tpl := template.Must(template.ParseFiles(t))
func generateImpl(src string, item interface{}) string {
tpl := template.New("template")
tpl.Parse(src)
var b bytes.Buffer
tpl.Execute(&b, item)
s := b.String()
Expand Down
Binary file modified ios-license-generator
Binary file not shown.

0 comments on commit aa720d7

Please sign in to comment.