From fee36ec740c6ef317171ce009af26b249d44d184 Mon Sep 17 00:00:00 2001 From: Marten Date: Sun, 3 Apr 2022 21:09:10 +0200 Subject: [PATCH] fix: when newRowAfter set for gallery fill with empty same width cells --- .../java/io/rocketbase/mail/GalleryLine.java | 22 +++++++++++++++++++ .../resources/templates/email/layout.html | 9 ++++++-- .../mail/EmailTemplateBuilderTest.java | 6 +++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/email-template-builder/src/main/java/io/rocketbase/mail/GalleryLine.java b/email-template-builder/src/main/java/io/rocketbase/mail/GalleryLine.java index 4eb89fc..780326c 100644 --- a/email-template-builder/src/main/java/io/rocketbase/mail/GalleryLine.java +++ b/email-template-builder/src/main/java/io/rocketbase/mail/GalleryLine.java @@ -95,6 +95,28 @@ public GalleryLine verticalAlign(VerticalAlignment verticalAlignment) { return this; } + /** + * used only by template to easyily fill empty cells + */ + public List getEmptyCells() { + List result = new ArrayList<>(); + if (photoElements != null && !photoElements.isEmpty() && newRowAfter != null) { + int startModulo = (photoElements.size() % (newRowAfter + 1)); + if (startModulo > 0) { + for (int x = startModulo; x < newRowAfter; x++) { + result.add(""); + } + } + } + return result; + } + + /** + * used only by template to easyily fill empty cells + */ + public String getColumnWidth() { + return newRowAfter == null ? null : (Math.round(10000.0/(newRowAfter.intValue() * 1.0))/100.0+"%"); + } @Override public TemplateLineType getType() { diff --git a/email-template-builder/src/main/resources/templates/email/layout.html b/email-template-builder/src/main/resources/templates/email/layout.html index 2da8f7b..9e97c7b 100644 --- a/email-template-builder/src/main/resources/templates/email/layout.html +++ b/email-template-builder/src/main/resources/templates/email/layout.html @@ -484,7 +484,7 @@ {% for photo in line.photoElements %} {% if (loop.index % perRowCount) == 0 %}{% endif %} - + {% if photo.linkUrl is not empty %}{% endif %} {% if c.darkModeEnabled and photo.srcDark is not empty %}{{- photo.alt | default('') -}}{% endif %} @@ -496,7 +496,12 @@ {% endfor %} - {% if ((loop.index+1) % perRowCount) == 0 or loop.last %}{% endif %} + {% if ((loop.index+1) % perRowCount) == 0 %}{% endif %} + {% endfor %} + + {% for c in line.emptyCells %} +   + {% if loop.last %}{% endif %} {% endfor %} diff --git a/email-template-builder/src/test/java/io/rocketbase/mail/EmailTemplateBuilderTest.java b/email-template-builder/src/test/java/io/rocketbase/mail/EmailTemplateBuilderTest.java index 3f4780e..c42f1cd 100644 --- a/email-template-builder/src/test/java/io/rocketbase/mail/EmailTemplateBuilderTest.java +++ b/email-template-builder/src/test/java/io/rocketbase/mail/EmailTemplateBuilderTest.java @@ -157,6 +157,12 @@ public void gallery() { .photos(Arrays.asList("https://source.unsplash.com/random/800x600?sig=1", "https://source.unsplash.com/random/800x600?sig=2", "https://source.unsplash.com/random/800x600?sig=3", "https://source.unsplash.com/random/800x600?sig=4", "https://source.unsplash.com/random/800x600?sig=5","https://source.unsplash.com/random/800x600?sig=6","https://source.unsplash.com/random/800x600?sig=7")) .and() + .gallery() + .newRowAfter(3) + .cellPadding(5) + .photos(Arrays.asList("https://source.unsplash.com/random/800x600?sig=1")) + .and() + .button("Here could be an action", "http://localhost").blue().and() .text("Would be great if you could click :)").and()