email_template 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +120 -0
- data/Rakefile +2 -0
- data/email_template.gemspec +21 -0
- data/lib/email-template/version.rb +3 -0
- data/lib/email_template.rb +20 -0
- data/lib/email_template/j_helpers.rb +35 -0
- data/lib/email_template/j_mailers.rb +7 -0
- data/lib/email_template/j_models.rb +112 -0
- data/lib/email_template/linkable/devise.rb +36 -0
- data/lib/email_template/linkable/devise_helper.rb +12 -0
- data/lib/generators/active_record/migration.rb +16 -0
- data/lib/generators/email_template/devise_install_generator.rb +17 -0
- data/lib/generators/email_template/devise_templates_generator.rb +53 -0
- data/lib/generators/email_template/install_generator.rb +34 -0
- data/lib/generators/email_template/install_helpers.rb +21 -0
- data/lib/generators/templates/active_admin/emails.rb +37 -0
- data/lib/generators/templates/devise/custom_devise_mailer.rb +19 -0
- data/lib/generators/templates/email_templates.rb +18 -0
- data/rails/init.rb +1 -0
- data/spec/.rspec +3 -0
- data/spec/helpers/mailer_helper_spec.rb +5 -0
- data/spec/spec_helper.rb +21 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jenua Boiko
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# EmailTemplate
|
2
|
+
|
3
|
+
Allows your users to edit e-mail templates.
|
4
|
+
With Devise and Active Admin support (but you don't need them to start using email_template).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'email_template'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```sh
|
17
|
+
$ bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or just:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
$ gem install email_template
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Run installer:
|
29
|
+
|
30
|
+
```sh
|
31
|
+
$ rails g email_template:install
|
32
|
+
```
|
33
|
+
|
34
|
+
In order to use Devise templates you need to install devise wrapper:
|
35
|
+
|
36
|
+
```sh
|
37
|
+
$ rails g email_template:devise_install
|
38
|
+
```
|
39
|
+
|
40
|
+
Then generate common devise templates for a specified scope:
|
41
|
+
|
42
|
+
```sh
|
43
|
+
$ rails g email_template:devise_templates <devise_scope>
|
44
|
+
```
|
45
|
+
|
46
|
+
This generator produces email templates with the names:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
<devise_scope>_mailer:confirmation_instructions
|
50
|
+
<devise_scope>_mailer:reset_password_instructions
|
51
|
+
<devise_scope>_mailer:unlock_instructions
|
52
|
+
```
|
53
|
+
|
54
|
+
Run:
|
55
|
+
|
56
|
+
```sh
|
57
|
+
$ rake db:migrate
|
58
|
+
```
|
59
|
+
|
60
|
+
You can configure email_template at
|
61
|
+
|
62
|
+
config/initializers/email_template.rb
|
63
|
+
|
64
|
+
Pull template to the base :
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
MailTemplate.create(name: "activity_partner_mailer:join_confirmation_self",
|
68
|
+
subject: "Join request confirmation",
|
69
|
+
classes: ["activity_partner"],
|
70
|
+
body:
|
71
|
+
<<-TEXT
|
72
|
+
Dear \#{activity_partner.full_name} ...
|
73
|
+
....
|
74
|
+
TEXT
|
75
|
+
)
|
76
|
+
```
|
77
|
+
|
78
|
+
In Mailer:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class ActivityPartnerMailer < TemplateSendMailer
|
82
|
+
def join_confirmation_self(activity_partner)
|
83
|
+
#send_mail(template_name, mail_params = {}, template_params = {})
|
84
|
+
send_mail("#{self.class.name.tableize.singularize}:#{__method__}", {to: "user@example.com"}, {activity_partner_join: activity_partner})
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
## Customization
|
90
|
+
|
91
|
+
In case you need additional customization :
|
92
|
+
|
93
|
+
In Mailer:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
class CustomDeviseMailer < Devise::Mailer
|
97
|
+
include Devise::Mailers::Helpers
|
98
|
+
include EmailTemplate::Mailers::Helpers
|
99
|
+
|
100
|
+
def confirmation_instructions(record, opts={})
|
101
|
+
@template = check_template("#{record.class.name.tableize.singularize}_mailer:#{__method__}")
|
102
|
+
devise_mail(record, :confirmation_instructions, opts.merge(subject: @template.subject))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
In View:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
= raw(@template.as_html(:parent => @resource).gsub(/\#\{confirm_link\}/,
|
111
|
+
link_to('Confirm my account', confirmation_url(@resource, confirmation_token: @resource.confirmation_token))))
|
112
|
+
```
|
113
|
+
|
114
|
+
## Contributing
|
115
|
+
|
116
|
+
1. Fork it
|
117
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
118
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
119
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
120
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/email-template/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jenua Boiko"]
|
6
|
+
gem.email = ["jeyboy1985@gmail.com"]
|
7
|
+
gem.description = %Q{Allows your users to edit e-mail templates}
|
8
|
+
gem.summary = %Q{Allows your users to edit e-mail templates. With Devise and Active Admin support (but you don't need them to start using email_template).}
|
9
|
+
gem.homepage = "https://github.com/jeyboy/email_template"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "email_template"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = EmailTemplate::VERSION
|
17
|
+
gem.rubygems_version = %q{1.8.6}
|
18
|
+
|
19
|
+
gem.add_dependency("rails", ">= 3.0.0")
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "email_template/j_models"
|
2
|
+
require "email_template/j_mailers"
|
3
|
+
require "email_template/j_helpers"
|
4
|
+
|
5
|
+
include JModels
|
6
|
+
include JMailers
|
7
|
+
include EmailTemplate::Mailers::Helpers
|
8
|
+
|
9
|
+
module EmailTemplate
|
10
|
+
mattr_accessor :columns_black_list
|
11
|
+
self.columns_black_list = []
|
12
|
+
mattr_accessor :attributes_black_list
|
13
|
+
self.attributes_black_list = []
|
14
|
+
mattr_accessor :methods_header
|
15
|
+
self.methods_header = "et_"
|
16
|
+
|
17
|
+
def self.setup
|
18
|
+
yield self
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module EmailTemplate
|
2
|
+
module Mailers
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
protected
|
6
|
+
def check_template(template_name)
|
7
|
+
throw "#{template_name} not set" if (@template = MailTemplate.where(name: template_name).first).blank?
|
8
|
+
@template
|
9
|
+
end
|
10
|
+
|
11
|
+
def mailing(template, mail_params = {}, template_params = {})
|
12
|
+
mail_params.reverse_merge!(subject: template.subject)
|
13
|
+
|
14
|
+
if mail_params.has_key?(:template_path) && mail_params.has_key?(:template_name)
|
15
|
+
mail mail_params
|
16
|
+
else
|
17
|
+
mail mail_params do |format|
|
18
|
+
format.text { render :text => template.as_text(template_params) }
|
19
|
+
format.html { render :text => template.as_html(template_params) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def obj_class_name(obj)
|
25
|
+
obj.class.name.tableize.singularize
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
#def subject_for(key)
|
30
|
+
# I18n.t(:"#{devise_mapping.name}_subject", :scope => [:devise, :mailer, key],
|
31
|
+
# :default => [:subject, key.to_s.humanize])
|
32
|
+
#end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module JModels
|
2
|
+
class MailTemplate < ActiveRecord::Base
|
3
|
+
include EmailTemplate
|
4
|
+
include ActionView::Helpers::SanitizeHelper
|
5
|
+
|
6
|
+
self.table_name = 'email_templates'
|
7
|
+
|
8
|
+
attr_accessor :prepared
|
9
|
+
|
10
|
+
attr_accessible :name, :body, :subject, :classes
|
11
|
+
serialize :classes, Array
|
12
|
+
|
13
|
+
validates :name, :uniqueness => true
|
14
|
+
|
15
|
+
def prepare(attrs={})
|
16
|
+
@prepared ||= lambda{ |attrs|
|
17
|
+
attrs.stringify_keys!
|
18
|
+
body.gsub(/\#{.*?}/) do |match|
|
19
|
+
elem, action = match[2..-2].split('.')
|
20
|
+
if (action)
|
21
|
+
attrs[elem].try(action.to_sym) rescue match.to_s
|
22
|
+
else
|
23
|
+
attrs[elem] || match.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}.call(attrs)
|
27
|
+
end
|
28
|
+
|
29
|
+
def as_html(attrs={})
|
30
|
+
prepare(attrs)
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_text(attrs={})
|
34
|
+
strip_tags(prepare(attrs))
|
35
|
+
#sanitize(prepare(attrs), :tags => %w(a), :attributes => %w(href))
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare_fields
|
39
|
+
possible_attrs = []
|
40
|
+
self.classes.each do |resource_class|
|
41
|
+
current_class = resource_class.downcase.match(/\w*/mix).to_a.first
|
42
|
+
if (current_class[0] == '_')
|
43
|
+
possible_attrs << obj(current_class.from(1))
|
44
|
+
else
|
45
|
+
const_obj = current_class.camelize.constantize
|
46
|
+
[:find_attributes, :find_columns, :find_methods].each do |method|
|
47
|
+
possible_attrs += self.send(method, current_class, const_obj)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
possible_attrs.uniq
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
def finder(classname, items, val, current_pattern)
|
56
|
+
items.each_with_object([]) do |attr, ret|
|
57
|
+
(ret << obj(classname, attr.send(val))) if ((attr.send(val) =~ /#{current_pattern}/).nil? || current_pattern.nil?)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_attributes(classname, object)
|
62
|
+
if object.respond_to?(:attributes)
|
63
|
+
finder(classname, object.attributes, :first, attr_pattern(classname))
|
64
|
+
end || []
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_columns(classname, object)
|
68
|
+
if object.respond_to?(:columns)
|
69
|
+
finder(classname, object.columns, :name, column_pattern(classname))
|
70
|
+
end || []
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_methods(classname, object)
|
74
|
+
object.public_instance_methods.each_with_object([]) do |m_alias, ret|
|
75
|
+
(ret << obj(classname, m_alias.to_s.from(methods_header.length))) if m_alias.to_s.start_with?(methods_header)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def find_devise_methods(object)
|
80
|
+
res = []
|
81
|
+
res << obj("confirmation_token") if object.respond_to? :confirmation_token
|
82
|
+
res << obj("reset_password_token") if object.respond_to? :reset_password_token
|
83
|
+
res << obj("unlock_token") if object.respond_to? :unlock_token
|
84
|
+
res
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def regex_from_list(list)
|
89
|
+
list.blank? ? nil : "(" + list.join(")|(") + ")"
|
90
|
+
end
|
91
|
+
|
92
|
+
def regex_from_hash(hash, object)
|
93
|
+
regex_from_list(hash[object] || hash['*'] || [])
|
94
|
+
end
|
95
|
+
|
96
|
+
def pattern(elems, object)
|
97
|
+
elems.is_a?(Array) ? regex_from_list(elems) : regex_from_hash(elems, object)
|
98
|
+
end
|
99
|
+
|
100
|
+
def column_pattern(object)
|
101
|
+
pattern(columns_black_list, object)
|
102
|
+
end
|
103
|
+
|
104
|
+
def attr_pattern(object)
|
105
|
+
pattern(attributes_black_list, object)
|
106
|
+
end
|
107
|
+
|
108
|
+
def obj(clas, name = nil)
|
109
|
+
"\#{#{[clas, name].compact.join('.')}}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Linkable
|
2
|
+
module DeviseMailer
|
3
|
+
class DeviseTemplateSendMailer < Devise::Mailer
|
4
|
+
require "email_template/linkable/devise_helper"
|
5
|
+
include Linkable::DeviseMailerHelper
|
6
|
+
include ActionView::Helpers::UrlHelper
|
7
|
+
include Devise::Mailers::Helpers
|
8
|
+
|
9
|
+
def send_mail(record, action, template_name, mail_params = {}, template_params = {})
|
10
|
+
initialize_from_record(record)
|
11
|
+
opts = template_params[:*] || {}
|
12
|
+
|
13
|
+
template_params.reverse_merge!(
|
14
|
+
:confirm_link => link_to(opts[:confirm_name] || 'Confirm my account',
|
15
|
+
"#{link_head(record)}/confirmation?confirmation_token=#{@resource.confirmation_token}")
|
16
|
+
) if @resource.respond_to? :confirmation_token
|
17
|
+
|
18
|
+
template_params.reverse_merge!(
|
19
|
+
:edit_password_link => link_to(opts[:change_name] || 'Change my password',
|
20
|
+
"#{link_head(record)}/password/edit?reset_password_token=#{@resource.reset_password_token}")
|
21
|
+
) if @resource.respond_to? :reset_password_token
|
22
|
+
|
23
|
+
template_params.reverse_merge!(
|
24
|
+
:unlock_link => link_to(opts[:unlock_name] || 'Unlock my account',
|
25
|
+
"#{link_head(record)}/unlock?unlock_token => #{@resource.unlock_token}")
|
26
|
+
) if @resource.respond_to? :unlock_token
|
27
|
+
|
28
|
+
mailing(
|
29
|
+
check_template(template_name),
|
30
|
+
headers_for(action, mail_params).except(:subject, :template_path, :template_name),
|
31
|
+
template_params.except(:*)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Linkable
|
2
|
+
module DeviseMailerHelper
|
3
|
+
def link_head(record)
|
4
|
+
"#{ActionMailer::Base.default_url_options[:host]}/#{record.class.name.tableize.singularize}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def sending(record, action, template_name, email_opts = {}, template_opts = {})
|
8
|
+
send_mail(record, action, template_name, email_opts,
|
9
|
+
template_opts.merge(obj_class_name(record).to_sym => record))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class AddMailsTemplate < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :email_templates do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :subject
|
6
|
+
t.text :body
|
7
|
+
t.text :classes
|
8
|
+
|
9
|
+
t.datetime :created_at
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :mail_templates
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'generators/email_template/install_helpers'
|
2
|
+
|
3
|
+
module EmailTemplate
|
4
|
+
module Generators
|
5
|
+
class DeviseInstallGenerator < Rails::Generators::Base
|
6
|
+
include EmailTemplate::Generators::OrmHelpers
|
7
|
+
|
8
|
+
source_root File.expand_path("../../", __FILE__)
|
9
|
+
|
10
|
+
desc "Copy devise mail template"
|
11
|
+
def copy_initializer
|
12
|
+
STDOUT << "devise mailer"
|
13
|
+
template "templates/devise/custom_devise_mailer.rb", "app/mailers/custom_devise_mailer.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module EmailTemplate
|
2
|
+
module Generators
|
3
|
+
class DeviseTemplatesGenerator < Rails::Generators::NamedBase
|
4
|
+
attr_reader :bodies
|
5
|
+
|
6
|
+
desc "Create devise basic templates for input scope"
|
7
|
+
def initialize(args, *options)
|
8
|
+
super
|
9
|
+
@bodies = {}
|
10
|
+
@bodies['confirmation_instructions'] = <<-STR
|
11
|
+
<p>Welcome \#{#{name}.email}!</p>
|
12
|
+
<p>You can confirm your account email through the link below:</p>
|
13
|
+
<p>\#{confirm_link}</p>
|
14
|
+
STR
|
15
|
+
@bodies['reset_password_instructions'] = <<-STR
|
16
|
+
<p>Hello \#{#{name}.email}!</p>
|
17
|
+
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
|
18
|
+
<p>\#{edit_password_link}</p>
|
19
|
+
<p>If you didn't request this, please ignore this email.</p>
|
20
|
+
<p>Your password won't change until you access the link above and create a new one.</p>
|
21
|
+
STR
|
22
|
+
@bodies['unlock_instructions'] = <<-STR
|
23
|
+
<p>Hello \#{#{name}.email}!</p>
|
24
|
+
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
|
25
|
+
<p>Click the link below to unlock your account:<\p>
|
26
|
+
<p>\#{unlock_link}</p>
|
27
|
+
STR
|
28
|
+
|
29
|
+
generate_templates
|
30
|
+
end
|
31
|
+
|
32
|
+
def generate_templates
|
33
|
+
if defined?(MailTemplate)
|
34
|
+
['confirmation_instructions', 'reset_password_instructions', 'unlock_instructions'].each do |method_name|
|
35
|
+
template_name = "#{name}_mailer:#{method_name}"
|
36
|
+
|
37
|
+
if MailTemplate.where(:name => template_name).empty?
|
38
|
+
STDOUT << template_name << "\n"
|
39
|
+
MailTemplate.create do |new_template|
|
40
|
+
new_template.name = template_name
|
41
|
+
new_template.classes = []
|
42
|
+
new_template.subject = method_name.humanize
|
43
|
+
new_template.body = bodies[method_name]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
STDOUT << "base model \"MailTemplate\" missed"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'generators/email_template/install_helpers'
|
2
|
+
|
3
|
+
module EmailTemplate
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
include EmailTemplate::Generators::OrmHelpers
|
7
|
+
|
8
|
+
source_root File.expand_path("../../", __FILE__)
|
9
|
+
|
10
|
+
desc "Creates initializer and migration. If ActiveAdmin install - copy admin page for templates"
|
11
|
+
class_option :orm
|
12
|
+
|
13
|
+
def copy_initializer
|
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
|
+
end
|
18
|
+
|
19
|
+
STDOUT << "config"
|
20
|
+
template "templates/email_templates.rb", "config/initializers/email_template.rb"
|
21
|
+
|
22
|
+
if Gem::Specification::find_all_by_name('activeadmin').any?
|
23
|
+
STDOUT << "admin"
|
24
|
+
template "templates/active_admin/emails.rb", "app/admin/email_templates.rb"
|
25
|
+
end
|
26
|
+
|
27
|
+
if Gem::Specification::find_all_by_name('devise').any?
|
28
|
+
STDOUT << "devise mailer"
|
29
|
+
template "templates/devise/custom_devise_mailer.rb", "app/mailers/custom_devise_mailer.rb"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EmailTemplate
|
2
|
+
module Generators
|
3
|
+
module OrmHelpers
|
4
|
+
def self.orm
|
5
|
+
Rails::Generators.options[:rails][:orm]
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.orm_has_migration?
|
9
|
+
[:active_record].include? orm
|
10
|
+
end
|
11
|
+
|
12
|
+
def migration_exists?(name)
|
13
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_#{name}.rb$/).first
|
14
|
+
end
|
15
|
+
|
16
|
+
def migration_path
|
17
|
+
@migration_path ||= File.join("db", "migrate")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
ActiveAdmin.register MailTemplate, :as => "Mail Template" do
|
2
|
+
config.sort_order = "name_asc"
|
3
|
+
#config.batch_actions = false #uncomment this if you need batches
|
4
|
+
|
5
|
+
filter :subject, as: :select, collection: proc { MailTemplate.all.map(&:subject) }
|
6
|
+
|
7
|
+
actions :all, :except => [:destroy, :new]
|
8
|
+
|
9
|
+
index as: :grid do |email_template|
|
10
|
+
a email_template.name.humanize, href: admin_mail_template_path(email_template)
|
11
|
+
end
|
12
|
+
|
13
|
+
show do |email_template|
|
14
|
+
attributes_table do
|
15
|
+
row :subject
|
16
|
+
row :body do
|
17
|
+
raw email_template.body
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
sidebar :email_objects, :only => :edit do
|
23
|
+
raw([
|
24
|
+
"You may use next constants :",
|
25
|
+
"<br/><br/>",
|
26
|
+
("<div>#{resource.prepare_fields.join("</div><div>")}</div>")
|
27
|
+
].join)
|
28
|
+
end
|
29
|
+
|
30
|
+
form do |f|
|
31
|
+
f.inputs do
|
32
|
+
f.input :subject
|
33
|
+
f.input :body, :as => :rich #, :as => :rich # You may use this flag if you have installed gem 'rich'
|
34
|
+
end
|
35
|
+
f.actions
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "email_template/linkable/devise"
|
2
|
+
include Linkable::DeviseMailer
|
3
|
+
|
4
|
+
class CustomDeviseMailer < DeviseTemplateSendMailer
|
5
|
+
def confirmation_instructions(record, opts={})
|
6
|
+
sending(record, :confirmation_instructions,
|
7
|
+
"#{obj_class_name(record)}_mailer:#{__method__}", opts, {})
|
8
|
+
end
|
9
|
+
|
10
|
+
def reset_password_instructions(record, opts={})
|
11
|
+
sending(record, :reset_password_instructions,
|
12
|
+
"#{obj_class_name(record)}_mailer:#{__method__}", opts, {})
|
13
|
+
end
|
14
|
+
|
15
|
+
def unlock_instructions(record, opts={})
|
16
|
+
sending(record, :unlock_instructions,
|
17
|
+
"#{obj_class_name(record)}_mailer:#{__method__}", opts, {})
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
EmailTemplate.setup do |config|
|
2
|
+
|
3
|
+
#############Whitelists################
|
4
|
+
|
5
|
+
# Accepts args as Hash and as Array
|
6
|
+
|
7
|
+
# Ignore token list for columns
|
8
|
+
#config.columns_black_list = ["_at", "id"]
|
9
|
+
#config.columns_black_list = {'*' => ["_at", "id"], "some_object" => ["complete"]}
|
10
|
+
|
11
|
+
# Ignore token list for attributes
|
12
|
+
#config.attributes_black_list = []
|
13
|
+
|
14
|
+
#######################################
|
15
|
+
|
16
|
+
# Method header for object methods selecting. By default eql "et_"
|
17
|
+
#config.methods_header = "et_"
|
18
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'email_template'
|
data/spec/.rspec
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'email_template'
|
5
|
+
require 'database_cleaner'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.use_transactional_fixtures = false
|
9
|
+
|
10
|
+
config.before(:suite) do
|
11
|
+
DatabaseCleaner.strategy = :truncation
|
12
|
+
end
|
13
|
+
|
14
|
+
config.before(:each) do
|
15
|
+
DatabaseCleaner.start
|
16
|
+
end
|
17
|
+
|
18
|
+
config.after(:each) do
|
19
|
+
DatabaseCleaner.clean
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_template
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jenua Boiko
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
description: Allows your users to edit e-mail templates
|
31
|
+
email:
|
32
|
+
- jeyboy1985@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- email_template.gemspec
|
43
|
+
- lib/email-template/version.rb
|
44
|
+
- lib/email_template.rb
|
45
|
+
- lib/email_template/j_helpers.rb
|
46
|
+
- lib/email_template/j_mailers.rb
|
47
|
+
- lib/email_template/j_models.rb
|
48
|
+
- lib/email_template/linkable/devise.rb
|
49
|
+
- lib/email_template/linkable/devise_helper.rb
|
50
|
+
- lib/generators/active_record/migration.rb
|
51
|
+
- lib/generators/email_template/devise_install_generator.rb
|
52
|
+
- lib/generators/email_template/devise_templates_generator.rb
|
53
|
+
- lib/generators/email_template/install_generator.rb
|
54
|
+
- lib/generators/email_template/install_helpers.rb
|
55
|
+
- lib/generators/templates/active_admin/emails.rb
|
56
|
+
- lib/generators/templates/devise/custom_devise_mailer.rb
|
57
|
+
- lib/generators/templates/email_templates.rb
|
58
|
+
- rails/init.rb
|
59
|
+
- spec/.rspec
|
60
|
+
- spec/helpers/mailer_helper_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
homepage: https://github.com/jeyboy/email_template
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.24
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Allows your users to edit e-mail templates. With Devise and Active Admin
|
86
|
+
support (but you don't need them to start using email_template).
|
87
|
+
test_files:
|
88
|
+
- spec/.rspec
|
89
|
+
- spec/helpers/mailer_helper_spec.rb
|
90
|
+
- spec/spec_helper.rb
|