Skip to content

Commit

Permalink
feat: expose courier template load
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Dec 23, 2021
1 parent 9cb1810 commit 3f374a6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions courier/template/load_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func loadTemplate(osdir, name, pattern string, html bool) (Template, error) {
return tpl, nil
}

func loadTextTemplate(osdir, name, pattern string, model interface{}) (string, error) {
func LoadTextTemplate(osdir, name, pattern string, model interface{}) (string, error) {
t, err := loadTemplate(osdir, name, pattern, false)
if err != nil {
return "", err
Expand All @@ -117,7 +117,7 @@ func loadTextTemplate(osdir, name, pattern string, model interface{}) (string, e
return b.String(), nil
}

func loadHTMLTemplate(osdir, name, pattern string, model interface{}) (string, error) {
func LoadHTMLTemplate(osdir, name, pattern string, model interface{}) (string, error) {
t, err := loadTemplate(osdir, name, pattern, true)
if err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions courier/template/load_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (

func TestLoadTextTemplate(t *testing.T) {
var executeTextTemplate = func(t *testing.T, dir, name, pattern string, model map[string]interface{}) string {
tp, err := loadTextTemplate(dir, name, pattern, model)
tp, err := LoadTextTemplate(dir, name, pattern, model)
require.NoError(t, err)
return tp
}

var executeHTMLTemplate = func(t *testing.T, dir, name, pattern string, model map[string]interface{}) string {
tp, err := loadHTMLTemplate(dir, name, pattern, model)
tp, err := LoadHTMLTemplate(dir, name, pattern, model)
require.NoError(t, err)
return tp
}
Expand Down
6 changes: 3 additions & 3 deletions courier/template/recovery_invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ func (t *RecoveryInvalid) EmailRecipient() (string, error) {
}

func (t *RecoveryInvalid) EmailSubject() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/invalid/email.subject.gotmpl", "recovery/invalid/email.subject*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/invalid/email.subject.gotmpl", "recovery/invalid/email.subject*", t.m)
}

func (t *RecoveryInvalid) EmailBody() (string, error) {
return loadHTMLTemplate(t.c.CourierTemplatesRoot(), "recovery/invalid/email.body.gotmpl", "recovery/invalid/email.body*", t.m)
return LoadHTMLTemplate(t.c.CourierTemplatesRoot(), "recovery/invalid/email.body.gotmpl", "recovery/invalid/email.body*", t.m)
}

func (t *RecoveryInvalid) EmailBodyPlaintext() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/invalid/email.body.plaintext.gotmpl", "recovery/invalid/email.body.plaintext*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/invalid/email.body.plaintext.gotmpl", "recovery/invalid/email.body.plaintext*", t.m)
}

func (t *RecoveryInvalid) MarshalJSON() ([]byte, error) {
Expand Down
6 changes: 3 additions & 3 deletions courier/template/recovery_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func (t *RecoveryValid) EmailRecipient() (string, error) {
}

func (t *RecoveryValid) EmailSubject() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/valid/email.subject.gotmpl", "recovery/valid/email.subject*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/valid/email.subject.gotmpl", "recovery/valid/email.subject*", t.m)
}

func (t *RecoveryValid) EmailBody() (string, error) {
return loadHTMLTemplate(t.c.CourierTemplatesRoot(), "recovery/valid/email.body.gotmpl", "recovery/valid/email.body*", t.m)
return LoadHTMLTemplate(t.c.CourierTemplatesRoot(), "recovery/valid/email.body.gotmpl", "recovery/valid/email.body*", t.m)
}

func (t *RecoveryValid) EmailBodyPlaintext() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/valid/email.body.plaintext.gotmpl", "recovery/valid/email.body.plaintext*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "recovery/valid/email.body.plaintext.gotmpl", "recovery/valid/email.body.plaintext*", t.m)
}

func (t *RecoveryValid) MarshalJSON() ([]byte, error) {
Expand Down
6 changes: 3 additions & 3 deletions courier/template/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ func (t *TestStub) EmailRecipient() (string, error) {
}

func (t *TestStub) EmailSubject() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "test_stub/email.subject.gotmpl", "test_stub/email.subject*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "test_stub/email.subject.gotmpl", "test_stub/email.subject*", t.m)
}

func (t *TestStub) EmailBody() (string, error) {
return loadHTMLTemplate(t.c.CourierTemplatesRoot(), "test_stub/email.body.gotmpl", "test_stub/email.body*", t.m)
return LoadHTMLTemplate(t.c.CourierTemplatesRoot(), "test_stub/email.body.gotmpl", "test_stub/email.body*", t.m)
}

func (t *TestStub) EmailBodyPlaintext() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "test_stub/email.body.plaintext.gotmpl", "test_stub/email.body.plaintext*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "test_stub/email.body.plaintext.gotmpl", "test_stub/email.body.plaintext*", t.m)
}

func (t *TestStub) MarshalJSON() ([]byte, error) {
Expand Down
6 changes: 3 additions & 3 deletions courier/template/verification_invalid.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ func (t *VerificationInvalid) EmailRecipient() (string, error) {
}

func (t *VerificationInvalid) EmailSubject() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "verification/invalid/email.subject.gotmpl", "verification/invalid/email.subject*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "verification/invalid/email.subject.gotmpl", "verification/invalid/email.subject*", t.m)
}

func (t *VerificationInvalid) EmailBody() (string, error) {
return loadHTMLTemplate(t.c.CourierTemplatesRoot(), "verification/invalid/email.body.gotmpl", "verification/invalid/email.body*", t.m)
return LoadHTMLTemplate(t.c.CourierTemplatesRoot(), "verification/invalid/email.body.gotmpl", "verification/invalid/email.body*", t.m)
}

func (t *VerificationInvalid) EmailBodyPlaintext() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "verification/invalid/email.body.plaintext.gotmpl", "verification/invalid/email.body.plaintext*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "verification/invalid/email.body.plaintext.gotmpl", "verification/invalid/email.body.plaintext*", t.m)
}

func (t *VerificationInvalid) MarshalJSON() ([]byte, error) {
Expand Down
6 changes: 3 additions & 3 deletions courier/template/verification_valid.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func (t *VerificationValid) EmailRecipient() (string, error) {
}

func (t *VerificationValid) EmailSubject() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "verification/valid/email.subject.gotmpl", "verification/valid/email.subject*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "verification/valid/email.subject.gotmpl", "verification/valid/email.subject*", t.m)
}

func (t *VerificationValid) EmailBody() (string, error) {
return loadHTMLTemplate(t.c.CourierTemplatesRoot(), "verification/valid/email.body.gotmpl", "verification/valid/email.body*", t.m)
return LoadHTMLTemplate(t.c.CourierTemplatesRoot(), "verification/valid/email.body.gotmpl", "verification/valid/email.body*", t.m)
}

func (t *VerificationValid) EmailBodyPlaintext() (string, error) {
return loadTextTemplate(t.c.CourierTemplatesRoot(), "verification/valid/email.body.plaintext.gotmpl", "verification/valid/email.body.plaintext*", t.m)
return LoadTextTemplate(t.c.CourierTemplatesRoot(), "verification/valid/email.body.plaintext.gotmpl", "verification/valid/email.body.plaintext*", t.m)
}

func (t *VerificationValid) MarshalJSON() ([]byte, error) {
Expand Down

0 comments on commit 3f374a6

Please sign in to comment.