Skip to content

Commit ad6e0f6

Browse files
committed
added error to AddPage
1 parent c851d5d commit ad6e0f6

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

_example/basic/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ func main() {
6565
funcs := template.FuncMap{}
6666

6767
tpl := tulkki.New(baseHTML, funcs)
68-
tpl.AddPage(`testpage`, testPageHTML, pagetranslations)
68+
err := tpl.AddPage(`testpage`, testPageHTML, pagetranslations)
69+
if err != nil {
70+
panic(err)
71+
}
6972

7073
// Generate a page template
7174
page := exampleBase{
@@ -77,7 +80,7 @@ func main() {
7780

7881
// Render the HTML
7982
var tmp bytes.Buffer
80-
err := tpl.Render(&tmp, `testpage`, useLanguage, page)
83+
err = tpl.Render(&tmp, `testpage`, useLanguage, page)
8184
if err != nil {
8285
panic(err)
8386
}

lib.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func New(baseContents string, funcs template.FuncMap) *Template {
5454
// Translations are per-page for collision reasons.
5555
// If you need access to translation tokens which are used globally,
5656
// simply inject them to the catalog before page specific tokens.
57-
func (t *Template) AddPage(name string, contents string, translations catalog.Catalog) {
57+
func (t *Template) AddPage(name string, contents string, translations catalog.Catalog) error {
5858
langlist := translations.Languages()
5959

6060
if len(langlist) == 0 {
61-
panic(`no languages found`)
61+
return fmt.Errorf(`no languages found`)
6262
}
6363

6464
for _, l := range langlist {
@@ -74,6 +74,8 @@ func (t *Template) AddPage(name string, contents string, translations catalog.Ca
7474
contents: contents,
7575
trcat: translations,
7676
}
77+
78+
return nil
7779
}
7880

7981
func (t *Template) getPageTemplate(templatename string) (p page, err error) {

0 commit comments

Comments
 (0)