email_template 0.6.2 → 0.6.3

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.
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: "activity_partner_mailer:join_confirmation_self",
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("#{self.class.name.tableize.singularize}:#{__method__}", {to: "user@example.com"}, {activity_partner_join: activity_partner})
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 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))
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
- = raw(@template.as_html(:parent => @resource).gsub(/\#\{confirm_link\}/,
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
@@ -1,3 +1,3 @@
1
1
  module EmailTemplate
2
- VERSION = "0.6.2"
2
+ VERSION = '0.6.3'
3
3
  end
@@ -1,6 +1,6 @@
1
- require "email_template/j_models"
2
- require "email_template/j_mailers"
3
- require "email_template/j_helpers"
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 = "et_"
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("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
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 "email_template/linkable/devise_helper"
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 "Copy devise mail template"
10
+ desc 'Copy devise mail template'
11
11
  def copy_initializer
12
- STDOUT << "devise mailer"
13
- template "templates/devise/custom_devise_mailer.rb", "app/mailers/custom_devise_mailer.rb"
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 "Create devise basic templates for input scope"
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 "Creates initializer and migration. If ActiveAdmin install - copy admin page for templates"
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?("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"
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 << "config"
20
- template "templates/email_templates.rb", "config/initializers/email_template.rb"
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 << "admin"
24
- template "templates/active_admin/emails.rb", "app/admin/email_templates.rb"
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 << "devise mailer"
29
- template "templates/devise/custom_devise_mailer.rb", "app/mailers/custom_devise_mailer.rb"
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
@@ -14,7 +14,7 @@ module EmailTemplate
14
14
  end
15
15
 
16
16
  def migration_path
17
- @migration_path ||= File.join("db", "migrate")
17
+ @migration_path ||= File.join('db', 'migrate')
18
18
  end
19
19
  end
20
20
  end
@@ -1,6 +1,6 @@
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
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
- raw([
24
- "You may use next constants :",
25
- "<br/><br/>",
26
- ("<div>#{resource.prepare_fields.join("</div><div>")}</div>")
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, :as => :rich #, :as => :rich # You may use this flag if you have installed gem 'rich'
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
@@ -1,4 +1,4 @@
1
- require "email_template/linkable/devise"
1
+ require 'email_template/linkable/devise'
2
2
  include EmailTemplate::Linkable::DeviseMailer
3
3
 
4
4
  class CustomDeviseMailer < DeviseTemplateSendMailer
@@ -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 selecting. By default eql "et_"
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.2
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-02-27 00:00:00.000000000 Z
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: -656039679
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: -656039679
85
+ hash: -128805631
86
86
  requirements: []
87
87
  rubyforge_project:
88
88
  rubygems_version: 1.8.24