mail_engine 0.1.10 → 0.1.11

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
@@ -1,4 +1,7 @@
1
1
  class MailEngine::ApplicationController < ApplicationController
2
+ # used when mail_template preview.
3
+ prepend_view_path MailEngine::MailTemplateResolver.instance
4
+
2
5
  include MailEngine
3
6
  helper MailEngine::MailEngineHelper
4
7
 
@@ -44,9 +44,9 @@ class MailEngine::MailSchedulesController < MailEngine::ApplicationController
44
44
 
45
45
  def send_test_mail
46
46
  @mail_schedule.send_test_mail_to!(params[:recipient], params[:sample_user_id])
47
- render :text => %Q{alert("Test Mail sent to #{params[:recipient]}"); $('#recipient').val('');}
47
+ render :js => %Q{alert("Test Mail sent to #{params[:recipient]}"); $('#recipient').val('');}
48
48
  rescue => e
49
- render :text => %Q{alert("Test Mail failed to send to #{params[:recipient]}, due to #{e.to_s}"); $('#recipient').val('');}
49
+ render :js => %Q{alert("Test Mail failed to send to #{params[:recipient]}, due to #{e.to_s.gsub(/\n/, '')}"); $('#recipient').val('');}
50
50
  end
51
51
 
52
52
  def start
@@ -34,7 +34,7 @@ class MailEngine::MailTemplateFilesController < MailEngine::ApplicationControlle
34
34
 
35
35
  def destroy
36
36
  @mail_template_file.destroy
37
- render :text => "window.location.reload()"
37
+ render :js => "window.location.reload()"
38
38
  end
39
39
 
40
40
  private
@@ -30,7 +30,6 @@ class MailEngine::MailDispatcher < ActionMailer::Base
30
30
  raise "No Template added." if templates.blank?
31
31
 
32
32
  subject = templates.first.subject
33
- formats = templates.map {|t| "format.#{t.format}" }.sort.reverse
34
33
 
35
34
  # generate the method for db template.
36
35
  class_eval <<-METHOD
@@ -53,9 +52,7 @@ class MailEngine::MailDispatcher < ActionMailer::Base
53
52
  instance_variable_set "@" + key.to_s, value
54
53
  end
55
54
 
56
- mail mail_options do |format|
57
- #{formats.join(';')}
58
- end
55
+ mail mail_options
59
56
  end
60
57
  METHOD
61
58
 
@@ -13,17 +13,6 @@ module ActionMailer
13
13
  headers[:subject] = Liquid::Template.parse(current_template.subject).render(instance_variable_hash) if current_template.present?
14
14
  headers[:message_id] = "#{controller_path}/#{action_name}"
15
15
 
16
- unless block_given?
17
- puts "\e[1;31;40m[Mail Engine Warning]\e[0m Please pass a block to 'mail' method as below style,
18
- mail engine needs you to specify the format to send:
19
- \e[1;34;40m
20
- mail :to => 'xxx@xxx.com' do |format|
21
- format.text
22
- format.html
23
- end
24
- \e[0m"
25
- end
26
-
27
16
  # Add sendgrid header before sending mail.
28
17
  # Why here but not add to default_params of action_mailer? because the receiver email [:to] only can get here.
29
18
  if self.sendgrid_config
@@ -47,19 +36,11 @@ module ActionMailer
47
36
  # need to set layout and pass partial path to each format of mail template.
48
37
  #
49
38
  # Completed copied from lib/action_mailer/base.rb#665
50
- # but used revisioned ActionMailer::Collector
51
39
  def collect_responses_and_parts_order(headers) #:nodoc:
52
40
  responses, parts_order = [], nil
53
41
 
54
42
  if block_given?
55
- ### modified this like, it's very strange when use resolver.is_a?(MailEngine::MailTemplate::Resolver) it will give false sometime.
56
- if lookup_context.view_paths.detect {|resolver| resolver.class.to_s == "MailEngine::MailTemplate::Resolver" }
57
- collector = ActionMailer::Collector.new(lookup_context) { |mime| set_layout_and_partials(mime) }
58
- else
59
- collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
60
- end
61
- ######################################################################################
62
-
43
+ collector = ActionMailer::Collector.new(lookup_context) { render(action_name) }
63
44
  yield(collector)
64
45
  parts_order = collector.responses.map { |r| r[:content_type] }
65
46
  responses = collector.responses
@@ -71,23 +52,27 @@ module ActionMailer
71
52
  else
72
53
  templates_path = headers.delete(:template_path) || self.class.mailer_name
73
54
  templates_name = headers.delete(:template_name) || action_name
74
-
75
55
  each_template(templates_path, templates_name) do |template|
76
56
  self.formats = template.formats
77
-
78
- responses << {
79
- :body => render(:template => template),
80
- :content_type => template.mime_type.to_s
81
- }
57
+ responses << if lookup_context.view_paths.detect {|resolver| resolver.class.to_s == "MailEngine::MailTemplateResolver" }
58
+ {
59
+ :body => render_with_layout_and_partials(template.mime_type.to_sym.to_s),
60
+ :content_type => template.mime_type.to_s
61
+ }
62
+ else
63
+ {
64
+ :body => render(:template => template),
65
+ :content_type => template.mime_type.to_s
66
+ }
67
+ end
82
68
  end
83
69
  end
84
70
 
85
71
  [responses, parts_order]
86
72
  end
87
73
 
88
-
89
- # set layout and partials
90
- def set_layout_and_partials(format)
74
+ # render template with layout and partials
75
+ def render_with_layout_and_partials(format)
91
76
  # looking for system mail.
92
77
  template = MailEngine::MailTemplate.where(:path => "#{controller_path}/#{action_name}", :format => format, :locale => I18n.locale, :partial => false, :for_marketing => false).first
93
78
  # looking for marketing mail.
@@ -109,25 +94,4 @@ module ActionMailer
109
94
  end
110
95
  end
111
96
  end
112
- end
113
-
114
- ###
115
- # REASON TO OVERRIDE THIS METHOD:
116
- # pass mime format to renderrer
117
- #
118
- # One concern if user provided block, there will be problem. like:
119
- # format.text { xxxx; render 'xxx' }
120
- #
121
- module ActionMailer
122
- class Collector
123
- def custom(mime, options={})
124
- options.reverse_merge!(:content_type => mime.to_s)
125
- @context.freeze_formats([mime.to_sym])
126
- ### modified this line
127
- # change from:
128
- # options[:body] = block_given? ? yield : @default_render.call
129
- options[:body] = block_given? ? yield : @default_render.call(mime.to_sym)
130
- @responses << options
131
- end
132
- end
133
97
  end
@@ -33,9 +33,8 @@ module MailEngine
33
33
  raise "Should specify :to option" if options[:to].blank?
34
34
 
35
35
  # find the template from database.
36
- template_path = File.join("mail_engine", "mail_dispatcher", template)
37
- unless mail_template = MailEngine::MailTemplate.where(:path => template_path, :locale => options[:locale], :for_marketing => true, :partial => false).first
38
- raise "Can't find the template: #{template_path}"
36
+ unless mail_template = MailEngine::MailTemplate.where(:path => template, :locale => options[:locale], :for_marketing => true, :partial => false).first
37
+ raise "Can't find the template: #{template}"
39
38
  end
40
39
 
41
40
  options[:subject] ||= mail_template.subject
@@ -22,8 +22,6 @@ module MailEngine
22
22
  initializer "mail_engine.register_database_template" do
23
23
  ActionMailer::Base.layout "layouts/mail_engine/mail_template_layouts/none"
24
24
  ActionMailer::Base.prepend_view_path(MailEngine::MailTemplateResolver.instance)
25
- # used when mail_template preview.
26
- MailEngine::ApplicationController.prepend_view_path(MailEngine::MailTemplateResolver.instance)
27
25
  end
28
26
 
29
27
  initializer "mail_engine.add_acts_as_mail_receiver" do
@@ -11,8 +11,8 @@ module MailEngine
11
11
 
12
12
  conditions = {
13
13
  :path => template_path_and_name,
14
- :locale => normalize_array(details[:locale]).first,
15
- :format => normalize_array(details[:formats]).first,
14
+ :locale => normalize_array(details[:locale]),
15
+ :format => normalize_array(details[:formats]),
16
16
  :handler => normalize_array(details[:handlers]),
17
17
  :partial => partial || false
18
18
  }
data/mail_engine.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mail_engine}
8
- s.version = "0.1.10"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["michael he"]
@@ -17,10 +17,7 @@ class UserMailer < ActionMailer::Base
17
17
 
18
18
  # html must below text
19
19
  # should use subject in the db mail template.
20
- mail :to => to, :subject => "subject in mailer" do |f|
21
- f.text
22
- f.html
23
- end
20
+ mail :to => to, :subject => "subject in mailer"
24
21
  end
25
22
 
26
23
  def notify_to_user(user)
@@ -28,9 +25,6 @@ class UserMailer < ActionMailer::Base
28
25
  @lastname = user.lastname
29
26
 
30
27
  # html must below text
31
- mail :to => user.email do |f|
32
- f.text
33
- f.html
34
- end
28
+ mail :to => user.email
35
29
  end
36
30
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_engine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 10
10
- version: 0.1.10
9
+ - 11
10
+ version: 0.1.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - michael he