pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
HtmlEmail.scala
(3872B)
1 package inc.pyc
2 package lib
3
4 import snippet.{Social, PYC}
5 import xml._
6 import net.liftweb._
7 import util._
8 import Helpers._
9 import common._
10 import http._
11
12
13 /**
14 * Creation of email messages with HTML templates.
15 * For advice, follow MailChimp's Email Design Reference at
16 * http://templates.mailchimp.com/
17 */
18 object HtmlEmail {
19
20 /**
21 * Creates main HTML template message.
22 */
23 def create(
24 teaser: String,
25 title: String,
26 subtitle: String,
27 body: NodeSeq,
28 includeTitle: Boolean = true,
29 includeLogo: Boolean = true,
30 leftColumn: NodeSeq = NodeSeq.Empty,
31 rightColumn: NodeSeq = NodeSeq.Empty): Box[NodeSeq] = {
32
33 Templates("templates-hidden" :: "email" :: "base" :: Nil) map {
34 {
35 if(teaser.isEmpty) "#pteaser-wrapper" #> NodeSeq.Empty
36 else "#pteaser" #> teaser
37 } &
38 {
39 if(!includeTitle) {
40 "#ptitle-wrapper" #> NodeSeq.Empty &
41 "#psubtitle-wrapper" #> NodeSeq.Empty
42 } else {
43 "#psubtitle" #> subtitle
44 }
45 } & {
46 if(!includeLogo) {
47 "#logo-wrapper" #> NodeSeq.Empty
48 } else {
49 "#logo" #> PYC.logo
50 }
51 } &
52 ".ptitle" #> title &
53 "#pbody" #> body &
54 "#pleftcolumn" #> leftColumn &
55 "#prightcolumn" #> rightColumn &
56 "#twitter-link" #> Social.twitterLink &
57 "#facebook-link" #> Social.facebookLink &
58 "#gplus-link" #> Social.gplusLink
59 }
60 }
61
62 /**
63 * Creates main HTML template message with an action button.
64 */
65 def simpleMessage(
66 title: String,
67 subtitle: String,
68 body: NodeSeq,
69 includeLogo: Boolean = true): Box[NodeSeq] = {
70
71 def teaser = {
72 val text = body.text
73 if(text.length > 80) text.take(80)+"..."
74 else text
75
76 }
77
78 create(teaser, title, subtitle,
79 <span>
80 <br/>
81 {body}
82 <br/>
83 </span>, (title != ""), includeLogo
84 )
85 }
86
87 /**
88 * Creates main HTML template message with an action button.
89 */
90 def createAction(
91 teaser: String,
92 title: String,
93 subtitle: String,
94 btnName: String,
95 link: String,
96 body: NodeSeq,
97 includeLogo: Boolean = true): Box[NodeSeq] = {
98
99 val actionButton = button(btnName, link)
100
101 create(teaser, title, subtitle,
102 <span>
103 <br/>
104 {actionButton}
105 <br/>
106 {body}
107 <br/><br/>
108 If the button above is not working, follow the link below.
109 <br/><a href={link}>{link}</a>
110 </span>, (title != ""), includeLogo
111 )
112 }
113
114 /**
115 * Creates a fixed HTML template message for generic user token links.
116 */
117 def createToken(
118 tease: Boolean,
119 title: String,
120 msg: String,
121 btnName: String,
122 link: String,
123 includeLogo: Boolean): Box[NodeSeq] = {
124
125 val actionButton = button(btnName, link)
126
127 val notice = "If you did not request this, you can safely ignore it. "+
128 "It will expire 48 hours from the time this message was sent."
129
130 def teaser = if(tease) msg else ""
131
132 create(teaser, title,
133 "Click the blue button below to continue",
134 <span>
135 <br/>
136 {actionButton}
137 <br/>
138 <span>
139 <h3>{msg}</h3>
140 <br/>
141 {notice}
142 </span>
143 <br/><br/>
144 If the button above is not working, follow the link below.
145 <br/><a href={link}>{link}</a>
146 </span>, (title != ""), includeLogo
147 )
148 }
149
150 /**
151 * Create a button.
152 * http://templates.mailchimp.com/resources/email-design-patterns/button/
153 */
154 def button(btnName: String, link: String): NodeSeq =
155 (Templates("templates-hidden" :: "email" :: "button" :: Nil) map {
156 "#pbuttontext *" #> btnName &
157 "#pbuttontext [href]" #> link
158 }) openOr Text(btnName)
159 }