Skip to content
Snippets Groups Projects
Commit 11d8bdd3 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

add cell formatting to email report email generation and add a unit test.

parent 33a00319
Branches
Tags
No related merge requests found
......@@ -52,16 +52,19 @@
{:pre [(string? subject)
(vector? recipients)
(map? query-result)]}
(let [html-header-row (fn [cols]
(let [format-cell (fn [cell]
(cond
(nil? cell) "N/A"
(number? cell) (u/format-num cell)
:else (str cell)))
html-header-row (fn [cols]
(into [:tr {:style "background-color: #f4f4f4;"}]
(map (fn [col]
[:td {:style "text-align: left; padding: 0.5em; border: 1px solid #ddd; font-size: 12px;"} col]) cols)))
html-data-row (fn [row]
(into [:tr]
(map (fn [cell]
;; TODO - format cell
;; {{ cell|default_if_none:"N/A"|floatformat:"-2"|default:cell }}
[:td {:style "border: 1px solid #ddd; padding: 0.5em;"} cell]) row)))
[:td {:style "border: 1px solid #ddd; padding: 0.5em;"} (format-cell cell)]) row)))
message-body (html [:html
[:head]
[:body {:style "font-family: Helvetica Neue, Helvetica, sans-serif; width: 100%; margin: 0 auto; max-width: 800px; font-size: 12px;"}
......
......@@ -16,3 +16,34 @@
"It can be safely ignored if you did not request a password reset. Click the link below to reset your password.</p>"
"<p><a href=\"http://localhost/some/url\">http://localhost/some/url</a></p></body></html>")
(send-password-reset-email "test@test.com" "test.domain.com" "http://localhost/some/url"))
;; email report
(expect
(str "<html><head></head>"
"<body style=\"font-family: Helvetica Neue, Helvetica, sans-serif; width: 100%; margin: 0 auto; max-width: 800px; font-size: 12px;\">"
"<div class=\"wrapper\" style=\"padding: 10px; background-color: #ffffff;\">"
"<table style=\"border: 1px solid #cccccc; width: 100%; border-collapse: collapse;\">"
"<tr style=\"background-color: #f4f4f4;\">"
"<td style=\"text-align: left; padding: 0.5em; border: 1px solid #ddd; font-size: 12px;\">first</td>"
"<td style=\"text-align: left; padding: 0.5em; border: 1px solid #ddd; font-size: 12px;\">second</td>"
"</tr>"
"<tr>"
"<td style=\"border: 1px solid #ddd; padding: 0.5em;\">N/A</td>"
"<td style=\"border: 1px solid #ddd; padding: 0.5em;\">N/A</td>"
"</tr>"
"<tr>"
"<td style=\"border: 1px solid #ddd; padding: 0.5em;\">abc</td>"
"<td style=\"border: 1px solid #ddd; padding: 0.5em;\">def</td>"
"</tr>"
"<tr>"
"<td style=\"border: 1px solid #ddd; padding: 0.5em;\">1,000</td>"
"<td style=\"border: 1px solid #ddd; padding: 0.5em;\">17.45</td>"
"</tr>"
"</table>"
"</div>"
"</body>"
"</html>")
(send-email-report "My Email Report" ["test.domain.com"] {:data {:columns ["first" "second"]
:rows [[nil nil]
["abc" "def"]
[1000 17.45234]]}}))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment