effective_email_templates 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -57
- data/app/models/effective/datatables/email_templates.rb +11 -9
- data/lib/effective_email_templates/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c13e3d65af439b35d89c4033d870d692d08698f3
|
4
|
+
data.tar.gz: 485f5e8e247057d1b3604c0801e20953592ccef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d0c7473ffc31eeaacdf7e00d79e00447fd577096df058fad22cbae046fb7a269576c2665c647f6410b6ec587a432840726ba16a49ed4c2efbb095f45cf236cd
|
7
|
+
data.tar.gz: 9f6d12909a9cf44bf9a67f8d670e814b2d1a1fdc01f2015997c98c88eb845465026fe1bbc812dd76ca42031420643021b6fd10c7e99ea49609e6527568b4bf05
|
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
+
|
1
2
|
# Effective Email Templates
|
2
3
|
|
3
|
-
|
4
|
+
Create email templates that an admin or any user can safely edit (you're protected from SQL injection and other nastiness).
|
5
|
+
Effective Email Templates relies on [Liquid templates](http://liquidmarkup.org/) built by Shopify to profide this safety.
|
4
6
|
|
5
7
|
Rails 3.2.x and Rails 4 Support
|
6
8
|
|
9
|
+
|
7
10
|
## Getting Started
|
8
11
|
|
9
12
|
Add to your Gemfile:
|
@@ -35,27 +38,52 @@ rake db:migrate
|
|
35
38
|
```
|
36
39
|
|
37
40
|
|
38
|
-
##
|
41
|
+
## Creating Email Templates
|
42
|
+
|
43
|
+
This is very similar to creating other emails in Rails.
|
39
44
|
|
40
|
-
|
41
|
-
- Create a mailer method for each email
|
45
|
+
1. Create a new mailer object (i.e. `/app/mailers/template_mailer.rb`)
|
42
46
|
- Mailer objects need to inherit from `Effective::LiquidMailer`
|
43
|
-
|
44
|
-
|
45
|
-
-
|
47
|
+
2. Create a method inside the mailer object based on the name of your email (i.e. `def welcome_email`)
|
48
|
+
3. Create a default email template file (i.e. `/app/views/template_mailer/welcome_email.liquid`)
|
49
|
+
- Start out with a plain text email (without any variables and we'll show you how to add dynamic content below)
|
50
|
+
- Add the email subject and from address at the top of the email. For example:
|
51
|
+
|
52
|
+
```yaml
|
53
|
+
---
|
54
|
+
subject: 'Hello User' # REQUIRED
|
55
|
+
from: 'effective@email_templates.com' # REQUIRED
|
56
|
+
cc: 'my_friend@email_templates.com' # optional
|
57
|
+
bcc: 'my_secret_friend@example.com' # optional
|
58
|
+
---
|
59
|
+
Hello new user! I'm a liquid template that will be editable to site admins and/or users.
|
60
|
+
```
|
46
61
|
|
47
|
-
|
62
|
+
4. Run this rake task to import this email template from the filesystem to the database (where it will be editable)
|
63
|
+
- Remember to do this in your staging and production environments as well!
|
64
|
+
- This task can be run even when no new templates have been added and will not overwrite existing
|
65
|
+
database templates. This allows you to run the rake task in a deploy script if you are adding new
|
66
|
+
templates frequently.
|
67
|
+
|
68
|
+
```console
|
69
|
+
rake effective_email_templates:import_default_views
|
70
|
+
```
|
71
|
+
|
72
|
+
5. Visit `localhost:3000/admin/email_templates` in your browser to edit templates.
|
73
|
+
|
74
|
+
|
75
|
+
## Making Content Dynamic
|
48
76
|
|
49
77
|
```liquid
|
50
|
-
Welcome to our site. We think you're {{ adjective }}
|
78
|
+
Welcome to our site. We think you're {{ adjective }}!
|
51
79
|
```
|
52
80
|
|
53
81
|
The corresponding Mailer:
|
54
82
|
|
55
83
|
```ruby
|
56
|
-
# app/mailers/
|
57
|
-
class
|
58
|
-
def
|
84
|
+
# app/mailers/template_mailer.rb
|
85
|
+
class TemplateMailer < Effective::LiquidMailer
|
86
|
+
def welcome_email(user)
|
59
87
|
@to_liquid = {
|
60
88
|
'adjective' => 'awesome'
|
61
89
|
}
|
@@ -67,39 +95,10 @@ end
|
|
67
95
|
Send the emails like normal:
|
68
96
|
|
69
97
|
```ruby
|
70
|
-
mail =
|
98
|
+
mail = TemplateMailer.welcome_email(user)
|
71
99
|
mail.deliver
|
72
100
|
```
|
73
101
|
|
74
|
-
### Default Templates
|
75
|
-
|
76
|
-
Email templates can still be added by a developer into a view file if a rake task is run to import
|
77
|
-
them into the database in production. To create a view template for the `after_create_user` email
|
78
|
-
above, simply create a template file inside /app/views (probably in the user_liquid directory)
|
79
|
-
with a .liquid file extension. That file should contain metadata in YAML format at the top
|
80
|
-
surrounded by two lines with three hyphens:
|
81
|
-
|
82
|
-
```yaml
|
83
|
-
---
|
84
|
-
subject: 'Hello User' # REQUIRED
|
85
|
-
from: 'effective@email_templates.com' # REQUIRED
|
86
|
-
cc: 'my_friend@email_templates.com' # optional
|
87
|
-
bcc: 'my_secret_friend@example.com' # optional
|
88
|
-
---
|
89
|
-
Hello new user! I'm a liquid template and you can use {{ }} inside of me to interpolate variables
|
90
|
-
defined in the corresponding LiquidMailer method.
|
91
|
-
```
|
92
|
-
|
93
|
-
To add these templates to the database, run the `effective_email_templates:import_default_views` task.
|
94
|
-
This task can be run even when no new templates have been added and will not overwrite existing
|
95
|
-
database templates. This allows you to run the rake task in a deploy script:
|
96
|
-
|
97
|
-
```ruby
|
98
|
-
# an example Heroku deploy script
|
99
|
-
...
|
100
|
-
system 'heroku run rake effective_email_templates:import_default_views'
|
101
|
-
...
|
102
|
-
```
|
103
102
|
|
104
103
|
## Authorization
|
105
104
|
|
@@ -178,18 +177,3 @@ You are not granted rights or licenses to the trademarks of Code and Effect
|
|
178
177
|
|
179
178
|
## Testing
|
180
179
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
@@ -2,16 +2,18 @@ if defined?(EffectiveDatatables)
|
|
2
2
|
module Effective
|
3
3
|
module Datatables
|
4
4
|
class EmailTemplates < Effective::Datatable
|
5
|
-
|
5
|
+
datatable do
|
6
|
+
default_order :subject, :asc
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
table_column :id, visible: false
|
9
|
+
table_column :slug
|
10
|
+
table_column :subject
|
11
|
+
table_column :from
|
12
|
+
table_column :cc, sortable: false, visible: false, label: 'CC'
|
13
|
+
table_column :bcc, sortable: false, visible: false, label: 'BCC'
|
14
|
+
table_column :body, sortable: false, visible: false
|
15
|
+
table_column :actions, sortable: false, partial: '/admin/email_templates/actions'
|
16
|
+
end
|
15
17
|
|
16
18
|
def collection
|
17
19
|
Effective::EmailTemplate.all
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_email_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: effective_datatables
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 2.0.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 2.0.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: pry
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|