email_template 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module EmailTemplate
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -2,8 +2,8 @@ require "email_template/j_models"
2
2
  require "email_template/j_mailers"
3
3
  require "email_template/j_helpers"
4
4
 
5
- include JModels
6
- include JMailers
5
+ include EmailTemplate::JModels
6
+ include EmailTemplate::JMailers
7
7
  include EmailTemplate::Mailers::Helpers
8
8
 
9
9
  module EmailTemplate
@@ -1,7 +1,9 @@
1
- module JMailers
2
- class TemplateSendMailer < ActionMailer::Base
3
- def send_mail(template_name, mail_params = {}, template_params = {})
4
- mailing(check_template(template_name), mail_params, template_params)
1
+ module EmailTemplate
2
+ module JMailers
3
+ class TemplateSendMailer < ActionMailer::Base
4
+ def send_mail(template_name, mail_params = {}, template_params = {})
5
+ mailing(check_template(template_name), mail_params, template_params)
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,112 +1,114 @@
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
1
+ module EmailTemplate
2
+ module JModels
3
+ class MailTemplate < ActiveRecord::Base
4
+ include ::EmailTemplate
5
+ include ActionView::Helpers::SanitizeHelper
6
+
7
+ self.table_name = 'email_templates'
8
+
9
+ attr_accessor :prepared
10
+
11
+ attr_accessible :name, :body, :subject, :classes
12
+ serialize :classes, Array
13
+
14
+ validates :name, :uniqueness => true
15
+
16
+ def prepare(attrs={})
17
+ @prepared ||= lambda{ |attrs|
18
+ attrs.stringify_keys!
19
+ body.gsub(/\#{.*?}/) do |match|
20
+ elem, action = match[2..-2].split('.')
21
+ if (action)
22
+ attrs[elem].try(action.to_sym) rescue match.to_s
23
+ else
24
+ attrs[elem] || match.to_s
25
+ end
26
+ end
27
+ }.call(attrs)
28
+ end
9
29
 
10
- attr_accessible :name, :body, :subject, :classes
11
- serialize :classes, Array
30
+ def as_html(attrs={})
31
+ prepare(attrs)
32
+ end
12
33
 
13
- validates :name, :uniqueness => true
34
+ def as_text(attrs={})
35
+ strip_tags(prepare(attrs))
36
+ #sanitize(prepare(attrs), :tags => %w(a), :attributes => %w(href))
37
+ end
14
38
 
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
39
+ def prepare_fields
40
+ possible_attrs = []
41
+ self.classes.each do |resource_class|
42
+ current_class = resource_class.downcase.match(/\w*/mix).to_a.first
43
+ if (current_class[0] == '_')
44
+ possible_attrs << obj(current_class.from(1))
22
45
  else
23
- attrs[elem] || match.to_s
46
+ const_obj = current_class.camelize.constantize
47
+ [:find_attributes, :find_columns, :find_methods].each do |method|
48
+ possible_attrs += self.send(method, current_class, const_obj)
49
+ end
24
50
  end
25
51
  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
52
+ possible_attrs.uniq
53
+ end
37
54
 
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
55
+ protected
56
+ def finder(classname, items, val, current_pattern)
57
+ items.each_with_object([]) do |attr, ret|
58
+ (ret << obj(classname, attr.send(val))) if ((attr.send(val) =~ /#{current_pattern}/).nil? || current_pattern.nil?)
49
59
  end
50
60
  end
51
- possible_attrs.uniq
52
- end
53
61
 
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?)
62
+ def find_attributes(classname, object)
63
+ if object.respond_to?(:attributes)
64
+ finder(classname, object.attributes, :first, attr_pattern(classname))
65
+ end || []
58
66
  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
 
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
68
+ def find_columns(classname, object)
69
+ if object.respond_to?(:columns)
70
+ finder(classname, object.columns, :name, column_pattern(classname))
71
+ end || []
72
+ end
72
73
 
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)
74
+ def find_methods(classname, object)
75
+ object.public_instance_methods.each_with_object([]) do |m_alias, ret|
76
+ (ret << obj(classname, m_alias.to_s.from(methods_header.length))) if m_alias.to_s.start_with?(methods_header)
77
+ end
76
78
  end
77
- end
78
79
 
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
80
+ def find_devise_methods(object)
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
85
+ res
86
+ end
86
87
 
87
- private
88
- def regex_from_list(list)
89
- list.blank? ? nil : "(" + list.join(")|(") + ")"
90
- end
88
+ private
89
+ def regex_from_list(list)
90
+ list.blank? ? nil : "(" + list.join(")|(") + ")"
91
+ end
91
92
 
92
- def regex_from_hash(hash, object)
93
- regex_from_list(hash[object] || hash['*'] || [])
94
- end
93
+ def regex_from_hash(hash, object)
94
+ regex_from_list(hash[object] || hash['*'] || [])
95
+ end
95
96
 
96
- def pattern(elems, object)
97
- elems.is_a?(Array) ? regex_from_list(elems) : regex_from_hash(elems, object)
98
- end
97
+ def pattern(elems, object)
98
+ elems.is_a?(Array) ? regex_from_list(elems) : regex_from_hash(elems, object)
99
+ end
99
100
 
100
- def column_pattern(object)
101
- pattern(columns_black_list, object)
102
- end
101
+ def column_pattern(object)
102
+ pattern(columns_black_list, object)
103
+ end
103
104
 
104
- def attr_pattern(object)
105
- pattern(attributes_black_list, object)
106
- end
105
+ def attr_pattern(object)
106
+ pattern(attributes_black_list, object)
107
+ end
107
108
 
108
- def obj(clas, name = nil)
109
- "\#{#{[clas, name].compact.join('.')}}"
109
+ def obj(clas, name = nil)
110
+ "\#{#{[clas, name].compact.join('.')}}"
111
+ end
110
112
  end
111
113
  end
112
114
  end
@@ -1,35 +1,37 @@
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
1
+ module EmailTemplate
2
+ module Linkable
3
+ module DeviseMailer
4
+ class DeviseTemplateSendMailer < Devise::Mailer
5
+ require "email_template/linkable/devise_helper"
6
+ include EmailTemplate::Linkable::DeviseMailerHelper
7
+ include ActionView::Helpers::UrlHelper
8
+ include Devise::Mailers::Helpers
8
9
 
9
- def send_mail(record, action, template_name, mail_params = {}, template_params = {})
10
- initialize_from_record(record)
11
- opts = template_params[:*] || {}
10
+ def send_mail(record, action, template_name, mail_params = {}, template_params = {})
11
+ initialize_from_record(record)
12
+ opts = template_params[:*] || {}
12
13
 
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
14
+ template_params.reverse_merge!(
15
+ :confirm_link => link_to(opts[:confirm_name] || 'Confirm my account',
16
+ "#{link_head(record)}/confirmation?confirmation_token=#{@resource.confirmation_token}")
17
+ ) if @resource.respond_to? :confirmation_token
17
18
 
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
19
+ template_params.reverse_merge!(
20
+ :edit_password_link => link_to(opts[:change_name] || 'Change my password',
21
+ "#{link_head(record)}/password/edit?reset_password_token=#{@resource.reset_password_token}")
22
+ ) if @resource.respond_to? :reset_password_token
22
23
 
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
24
+ template_params.reverse_merge!(
25
+ :unlock_link => link_to(opts[:unlock_name] || 'Unlock my account',
26
+ "#{link_head(record)}/unlock?unlock_token => #{@resource.unlock_token}")
27
+ ) if @resource.respond_to? :unlock_token
27
28
 
28
- mailing(
29
- check_template(template_name),
30
- headers_for(action, mail_params).except(:subject, :template_path, :template_name),
31
- template_params.except(:*)
32
- )
29
+ mailing(
30
+ check_template(template_name),
31
+ headers_for(action, mail_params).except(:subject, :template_path, :template_name),
32
+ template_params.except(:*)
33
+ )
34
+ end
33
35
  end
34
36
  end
35
37
  end
@@ -1,12 +1,14 @@
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
1
+ module EmailTemplate
2
+ module Linkable
3
+ module DeviseMailerHelper
4
+ def link_head(record)
5
+ "#{ActionMailer::Base.default_url_options[:host]}/#{record.class.name.tableize.singularize}"
6
+ end
6
7
 
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))
8
+ def sending(record, action, template_name, email_opts = {}, template_opts = {})
9
+ send_mail(record, action, template_name, email_opts,
10
+ template_opts.merge(obj_class_name(record).to_sym => record))
11
+ end
10
12
  end
11
13
  end
12
14
  end
@@ -11,6 +11,6 @@ class AddMailsTemplate < ActiveRecord::Migration
11
11
  end
12
12
 
13
13
  def self.down
14
- drop_table :mail_templates
14
+ drop_table :email_templates
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  require "email_template/linkable/devise"
2
- include Linkable::DeviseMailer
2
+ include EmailTemplate::Linkable::DeviseMailer
3
3
 
4
4
  class CustomDeviseMailer < DeviseTemplateSendMailer
5
5
  def confirmation_instructions(record, opts={})
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.0
4
+ version: 0.6.2
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-19 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -71,12 +71,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  - - ! '>='
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
+ segments:
75
+ - 0
76
+ hash: -656039679
74
77
  required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  none: false
76
79
  requirements:
77
80
  - - ! '>='
78
81
  - !ruby/object:Gem::Version
79
82
  version: '0'
83
+ segments:
84
+ - 0
85
+ hash: -656039679
80
86
  requirements: []
81
87
  rubyforge_project:
82
88
  rubygems_version: 1.8.24