email_template 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -12
- data/lib/email-template/version.rb +1 -1
- data/lib/email_template.rb +4 -4
- data/lib/email_template/j_helpers.rb +1 -0
- data/lib/email_template/j_models.rb +3 -3
- data/lib/email_template/linkable/devise.rb +1 -1
- data/lib/generators/email_template/devise_install_generator.rb +3 -3
- data/lib/generators/email_template/devise_templates_generator.rb +1 -1
- data/lib/generators/email_template/install_generator.rb +10 -10
- data/lib/generators/email_template/install_helpers.rb +1 -1
- data/lib/generators/templates/active_admin/emails.rb +8 -9
- data/lib/generators/templates/devise/custom_devise_mailer.rb +1 -1
- data/lib/generators/templates/email_templates.rb +2 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -64,7 +64,7 @@ You can configure email_template at
|
|
64
64
|
Pull template to the base :
|
65
65
|
|
66
66
|
```ruby
|
67
|
-
MailTemplate.create(name: "
|
67
|
+
MailTemplate.create(name: "template unique name",
|
68
68
|
subject: "Join request confirmation",
|
69
69
|
classes: ["activity_partner"],
|
70
70
|
body:
|
@@ -81,34 +81,54 @@ In Mailer:
|
|
81
81
|
class ActivityPartnerMailer < TemplateSendMailer
|
82
82
|
def join_confirmation_self(activity_partner)
|
83
83
|
#send_mail(template_name, mail_params = {}, template_params = {})
|
84
|
-
send_mail("
|
84
|
+
send_mail("template unique name", {to: "user@example.com"}, {activity_partner_: activity_partner})
|
85
85
|
end
|
86
86
|
end
|
87
87
|
```
|
88
88
|
|
89
|
+
## Configuration
|
90
|
+
If you need adding some model method to token list need create in model alias with prefix,
|
91
|
+
which you set in config(by default is 'et_').
|
92
|
+
|
93
|
+
For example if you need add method 'full_name' for 'activity_partner' to token list you need do next:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
class ActivityPartner < ActiveRecord::Base
|
97
|
+
def full_name
|
98
|
+
[self.first_name, self.last_name].join(' ')
|
99
|
+
end
|
100
|
+
|
101
|
+
alias et_full_name full_name
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
|
89
106
|
## Customization
|
90
107
|
|
91
108
|
In case you need additional customization :
|
92
109
|
|
93
110
|
In Mailer:
|
111
|
+
Simply add 'template_path' and 'template_name'
|
94
112
|
|
95
113
|
```ruby
|
96
|
-
class
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
114
|
+
class MyMailer < TemplateSendMailer
|
115
|
+
|
116
|
+
def result(tree)
|
117
|
+
send_mail('MyMailer:result',
|
118
|
+
{
|
119
|
+
to: my_email,
|
120
|
+
template_path: 'mailers',
|
121
|
+
template_name: 'mail'
|
122
|
+
}, {tree: tree})
|
103
123
|
end
|
104
|
-
end
|
124
|
+
end
|
105
125
|
```
|
106
126
|
|
107
127
|
In View:
|
128
|
+
In view you will have compiled template in @data variable
|
108
129
|
|
109
130
|
```ruby
|
110
|
-
=
|
111
|
-
link_to('Confirm my account', confirmation_url(@resource, confirmation_token: @resource.confirmation_token))))
|
131
|
+
= @data.html_safe
|
112
132
|
```
|
113
133
|
|
114
134
|
## Contributing
|
data/lib/email_template.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'email_template/j_models'
|
2
|
+
require 'email_template/j_mailers'
|
3
|
+
require 'email_template/j_helpers'
|
4
4
|
|
5
5
|
include EmailTemplate::JModels
|
6
6
|
include EmailTemplate::JMailers
|
@@ -12,7 +12,7 @@ module EmailTemplate
|
|
12
12
|
mattr_accessor :attributes_black_list
|
13
13
|
self.attributes_black_list = []
|
14
14
|
mattr_accessor :methods_header
|
15
|
-
self.methods_header =
|
15
|
+
self.methods_header = 'et_'
|
16
16
|
|
17
17
|
def self.setup
|
18
18
|
yield self
|
@@ -12,6 +12,7 @@ module EmailTemplate
|
|
12
12
|
mail_params.reverse_merge!(subject: template.subject)
|
13
13
|
|
14
14
|
if mail_params.has_key?(:template_path) && mail_params.has_key?(:template_name)
|
15
|
+
@data = template.as_html(template_params)
|
15
16
|
mail mail_params
|
16
17
|
else
|
17
18
|
mail mail_params do |format|
|
@@ -79,9 +79,9 @@ module EmailTemplate
|
|
79
79
|
|
80
80
|
def find_devise_methods(object)
|
81
81
|
res = []
|
82
|
-
res << obj(
|
83
|
-
res << obj(
|
84
|
-
res << obj(
|
82
|
+
res << obj('confirmation_token') if object.respond_to? :confirmation_token
|
83
|
+
res << obj('reset_password_token') if object.respond_to? :reset_password_token
|
84
|
+
res << obj('unlock_token') if object.respond_to? :unlock_token
|
85
85
|
res
|
86
86
|
end
|
87
87
|
|
@@ -2,7 +2,7 @@ module EmailTemplate
|
|
2
2
|
module Linkable
|
3
3
|
module DeviseMailer
|
4
4
|
class DeviseTemplateSendMailer < Devise::Mailer
|
5
|
-
require
|
5
|
+
require 'email_template/linkable/devise_helper'
|
6
6
|
include EmailTemplate::Linkable::DeviseMailerHelper
|
7
7
|
include ActionView::Helpers::UrlHelper
|
8
8
|
include Devise::Mailers::Helpers
|
@@ -7,10 +7,10 @@ module EmailTemplate
|
|
7
7
|
|
8
8
|
source_root File.expand_path("../../", __FILE__)
|
9
9
|
|
10
|
-
desc
|
10
|
+
desc 'Copy devise mail template'
|
11
11
|
def copy_initializer
|
12
|
-
STDOUT <<
|
13
|
-
template
|
12
|
+
STDOUT << 'devise mailer'
|
13
|
+
template 'templates/devise/custom_devise_mailer.rb', 'app/mailers/custom_devise_mailer.rb'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -3,7 +3,7 @@ module EmailTemplate
|
|
3
3
|
class DeviseTemplatesGenerator < Rails::Generators::NamedBase
|
4
4
|
attr_reader :bodies
|
5
5
|
|
6
|
-
desc
|
6
|
+
desc 'Create devise basic templates for input scope'
|
7
7
|
def initialize(args, *options)
|
8
8
|
super
|
9
9
|
@bodies = {}
|
@@ -7,26 +7,26 @@ module EmailTemplate
|
|
7
7
|
|
8
8
|
source_root File.expand_path("../../", __FILE__)
|
9
9
|
|
10
|
-
desc
|
10
|
+
desc 'Creates initializer and migration. If ActiveAdmin install - copy admin page for templates'
|
11
11
|
class_option :orm
|
12
12
|
|
13
13
|
def copy_initializer
|
14
|
-
unless migration_exists?(
|
15
|
-
STDOUT <<
|
16
|
-
template
|
14
|
+
unless migration_exists?('add_mails_template')
|
15
|
+
STDOUT << 'migration'
|
16
|
+
template 'active_record/migration.rb', "db/migrate/#{Time.now.utc.strftime('%Y%m%d%H%M%S').to_i}_add_mails_template.rb"
|
17
17
|
end
|
18
18
|
|
19
|
-
STDOUT <<
|
20
|
-
template
|
19
|
+
STDOUT << 'config'
|
20
|
+
template 'templates/email_templates.rb', 'config/initializers/email_template.rb'
|
21
21
|
|
22
22
|
if Gem::Specification::find_all_by_name('activeadmin').any?
|
23
|
-
STDOUT <<
|
24
|
-
template
|
23
|
+
STDOUT << 'admin'
|
24
|
+
template 'templates/active_admin/emails.rb', 'app/admin/email_templates.rb'
|
25
25
|
end
|
26
26
|
|
27
27
|
if Gem::Specification::find_all_by_name('devise').any?
|
28
|
-
STDOUT <<
|
29
|
-
template
|
28
|
+
STDOUT << 'devise mailer'
|
29
|
+
template 'templates/devise/custom_devise_mailer.rb', 'app/mailers/custom_devise_mailer.rb'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
ActiveAdmin.register MailTemplate, :as =>
|
2
|
-
config.sort_order =
|
3
|
-
|
1
|
+
ActiveAdmin.register MailTemplate, :as => 'Mail Template' do
|
2
|
+
config.sort_order = 'name_asc'
|
3
|
+
config.batch_actions = false #comment this if you need batches
|
4
4
|
|
5
5
|
filter :subject, as: :select, collection: proc { MailTemplate.all.map(&:subject) }
|
6
6
|
|
@@ -20,17 +20,16 @@ ActiveAdmin.register MailTemplate, :as => "Mail Template" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
sidebar :email_objects, :only => :edit do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
].join)
|
23
|
+
table_for([]) do
|
24
|
+
tr { td 'You may use next constants : ' }
|
25
|
+
resource.prepare_fields.each { |item| tr { td item} }
|
26
|
+
end
|
28
27
|
end
|
29
28
|
|
30
29
|
form do |f|
|
31
30
|
f.inputs do
|
32
31
|
f.input :subject
|
33
|
-
f.input :body
|
32
|
+
f.input :body #, :as => :rich # You may use this flag if you have installed gem 'rich'
|
34
33
|
end
|
35
34
|
f.actions
|
36
35
|
end
|
@@ -3,6 +3,7 @@ EmailTemplate.setup do |config|
|
|
3
3
|
#############Whitelists################
|
4
4
|
|
5
5
|
# Accepts args as Hash and as Array
|
6
|
+
#if column name or attribute contains one of listened pieces - it will be ignore in output list
|
6
7
|
|
7
8
|
# Ignore token list for columns
|
8
9
|
#config.columns_black_list = ["_at", "id"]
|
@@ -13,6 +14,6 @@ EmailTemplate.setup do |config|
|
|
13
14
|
|
14
15
|
#######################################
|
15
16
|
|
16
|
-
# Method header for object methods
|
17
|
+
# Method header for object methods which will be output in usable tokens list. By default eql "et_"
|
17
18
|
#config.methods_header = "et_"
|
18
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
segments:
|
75
75
|
- 0
|
76
|
-
hash: -
|
76
|
+
hash: -128805631
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
none: false
|
79
79
|
requirements:
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
segments:
|
84
84
|
- 0
|
85
|
-
hash: -
|
85
|
+
hash: -128805631
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project:
|
88
88
|
rubygems_version: 1.8.24
|