-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gochore/dev
support theme
- Loading branch information
Showing
11 changed files
with
487 additions
and
115 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
package emailt | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"html/template" | ||
"io" | ||
"strings" | ||
) | ||
|
||
type Element interface { | ||
Render(writer io.Writer) error | ||
Render(writer io.Writer, themes ...Theme) error | ||
} | ||
|
||
type StringElement string | ||
|
||
func (e StringElement) Render(writer io.Writer) error { | ||
_, err := writer.Write([]byte(e)) | ||
return err | ||
func (e StringElement) Render(writer io.Writer, themes ...Theme) error { | ||
return htmlRender(strings.NewReader(string(e)), writer, mergeThemes(themes)) | ||
} | ||
|
||
type TemplateElement struct { | ||
Data interface{} | ||
Template string | ||
} | ||
|
||
func (e TemplateElement) Render(writer io.Writer) error { | ||
func (e TemplateElement) Render(writer io.Writer, themes ...Theme) error { | ||
t, err := template.New("").Parse(e.Template) | ||
if err != nil { | ||
return fmt.Errorf("parse template: %w", err) | ||
} | ||
return t.Execute(writer, e.Data) | ||
buffer := &bytes.Buffer{} | ||
if err := t.Execute(buffer, e.Data); err != nil { | ||
return fmt.Errorf("template execute: %w", err) | ||
} | ||
return htmlRender(buffer, writer, mergeThemes(themes)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.