Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple tables to be used in templates. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Allow multiple tables to be used in templates. #23

wants to merge 1 commit into from

Conversation

wI2L
Copy link

@wI2L wI2L commented Sep 27, 2017

Hello,

Following my Issue #22 I have made some changes to allow multiples tables in the templates.
I also added the field Title to type hermes.Table. With HTML, a <caption> aligned to the left is used, when rendering to text, the intermediate HTML template uses a <span> before the table.

Example with two tables, and a title on the first one.

email := hermes.Email{
	Body: hermes.Body{
		Intros: []string{
			"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
		},
		Dictionary: []hermes.Entry{},
		Tables: []hermes.Table{
			{
				Title: "A table",
				Data: [][]hermes.Entry{
					// List of rows
					{
						// Key is the column name, Value is the cell value
						// First object defines what columns will be displayed
						{Key: "Item", Value: "Golang"},
						{Key: "Description", Value: "Open source programming language that makes it easy to build simple, reliable, and efficient software"},
						{Key: "Price", Value: "$10.99"},
					},
					{
						{Key: "Item", Value: "Hermes"},
						{Key: "Description", Value: "Programmatically create beautiful e-mails using Golang."},
						{Key: "Price", Value: "$1.99"},
					},
				},
				Columns: hermes.Columns{
					CustomWidth: map[string]string{
						"Item": "25%",
					},
				},
			},
			{
				Data: [][]hermes.Entry{
					// List of rows
					{
						// Key is the column name, Value is the cell value
						// First object defines what columns will be displayed
						{Key: "Item", Value: "Golang"},
						{Key: "Description", Value: "Open source programming language that makes it easy to build simple, reliable, and efficient software"},
						{Key: "Price", Value: "$10.99"},
					},
					{
						{Key: "Item", Value: "Hermes"},
						{Key: "Description", Value: "Programmatically create beautiful e-mails using Golang."},
						{Key: "Price", Value: "$1.99"},
					},
				},
				Columns: hermes.Columns{
					CustomWidth: map[string]string{
						"Item": "25%",
					},
				},
			},
		},
	},
}

TEXT

----
Hi ,
----

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

A table

+--------+--------------------------------+--------+
|  ITEM  |          DESCRIPTION           | PRICE  |
+--------+--------------------------------+--------+
| Golang | Open source programming        | $10.99 |
|        | language that makes it easy    |        |
|        | to build simple, reliable, and |        |
|        | efficient software             |        |
| Hermes | Programmatically create        | $1.99  |
|        | beautiful e-mails using        |        |
|        | Golang.                        |        |
+--------+--------------------------------+--------+

+--------+--------------------------------+--------+
|  ITEM  |          DESCRIPTION           | PRICE  |
+--------+--------------------------------+--------+
| Golang | Open source programming        | $10.99 |
|        | language that makes it easy    |        |
|        | to build simple, reliable, and |        |
|        | efficient software             |        |
| Hermes | Programmatically create        | $1.99  |
|        | beautiful e-mails using        |        |
|        | Golang.                        |        |
+--------+--------------------------------+--------+

Yours truly,
Hermes -

Copyright © 2017 Hermes. All rights reserved.

HTML
Default Theme

@wI2L
Copy link
Author

wI2L commented Sep 27, 2017

Note: README should be update with an example.

@codecov-io
Copy link

codecov-io commented Sep 27, 2017

Codecov Report

Merging #23 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #23      +/-   ##
==========================================
+ Coverage   98.06%   98.11%   +0.04%     
==========================================
  Files           3        3              
  Lines        1033     1059      +26     
==========================================
+ Hits         1013     1039      +26     
  Misses         14       14              
  Partials        6        6
Impacted Files Coverage Δ
hermes.go 73.91% <ø> (ø) ⬆️
flat.go 99.59% <100%> (+0.01%) ⬆️
default.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b79dc09...57e35f3. Read the comment docs.

@wI2L
Copy link
Author

wI2L commented Oct 2, 2017

@matcornic up ?

Copy link
Owner

@matcornic matcornic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your PR :), I just wrote some comments and it should be OK

Note : Github did weird things with code comparison, not easy to find your changes ^^

},
CustomAlignement: map[string]string{
"Price": "right",
},
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should improve the test by adding the title (and check its presence)

padding: 35px 0;
margin: 25px 0 25px 15px;
padding-top: 15px;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change in css is really necessary ? I don't really want to change the default theme unless it's necessary, as it could be considered as a regression for some people.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing the idea here was to indent for the caption. I would inject a margin-left style in the template when caption Title field exists.

@wI2L
Copy link
Author

wI2L commented Nov 16, 2017 via email

@nlandeker
Copy link

Any news on this PR? would really come in handy. Or at least a workaround to achieve this.

@wI2L
Copy link
Author

wI2L commented May 27, 2019

@nlandeker Feel free to take over the PR and address @matcornic comments.

@rowe0x
Copy link

rowe0x commented Jul 8, 2019

Any progress on this PR?

@rvillablanca
Copy link

This is a good feature and would be great if this was integrated, any updates on this ?

@danielpoe
Copy link

This feature would be great.

I even would think that the order of elements in the mail should be flexible and can be repeated like the email creator wants it ..

@wI2L
Copy link
Author

wI2L commented Jun 30, 2020 via email

@AdamDrewsTR
Copy link

Would also like this feature!

@@ -62,7 +63,7 @@ type Body struct {
Name string // The name of the contacted person
Intros []string // Intro sentences, first displayed in the email
Dictionary []Entry // A list of key+value (useful for displaying parameters/settings/personal info)
Table Table // Table is an table where you can put data (pricing grid, a bill, and so on)
Tables []Table // Tables is a list of tables where you can put data (pricing grid, a bill, and so on)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest keeping both fields as this is a breaking change. We can log a warning the Table field is deprecated and if you use it. The way to keep this from breaking everyone we can add code to programmatically add Table to the Tables slice, while also warning the user of the deprecation.

@ChronosMasterOfAllTime
Copy link

@danielpoe @wI2L

I forked this project and am working on it here: https://github.com/go-hermes/hermes

Completed the multi table support, bumped go.mod to 1.22, and bumped all available versions.
See commit go-hermes@e07a58a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants