hermes icon indicating copy to clipboard operation
hermes copied to clipboard

Allow multiple tables to be used in templates.

Open wI2L opened this issue 6 years ago • 12 comments

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 avatar Sep 27 '17 15:09 wI2L

Note: README should be update with an example.

wI2L avatar Sep 27 '17 15:09 wI2L

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% <ø> (ø) :arrow_up:
flat.go 99.59% <100%> (+0.01%) :arrow_up:
default.go 100% <100%> (ø) :arrow_up:

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.

codecov-io avatar Sep 27 '17 16:09 codecov-io

@matcornic up ?

wI2L avatar Oct 02 '17 09:10 wI2L

Hello

Glad to hear back from you. I finally opted for a simpler solution in my use case, but I am still open to finish this PR.

Regarding the tests, I agree with you, and i'll make the change. Regarding the changes in the default theme CSS, I did it because I feel like it is a significant gain in readability, instead of having items packed, but I guess this is debatable, and things like this are subject to personnal tastes. I encourage you to try it and see for yourself if the visual result with and without the change is worth it.

Regards,

William

2017-11-16 20:31 GMT+01:00 Mathieu Cornic [email protected]:

@matcornic requested changes on this pull request.

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 ^^

In hermes_test.go https://github.com/matcornic/hermes/pull/23#discussion_r151513008:

				},
  • 			CustomAlignement: map[string]string{
    
  • 				"Price": "right",
    
  • 			Columns: Columns{
    
  • 				CustomWidth: map[string]string{
    
  • 					"Item":  "20%",
    
  • 					"Price": "15%",
    
  • 				},
    
  • 				CustomAlignement: map[string]string{
    
  • 					"Price": "right",
    
  • 				},
    			},
    

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

In default.go https://github.com/matcornic/hermes/pull/23#discussion_r151513834:

@@ -207,8 +207,11 @@ func (dt Default) HTMLTemplate() string { / Data table ------------------------------ */ .data-wrapper { width: 100%;

  •  margin: 0;
    
  •  padding: 35px 0;
    
  •  margin: 25px 0 25px 15px;
    
  •  padding-top: 15px;
    
  • }

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/matcornic/hermes/pull/23#pullrequestreview-77234193, or mute the thread https://github.com/notifications/unsubscribe-auth/AGN7EUyKfKsFX-4tiYEdX4RxzGGewwUMks5s3I2AgaJpZM4Pl_KN .

wI2L avatar Nov 16 '17 19:11 wI2L

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

nlandeker avatar May 27 '19 13:05 nlandeker

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

wI2L avatar May 27 '19 13:05 wI2L

Any progress on this PR?

rowe0x avatar Jul 08 '19 06:07 rowe0x

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

rvillablanca avatar Nov 28 '19 10:11 rvillablanca

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 ..

danielpoe avatar Jun 30 '20 18:06 danielpoe

Feel free to takeover the PR Daniel, I don't use this project anymore and I will not make further changes, but this would require minimal work to address the comments made by matcornic.

Le mar. 30 juin 2020 à 20:33, Daniel Pötzinger [email protected] a écrit :

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 ..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/matcornic/hermes/pull/23#issuecomment-651969341, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRXWENQRPJ3ZAQXKQVHK2DRZIVWLANCNFSM4D4X6KGQ .

wI2L avatar Jun 30 '20 18:06 wI2L

Would also like this feature!

AdamDrewsTR avatar Mar 06 '23 15:03 AdamDrewsTR