effective_email_templates 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7ceefc31750874cc34b906a00ce64e80ee805bdf247cb69ec33d080e3625e28
4
- data.tar.gz: ba54f4fc199b22bb8aed8b01d60f7b71ddfec735b6be56fc37d1cee9853f9a3f
3
+ metadata.gz: 3f78b09e0fce401909a35e596e6d8628b8b2a79199884de8a27c90ac0145ac18
4
+ data.tar.gz: 307f2c713e151db5069195446b3fdf2918f108144a64bfffae477afb0902fe08
5
5
  SHA512:
6
- metadata.gz: e24eb4a7e1fa925844d45de25fab8a7bb9b6b3f4fc631c13ba4418a43e9bb304b6be6e1e7eb16c5396d097d8cb5ac910040464af9e1a7bb2aba5122b40f92c61
7
- data.tar.gz: fc6b6f48a42448af82136497ab39ec26a28c9ef60e1db3ef45b42dac8c7c0d7d0d093005e40f6b246e5e671a63a275e8f32ccce34520a6281fd4ff80c821768e
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 and higher
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
- ## Create Email Templates
48
+ And import the provided welcome email template:
48
49
 
49
- `link_to 'Email Templates', effective_email_templates.admin_email_templates_path`
50
+ ```ruby
51
+ rake effective_email_templates:import
52
+ ```
50
53
 
51
- To create your first post, visit `/admin/email_templates` and click `New Email Template`.
54
+ ## Admin View
52
55
 
53
- 1. Create a new mailer object (i.e. `/app/mailers/template_mailer.rb`)
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
- 2. Create a method inside the mailer object based on the name of your email (i.e. `def welcome_email`)
58
+ `link_to 'Email Templates', effective_email_templates.admin_email_templates_path` to your menu.
57
59
 
58
- 3. Create a default email template file (i.e. `/app/views/template_mailer/welcome_email.liquid`)
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
- ```yaml
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
- 4. Run this rake task to import this email template from the filesystem to the database (where it will be editable)
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
- ```console
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
- 5. Visit `localhost:3000/admin/email_templates` in your browser to edit templates.
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
- 6. Run this rake task to overwrite to initial state default database email templates that have already been changed. This will touch email templates created only from filesystem.
85
- ```console
86
- rake effective_email_templates:overwrite_templates
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
- ## Making Content Dynamic
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
- ```liquid
93
- Welcome to our site. We think you're {{ adjective }}!
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
- The corresponding Mailer:
101
+ 3. Run `rake effective_email_templates:import` or `rake effective_email_templates:overwrite`
97
102
 
98
- ```ruby
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
- Send the emails like normal:
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
- mail = TemplateMailer.welcome_email(user)
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.
@@ -62,6 +62,8 @@ module Effective
62
62
  end
63
63
 
64
64
  def render(assigns = {})
65
+ assigns = assigns.deep_stringify_keys() if assigns.respond_to?(:deep_stringify_keys)
66
+
65
67
  {
66
68
  from: from,
67
69
  cc: cc.presence || false,
@@ -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
- - if f.object.persisted?
3
- = f.static_field :template_name, label: 'Name'
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.select :content_type, Effective::EmailTemplate::CONTENT_TYPES
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
- = f.text_area :body, hint: 'The content of your email template'
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
@@ -0,0 +1,11 @@
1
+ # In Rails 4.1 and above, visit:
2
+ # http://localhost:3000/rails/mailers
3
+ # to see a preview of the following emails:
4
+
5
+ class EmailTemplatesMailerPreview < ActionMailer::Preview
6
+
7
+ def welcome
8
+ EmailTemplatesMailer.welcome(User.first)
9
+ end
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ ---
2
+ subject: 'Welcome {{ user.first_name }}'
3
+ from: 'admin@example.com'
4
+ ---
5
+ Hello {{ user.first_name }} {{ user.last_name }},
6
+
7
+ {{ root_url }}
8
+
9
+ Welcome to our site!
@@ -7,7 +7,6 @@ module EffectiveEmailTemplates
7
7
  mattr_accessor :email_templates_table_name
8
8
  mattr_accessor :authorization_method
9
9
  mattr_accessor :layout
10
- mattr_accessor :mailer
11
10
 
12
11
  def self.setup
13
12
  yield self
@@ -1,3 +1,3 @@
1
1
  module EffectiveEmailTemplates
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  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.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-17 00:00:00.000000000 Z
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