effective_email_templates 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +48 -51
- data/app/models/effective/email_template.rb +2 -0
- data/app/views/admin/email_templates/_form.html.haml +14 -8
- data/config/effective_email_templates.rb +0 -7
- data/config/email_templates_mailer.rb +15 -0
- data/config/email_templates_mailer_preview.rb +11 -0
- data/config/welcome.liquid +9 -0
- data/lib/effective_email_templates.rb +0 -1
- data/lib/effective_email_templates/version.rb +1 -1
- data/lib/generators/effective_email_templates/install_generator.rb +17 -0
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f78b09e0fce401909a35e596e6d8628b8b2a79199884de8a27c90ac0145ac18
|
4
|
+
data.tar.gz: 307f2c713e151db5069195446b3fdf2918f108144a64bfffae477afb0902fe08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2ce8cefc4c2f9fb1b4465cfbf1c1fd94a584e41691c894c9ec983ab750676a73676778f9f7bb02ae21090ab569967f27ea573bd4531dccfb3fb569f7481c99d
|
7
|
+
data.tar.gz: 26cc8dddb9911e40e00f64e3423e288e968e7c4617a817e1ed0be007048bc6fa6935cf3aba7555f7dfacb57c36a91549e5b7360727a017206fd004e75ce0c536
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Create email templates that an admin can edit and then send.
|
5
5
|
|
6
|
-
Rails 3.2.x
|
6
|
+
Rails 3.2.x through Rails 6
|
7
7
|
|
8
8
|
## effective_email_templates 1.0
|
9
9
|
|
@@ -19,6 +19,7 @@ Please check out [Effective Email Templates 0.x](https://github.com/code-and-eff
|
|
19
19
|
Add to your Gemfile:
|
20
20
|
|
21
21
|
```ruby
|
22
|
+
gem 'haml-rails' # or try using gem 'hamlit-rails'
|
22
23
|
gem 'effective_email_templates'
|
23
24
|
```
|
24
25
|
|
@@ -44,77 +45,73 @@ Then migrate the database:
|
|
44
45
|
rake db:migrate
|
45
46
|
```
|
46
47
|
|
47
|
-
|
48
|
+
And import the provided welcome email template:
|
48
49
|
|
49
|
-
|
50
|
+
```ruby
|
51
|
+
rake effective_email_templates:import
|
52
|
+
```
|
50
53
|
|
51
|
-
|
54
|
+
## Admin View
|
52
55
|
|
53
|
-
|
54
|
-
- Mailer objects need to inherit from `Effective::LiquidMailer`
|
56
|
+
To manage the content of the email templates, navigate to `/admin/email_templates` or add,
|
55
57
|
|
56
|
-
|
58
|
+
`link_to 'Email Templates', effective_email_templates.admin_email_templates_path` to your menu.
|
57
59
|
|
58
|
-
|
59
|
-
- Start out with a plain text email (without any variables and we'll show you how to add dynamic content below)
|
60
|
-
- Add the email subject and from address at the top of the email. For example:
|
60
|
+
## Create Email Templates
|
61
61
|
|
62
|
-
|
63
|
-
---
|
64
|
-
subject: 'Hello User' # REQUIRED
|
65
|
-
from: 'effective@email_templates.com' # REQUIRED
|
66
|
-
cc: 'my_friend@email_templates.com' # optional
|
67
|
-
bcc: 'my_secret_friend@example.com' # optional
|
68
|
-
---
|
69
|
-
Hello new user! I'm a liquid template that will be editable to site admins and/or users.
|
70
|
-
```
|
62
|
+
The installer already created an `app/mailers/email_templates_mailer.rb`. You can change this name. And additional mailers can be created, just make sure they extend from `Effective::EmailTemplatesMailer`.
|
71
63
|
|
72
|
-
|
73
|
-
- Remember to do this in your staging and production environments as well!
|
74
|
-
- This task can be run even when no new templates have been added and will not overwrite existing
|
75
|
-
database templates. This allows you to run the rake task in a deploy script if you are adding new
|
76
|
-
templates frequently.
|
64
|
+
To create an email template:
|
77
65
|
|
78
|
-
|
79
|
-
rake effective_email_templates:import_templates
|
80
|
-
```
|
66
|
+
1. Create a method inside the mailer, like `def welcome`. The `@assigns` instance variable should contain all the variables that are passed to the liquid view. Any variables that end in `_url` like `root_url` will be automatically expanded.
|
81
67
|
|
82
|
-
|
68
|
+
```ruby
|
69
|
+
# app/mailers/email_templates_mailer.rb
|
70
|
+
class EmailTemplatesMailer < Effective::EmailTemplatesMailer
|
71
|
+
def welcome(user)
|
72
|
+
@assigns = {
|
73
|
+
user: {
|
74
|
+
first_name: user.first_name,
|
75
|
+
last_name: user.last_name
|
76
|
+
}
|
77
|
+
adjective: 'awesome'
|
78
|
+
}
|
83
79
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
80
|
+
mail(to: user.email)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
```
|
88
84
|
|
85
|
+
2. Create a .liquid file in `app/views/email_templates_mailer/welcome.liquid`.
|
89
86
|
|
90
|
-
|
87
|
+
```yaml
|
88
|
+
---
|
89
|
+
subject: 'Welcome {{ user.first_name }}' # REQUIRED
|
90
|
+
from: 'admin@example.com' # REQUIRED
|
91
|
+
cc: 'info@example.com' # optional
|
92
|
+
bcc: 'info@example.com' # optional
|
93
|
+
---
|
94
|
+
Welcome {{ user.first_name }} {{ user.last_name }}!
|
91
95
|
|
92
|
-
|
93
|
-
|
96
|
+
I am a liquid template that is imported to the database, and is then editable.
|
97
|
+
|
98
|
+
Thanks for using our site at {{ root_url }}.
|
94
99
|
```
|
95
100
|
|
96
|
-
|
101
|
+
3. Run `rake effective_email_templates:import` or `rake effective_email_templates:overwrite`
|
97
102
|
|
98
|
-
|
99
|
-
# app/mailers/template_mailer.rb
|
100
|
-
class TemplateMailer < Effective::LiquidMailer
|
101
|
-
def welcome_email(user)
|
102
|
-
@to_liquid = {
|
103
|
-
'adjective' => 'awesome'
|
104
|
-
}
|
105
|
-
mail(to: user.email)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
```
|
103
|
+
- Remember to do this in your staging and production environments as well!
|
109
104
|
|
110
|
-
|
105
|
+
- The import task can be run even when no new templates have been added and will not overwrite existing
|
106
|
+
database templates. This allows you to run the rake task in a deploy script if you are adding new
|
107
|
+
templates frequently.
|
108
|
+
|
109
|
+
4. Send the emails like normal:
|
111
110
|
|
112
111
|
```ruby
|
113
|
-
|
114
|
-
mail.deliver
|
112
|
+
EmailTemplatesMailer.welcome(user).deliver
|
115
113
|
```
|
116
114
|
|
117
|
-
|
118
115
|
## Authorization
|
119
116
|
|
120
117
|
All authorization checks are handled via the config.authorization_method found in the `app/config/initializers/effective_email_templates.rb` file.
|
@@ -1,16 +1,22 @@
|
|
1
1
|
= effective_form_with(model: email_template, url: email_template.persisted? ? effective_email_templates.admin_email_template_path(email_template.id) : effective_email_templates.admin_email_templates_path) do |f|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
= f.text_field :subject, hint: 'The subject of your email.'
|
6
|
-
|
7
|
-
= f.email_field :from, hint: 'Whom the email will be sent from.'
|
2
|
+
= f.static_field :template_name, label: 'Name'
|
3
|
+
= f.select :content_type, Effective::EmailTemplate::CONTENT_TYPES
|
8
4
|
|
5
|
+
= f.email_field :from, hint: 'Whom the email will be sent from'
|
9
6
|
= f.text_field :cc
|
10
7
|
= f.text_field :bcc
|
11
8
|
|
12
|
-
= f.
|
9
|
+
= f.text_field :subject, hint: 'The subject of your email'
|
10
|
+
= f.text_area :body, hint: 'The content of your email template', rows: 10
|
11
|
+
|
12
|
+
.card
|
13
|
+
.card-body
|
14
|
+
%p The available variables for this email template are:
|
15
|
+
|
16
|
+
%ul
|
17
|
+
- Array(f.object.template_variables).each do |variable|
|
18
|
+
%li {{ #{variable} }}
|
13
19
|
|
14
|
-
|
20
|
+
%small.text-muted Only a developer can add additional variables
|
15
21
|
|
16
22
|
= f.submit
|
@@ -32,11 +32,4 @@ EffectiveEmailTemplates.setup do |config|
|
|
32
32
|
admin_email_templates: 'admin'
|
33
33
|
}
|
34
34
|
|
35
|
-
# Mailer Settings
|
36
|
-
config.mailer = {
|
37
|
-
subject_prefix: '[example] ',
|
38
|
-
layout: 'effective_email_templates_mailer_layout',
|
39
|
-
deliver_method: nil # :deliver (rails < 4.2), :deliver_now (rails >= 4.2) or :deliver_later
|
40
|
-
}
|
41
|
-
|
42
35
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class EmailTemplatesMailer < Effective::EmailTemplatesMailer
|
2
|
+
|
3
|
+
def welcome(user)
|
4
|
+
@assigns = {
|
5
|
+
'user' => {
|
6
|
+
'first_name' => user.first_name,
|
7
|
+
'last_name' => user.last_name,
|
8
|
+
'email' => user.email,
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
mail(to: user.email)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -19,10 +19,27 @@ module EffectiveEmailTemplates
|
|
19
19
|
template ('../' * 3) + 'config/effective_email_templates.rb', 'config/initializers/effective_email_templates.rb'
|
20
20
|
end
|
21
21
|
|
22
|
+
def copy_mailer
|
23
|
+
template ('../' * 3) + 'config/email_templates_mailer.rb', 'app/mailers/email_templates_mailer.rb'
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_liquid
|
27
|
+
template ('../' * 3) + 'config/welcome.liquid', 'app/views/email_templates_mailer/welcome.liquid'
|
28
|
+
end
|
29
|
+
|
30
|
+
def copy_preview
|
31
|
+
template ('../' * 3) + 'config/email_templates_mailer_preview.rb', 'test/mailers/previews/email_templates_mailer_preview.rb'
|
32
|
+
end
|
33
|
+
|
22
34
|
def create_migration_file
|
23
35
|
@email_templates_table_name = ':' + EffectiveEmailTemplates.email_templates_table_name.to_s
|
24
36
|
migration_template ('../' * 3) + 'db/migrate/01_create_effective_email_templates.rb.erb', 'db/migrate/create_effective_email_templates.rb'
|
25
37
|
end
|
38
|
+
|
39
|
+
def message
|
40
|
+
puts("Please run rake db:migrate and rake effective_email_templates:import")
|
41
|
+
end
|
42
|
+
|
26
43
|
end
|
27
44
|
end
|
28
45
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.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: 2020-03-
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: coffee-rails
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: effective_bootstrap
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +100,10 @@ files:
|
|
114
100
|
- app/views/admin/email_templates/index.html.haml
|
115
101
|
- app/views/layouts/effective_email_templates_mailer_layout.html.haml
|
116
102
|
- config/effective_email_templates.rb
|
103
|
+
- config/email_templates_mailer.rb
|
104
|
+
- config/email_templates_mailer_preview.rb
|
117
105
|
- config/routes.rb
|
106
|
+
- config/welcome.liquid
|
118
107
|
- db/migrate/01_create_effective_email_templates.rb.erb
|
119
108
|
- lib/effective_email_templates.rb
|
120
109
|
- lib/effective_email_templates/engine.rb
|