padrino-mailer 0.16.0.pre4 → 0.16.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a39de3466c63a873148cfe2b7505c63eca732ab67d2eaee4459b40fe18d56fdb
4
- data.tar.gz: 9e17be58b8de1b8f76e66abe6ef41d08eab519aa8c7645fad7d9418db55f7b87
3
+ metadata.gz: c46c1f19967fd458ae6b7a70a8941dca6034e5efe925b2bda5676ac304820259
4
+ data.tar.gz: 39603fd4d73b1c39ee81079bd2abc23b6f6daa3c5516f3404a4df3dc6c0353f7
5
5
  SHA512:
6
- metadata.gz: 2dce0ac3d7e5e69b10cb16f0faf11d30724a1a47b85b3720288526626364066ef68ade6ca92fa2a78480d635e1240bd3e9917ba2983d80cf1d31a707a0da387a
7
- data.tar.gz: 35fba3bb110e839a078851451ab2e2a7fcb85590d44b5c22eada6308c5c26f9baebd0cc98308eb14ac38c8362d99adedb81060270d7cab8428026da2bc937aee
6
+ metadata.gz: 1ce813f2e2349a375585cb91a9344cc6e5b4481abd4a696810df88dd4c369c69863ea7002de0069c3f996f90642a99254c25ab523170edbe9dd61a79be942adc
7
+ data.tar.gz: 3e9f4ea2c1f6400b3003e44557d9edd433d58892473a0c98d33d8e3b6b22efd931b165a2dd874c5e857e063c31ed703a24eb383c0db572615469f64570a6ef82
data/README.rdoc CHANGED
@@ -13,14 +13,14 @@ Let's take a look at using the Mailer in an application. By default, the Mailer
13
13
  command on the server. However, SMTP is also supported using the following configuration:
14
14
 
15
15
  # Example for configuring gmail smtp
16
- set :delivery_method, :smtp => {
17
- :address => "smtp.gmail.com",
18
- :port => 587,
19
- :domain => 'your.host.name',
20
- :user_name => '<username>',
21
- :password => '<password>',
22
- :authentication => 'plain',
23
- :enable_starttls_auto => true
16
+ set :delivery_method, smtp: {
17
+ address: "smtp.gmail.com",
18
+ port: 587,
19
+ domain: 'your.host.name',
20
+ user_name: '<username>',
21
+ password: '<password>',
22
+ authentication: 'plain',
23
+ enable_starttls_auto: true
24
24
  }
25
25
 
26
26
  Once the delivery settings have been defined, the default will become smtp delivery but can be
@@ -33,7 +33,7 @@ Delivering an email from within your controller is simple:
33
33
 
34
34
  # app/controllers/session.rb
35
35
  post :create do
36
- email(:to => "john@smith.com", :subject => "Successfully Registered!", :body => "Test Body")
36
+ email(to: "john@smith.com", subject: "Successfully Registered!", body: "Test Body")
37
37
  end
38
38
 
39
39
  Padrino also supports structured mailer declarations. We can define a new mailer using a <tt>mailer</tt> block.
@@ -41,14 +41,14 @@ Padrino also supports structured mailer declarations. We can define a new mailer
41
41
  # app/mailers/sample_mailer.rb
42
42
  MyAppName.mailers :sample do
43
43
  email :registration do |name|
44
- from 'admin@site.com'
45
- to 'user@domain.com'
46
- subject 'Welcome to the site!'
47
- locals :name => name
48
- content_type 'html' # optional, defaults to plain/text
49
- charset 'windows-1252' # optional, defaults to utf-8
50
- via :sendmail # optional, smtp if defined otherwise sendmail
51
- render 'registration'
44
+ from 'admin@site.com'
45
+ to 'user@domain.com'
46
+ subject 'Welcome to the site!'
47
+ locals name: name
48
+ content_type 'html' # optional, defaults to plain/text
49
+ charset 'windows-1252' # optional, defaults to utf-8
50
+ via :sendmail # optional, smtp if defined otherwise sendmail
51
+ render 'registration'
52
52
  end
53
53
  end
54
54
 
@@ -69,16 +69,16 @@ In addition to a standard body, Padrino also easily supports multi-part emails:
69
69
  Defaults can also be declared on a per-mailer or app-wide basis:
70
70
 
71
71
  # app/app.rb
72
- set :mailer_defaults, :from => 'admin@site.com'
72
+ set :mailer_defaults, from: 'admin@site.com'
73
73
 
74
74
  # app/mailers/sample_mailer.rb
75
75
  MyAppName.mailers :sample do
76
- defaults :content_type => 'html'
76
+ defaults content_type: 'html'
77
77
  email :registration do |name, age|
78
78
  # Uses default 'content_type' and 'from' values but can also overwrite them
79
79
  to 'user@domain.com'
80
80
  subject 'Welcome to the site!'
81
- locals :name => name
81
+ locals name: name
82
82
  render 'registration'
83
83
  end
84
84
  end
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
1
+ require_relative '../gem_rake_helper'
@@ -5,12 +5,12 @@ module Padrino
5
5
  #
6
6
  # You can set the default delivery settings from your app through:
7
7
  #
8
- # set :delivery_method, :smtp => {
9
- # :address => 'smtp.yourserver.com',
10
- # :port => '25',
11
- # :user_name => 'user',
12
- # :password => 'pass',
13
- # :authentication => :plain
8
+ # set :delivery_method, smtp: {
9
+ # address: 'smtp.yourserver.com',
10
+ # port: '25',
11
+ # user_name: 'user',
12
+ # password: 'pass',
13
+ # authentication: :plain
14
14
  # }
15
15
  #
16
16
  # or sendmail:
@@ -27,12 +27,12 @@ module Padrino
27
27
  #
28
28
  # # app/mailers/sample_mailer.rb
29
29
  # MyAppName.mailers :sample do
30
- # defaults :content_type => 'html'
30
+ # defaults content_type: 'html'
31
31
  # email :registration do |name, age|
32
32
  # to 'user@domain.com'
33
33
  # from 'admin@site.com'
34
34
  # subject 'Welcome to the site!'
35
- # locals :name => name
35
+ # locals name: name
36
36
  # render 'registration'
37
37
  # end
38
38
  # end
@@ -74,15 +74,15 @@ module Padrino
74
74
  # @example
75
75
  # email :birthday do |name, age|
76
76
  # subject "Happy Birthday!"
77
- # to 'john@fake.com'
78
- # from 'noreply@birthday.com'
79
- # locals 'name' => name, 'age' => age
77
+ # to 'john@fake.com'
78
+ # from 'noreply@birthday.com'
79
+ # locals name: name, age: age
80
80
  # render 'birthday'
81
81
  # end
82
82
  #
83
83
  def email(name, &block)
84
84
  raise "The email '#{name}' is already defined" if self.messages[name]
85
- self.messages[name] = Proc.new { |*attrs|
85
+ self.messages[name] = proc { |*attrs|
86
86
  message = app.settings._padrino_mailer::Message.new(self.app)
87
87
  message.mailer_name = mailer_name
88
88
  message.message_name = name
@@ -92,7 +92,7 @@ module Padrino
92
92
  message
93
93
  }
94
94
  end
95
- alias :message :email
95
+ alias message email
96
96
 
97
97
  # Defines the default attributes for a message in this mailer
98
98
  # (including app-wide defaults).
@@ -102,11 +102,11 @@ module Padrino
102
102
  #
103
103
  # @example
104
104
  # mailer :alternate do
105
- # defaults :from => 'padrino@from.com', :to => 'padrino@to.com'
105
+ # defaults from: 'padrino@from.com', to: 'padrino@to.com'
106
106
  # email(:foo) do; end
107
107
  # end
108
108
  #
109
- def defaults(attributes=nil)
109
+ def defaults(attributes = nil)
110
110
  if attributes.nil? # Retrieve the default values
111
111
  @app.respond_to?(:mailer_defaults) ? @app.mailer_defaults.merge(@defaults) : @defaults
112
112
  else # updates the default values
@@ -16,7 +16,7 @@ module Mail # @private
16
16
  settings.views = File.join(app.views, 'mailers')
17
17
  settings.reload_templates = app.reload_templates?
18
18
  else
19
- settings.views = File.expand_path("./mailers")
19
+ settings.views = File.expand_path('./mailers')
20
20
  settings.reload_templates = true
21
21
  end
22
22
 
@@ -24,8 +24,8 @@ module Mail # @private
24
24
 
25
25
  initialize_without_app(*args, &block)
26
26
  end
27
- alias_method :initialize_without_app, :initialize
28
- alias_method :initialize, :initialize_with_app
27
+ alias initialize_without_app initialize
28
+ alias initialize initialize_with_app
29
29
 
30
30
  ##
31
31
  # Setup like in Sinatra/Padrino apps content_type and template lookup.
@@ -59,9 +59,9 @@ module Mail # @private
59
59
  # text_part { render('multipart/basic.text') }
60
60
  #
61
61
  def text_part(value = nil, &block)
62
- add_resolved_part(:variable => :text_part,
63
- :value => value,
64
- :content_type => 'text/plain',
62
+ add_resolved_part(variable: :text_part,
63
+ value: value,
64
+ content_type: 'text/plain',
65
65
  &block)
66
66
  end
67
67
 
@@ -75,18 +75,18 @@ module Mail # @private
75
75
  # html_part { render('multipart/basic.html') }
76
76
  #
77
77
  def html_part(value = nil, &block)
78
- add_resolved_part(:variable => :html_part,
79
- :value => value,
80
- :content_type => 'text/html',
78
+ add_resolved_part(variable: :html_part,
79
+ value: value,
80
+ content_type: 'text/html',
81
81
  &block)
82
82
  end
83
83
 
84
84
  def add_resolved_part(attributes = {}, &block)
85
85
  variable, value, content_type = attributes.values_at(:variable, :value, :content_type)
86
86
  if block_given? || value
87
- instance_variable_set "@#{variable}", self.part(:content_type => content_type,
88
- :body => value,
89
- :part_block => block)
87
+ instance_variable_set "@#{variable}", self.part(content_type: content_type,
88
+ body: value,
89
+ part_block: block)
90
90
  add_multipart_alternate_header if self.send(variable)
91
91
  else
92
92
  instance_variable_get("@#{variable}") || find_first_mime_type(content_type)
@@ -98,9 +98,9 @@ module Mail # @private
98
98
  #
99
99
  # @example
100
100
  # mail = Mail.new do
101
- # part :content_type => "multipart/alternative", :content_disposition => "inline" do |p|
102
- # p.part :content_type => "text/plain", :body => "test text\nline #2"
103
- # p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
101
+ # part content_type: 'multipart/alternative', content_disposition: 'inline' do |p|
102
+ # p.part content_type: 'text/plain', body: "test text\nline #2"
103
+ # p.part content_type: 'text/html', body: "<b>test</b> HTML<br/>\nline #2"
104
104
  # end
105
105
  # end
106
106
  #
@@ -116,13 +116,14 @@ module Mail # @private
116
116
  end
117
117
 
118
118
  def do_delivery_with_logging
119
- logger.debug "Sending email to: #{destinations.join(" ")}"
120
- encoded.each_line { |line| logger << (" " + line.strip) } if logger.debug?
119
+ logger.debug "Sending email to: #{destinations.join(' ')}"
120
+ encoded.each_line { |line| logger << " #{line.strip}" } if logger.debug?
121
121
  do_delivery_without_logging
122
122
  end
123
+
123
124
  if Padrino.respond_to?(:logger)
124
- alias_method :do_delivery_without_logging, :do_delivery
125
- alias_method :do_delivery, :do_delivery_with_logging
125
+ alias do_delivery_without_logging do_delivery
126
+ alias do_delivery do_delivery_with_logging
126
127
  end
127
128
 
128
129
  ##
@@ -136,7 +137,7 @@ module Mail # @private
136
137
  # Sinatra almost compatibility.
137
138
  #
138
139
  def self.set(name, value)
139
- self.class.instance_eval{ define_method(name) { value } unless method_defined?(:erb) }
140
+ self.class.instance_eval { define_method(name) { value } unless method_defined?(:erb) }
140
141
  end
141
142
 
142
143
  ##
@@ -192,14 +193,14 @@ module Mail # @private
192
193
  # Return the path of this file, only for compatibility with Sinatra rendering methods.
193
194
  #
194
195
  def self.caller_locations
195
- [[File.dirname(__FILE__), 1]]
196
+ [[__dir__, 1]]
196
197
  end
197
198
 
198
199
  ##
199
200
  # Return the default encoding.
200
201
  #
201
202
  def self.default_encoding
202
- "utf-8"
203
+ 'utf-8'
203
204
  end
204
205
 
205
206
  ##
@@ -241,20 +242,20 @@ module Mail # @private
241
242
  #
242
243
  # See Padrino::Mailer::Mime for more usage informations.
243
244
  #
244
- def content_type_with_symbol(value=nil)
245
- value = Padrino::Mailer::Mime::MIME_TYPES.find { |k,v| v == value }[0] rescue value if value.is_a?(Symbol)
245
+ def content_type_with_symbol(value = nil)
246
+ value = Padrino::Mailer::Mime::MIME_TYPES.find { |_k, v| v == value }[0] rescue value if value.is_a?(Symbol)
246
247
  mime = content_type_without_symbol(value)
247
248
  Padrino::Mailer::Mime.mime_type(mime)
248
249
  end
249
- alias_method :content_type_without_symbol, :content_type
250
- alias_method :content_type, :content_type_with_symbol
250
+ alias content_type_without_symbol content_type
251
+ alias content_type content_type_with_symbol
251
252
 
252
253
  private
253
254
 
254
255
  ##
255
256
  # Defines the render for the mailer utilizing the padrino 'rendering' module
256
257
  #
257
- def render(engine=nil, data=nil, options={}, locals={}, &block)
258
+ def render(engine = nil, data = nil, options = {}, locals = {}, &block)
258
259
  locals = @_locals || {} if !options[:locals] && locals.empty?
259
260
  @template_cache.clear if settings.reload_templates?
260
261
 
@@ -276,8 +277,8 @@ module Mail # @private
276
277
  self.body = super(engine, data, options, locals, &block) if provides.empty?
277
278
  end
278
279
 
279
- alias_method :original_partial, :partial if instance_methods.include?(:partial)
280
- def partial(template, options={}, &block)
280
+ alias original_partial partial if instance_methods.include?(:partial)
281
+ def partial(template, options = {}, &block)
281
282
  raise "gem 'padrino-helpers' is required to render partials" unless respond_to?(:original_partial)
282
283
  self.body = original_partial(template, options, &block)
283
284
  end
@@ -19,14 +19,14 @@ module Padrino
19
19
  # @example
20
20
  # email do
21
21
  # to @user.email
22
- # from "awesomeness@example.com"
23
- # subject "Welcome to Awesomeness!"
24
- # locals :a => a, :b => b
22
+ # from 'awesomeness@example.com'
23
+ # subject 'Welcome to Awesomeness!'
24
+ # locals a: a, b: b
25
25
  # render 'path/to/my/template'
26
26
  # end
27
27
  #
28
28
  # @see ClassMethods#email
29
- def email(mail_attributes={}, &block)
29
+ def email(mail_attributes = {}, &block)
30
30
  settings.email(mail_attributes, &block)
31
31
  end
32
32
 
@@ -41,8 +41,8 @@ module Padrino
41
41
  # The parameters to pass to the mailer.
42
42
  #
43
43
  # @example
44
- # deliver(:sample, :birthday, "Joey", 21)
45
- # deliver(:example, :message, "John")
44
+ # deliver(:sample, :birthday, 'Joey', 21)
45
+ # deliver(:example, :message, 'John')
46
46
  #
47
47
  # @see ClassMethods#deliver
48
48
  def deliver(mailer_name, message_name, *attributes)
@@ -78,7 +78,7 @@ module Padrino
78
78
  # subject 'Happy Birthday!'
79
79
  # to 'john@fake.com'
80
80
  # from 'noreply@birthday.com'
81
- # locals :name => name, :age => age
81
+ # locals name: name, age: age
82
82
  # render 'sample/birthday'
83
83
  # end
84
84
  # end
@@ -89,7 +89,7 @@ module Padrino
89
89
  registered_mailers[name] = mailer
90
90
  mailer
91
91
  end
92
- alias :mailers :mailer
92
+ alias mailers mailer
93
93
 
94
94
  ##
95
95
  # Delivers a mailer message email with the given attributes.
@@ -102,12 +102,12 @@ module Padrino
102
102
  # The parameters to pass to the mailer.
103
103
  #
104
104
  # @example
105
- # deliver(:sample, :birthday, "Joey", 21)
106
- # deliver(:example, :message, "John")
105
+ # deliver(:sample, :birthday, 'Joey', 21)
106
+ # deliver(:example, :message, 'John')
107
107
  #
108
108
  def deliver(mailer_name, message_name, *attributes)
109
- mailer = registered_mailers[mailer_name] or fail "mailer '#{mailer_name}' is not registered"
110
- message = mailer.messages[message_name] or fail "mailer '#{mailer_name}' has no message '#{message_name}'"
109
+ mailer = registered_mailers[mailer_name] or raise "mailer '#{mailer_name}' is not registered"
110
+ message = mailer.messages[message_name] or raise "mailer '#{mailer_name}' has no message '#{message_name}'"
111
111
  message = message.call(*attributes)
112
112
  message.delivery_method(*delivery_settings)
113
113
  message.deliver
@@ -122,18 +122,18 @@ module Padrino
122
122
  # The block mail attributes for this message.
123
123
  #
124
124
  # @example
125
- # MyApp.email(:to => 'to@ma.il', :from => 'from@ma.il', :subject => 'Welcome!', :body => 'Welcome Here!')
125
+ # MyApp.email(to: 'to@ma.il', from: 'from@ma.il', subject: 'Welcome!', body: 'Welcome Here!')
126
126
  #
127
127
  # # or if you prefer blocks
128
128
  #
129
129
  # MyApp.email do
130
- # to @user.email
131
- # from "awesomeness@example.com"
132
- # subject "Welcome to Awesomeness!"
133
- # body 'path/to/my/template', :locals => { :a => a, :b => b }
130
+ # to @user.email
131
+ # from 'awesomeness@example.com'
132
+ # subject 'Welcome to Awesomeness!'
133
+ # body 'path/to/my/template', locals: { a: a, b: b }
134
134
  # end
135
135
  #
136
- def email(mail_attributes={}, &block)
136
+ def email(mail_attributes = {}, &block)
137
137
  message = _padrino_mailer::Message.new(self)
138
138
  message.delivery_method(*delivery_settings)
139
139
  message.instance_eval(&block) if block_given?
@@ -143,16 +143,17 @@ module Padrino
143
143
  end
144
144
 
145
145
  private
146
+
146
147
  ##
147
148
  # Returns the parsed delivery method options.
148
149
  #
149
150
  def delivery_settings
150
151
  @_delivery_setting ||= begin
151
152
  if Gem.win_platform? && !respond_to?(:delivery_method)
152
- raise "To use mailers on Windows you must set a :delivery_method, see http://padrinorb.com/guides/features/padrino-mailer/#configuration"
153
+ raise 'To use mailers on Windows you must set a :delivery_method, see http://padrinorb.com/guides/features/padrino-mailer/#configuration'
153
154
  end
154
155
 
155
- return [:sendmail, { :location => `which sendmail`.chomp }] unless respond_to?(:delivery_method)
156
+ return [:sendmail, { location: `which sendmail`.chomp }] unless respond_to?(:delivery_method)
156
157
  return [delivery_method.keys[0], delivery_method.values[0]] if delivery_method.is_a?(Hash)
157
158
  return [delivery_method, {}] if delivery_method.is_a?(Symbol)
158
159
  [nil, {}]
@@ -26,7 +26,7 @@ module Padrino
26
26
  #
27
27
  # Padrino::Mailer::Mime::MIME_TYPES.fetch('text/plain', :plain)
28
28
  #
29
- def self.mime_type(mime, fallback=:plain)
29
+ def self.mime_type(mime, fallback = :plain)
30
30
  MIME_TYPES.fetch(mime.to_s.split(';').first.to_s.downcase, fallback)
31
31
  end
32
32
 
@@ -39,9 +39,9 @@ module Padrino
39
39
  # Padrino::Mailer::Mime::MIME_TYPES.merge!("text/xml" => :xml)
40
40
  #
41
41
  MIME_TYPES = {
42
- "text/html" => :html,
43
- "text/plain" => :plain,
44
- "text/xml" => :xml
42
+ 'text/html' => :html,
43
+ 'text/plain' => :plain,
44
+ 'text/xml' => :xml
45
45
  }
46
46
  end
47
47
  end
@@ -46,11 +46,9 @@ module Padrino
46
46
  app._padrino_mailer = Mail
47
47
  }
48
48
  app.helpers Padrino::Mailer::Helpers
49
- unless app.respond_to?(:mailer)
50
- app.send(:extend, Padrino::Mailer::Helpers::ClassMethods)
51
- end
49
+ app.send(:extend, Padrino::Mailer::Helpers::ClassMethods) unless app.respond_to?(:mailer)
52
50
  end
53
- alias :included :registered
51
+ alias included registered
54
52
  end
55
53
  end
56
54
  end
@@ -1,28 +1,28 @@
1
1
  #!/usr/bin/env gem build
2
2
  # encoding: utf-8
3
3
 
4
- require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
4
+ require File.expand_path('../padrino-core/lib/padrino-core/version.rb', __dir__)
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "padrino-mailer"
8
- s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
9
- s.email = "padrinorb@gmail.com"
10
- s.summary = "Mailer system for padrino"
11
- s.homepage = "http://www.padrinorb.com"
12
- s.description = "Mailer system for padrino allowing easy delivery of application emails"
13
- s.required_rubygems_version = ">= 1.3.6"
7
+ s.name = 'padrino-mailer'
8
+ s.authors = ['Padrino Team', 'Nathan Esquenazi', "Davide D'Agostino", 'Arthur Chiu']
9
+ s.email = 'padrinorb@gmail.com'
10
+ s.summary = 'Mailer system for padrino'
11
+ s.homepage = 'http://www.padrinorb.com'
12
+ s.description = 'Mailer system for padrino allowing easy delivery of application emails'
13
+ s.required_rubygems_version = '>= 1.3.6'
14
14
  s.version = Padrino.version
15
- s.date = Time.now.strftime("%Y-%m-%d")
16
- s.license = "MIT"
15
+ s.date = Time.now.strftime('%Y-%m-%d')
16
+ s.license = 'MIT'
17
17
 
18
- s.extra_rdoc_files = Dir["*.rdoc"]
18
+ s.extra_rdoc_files = Dir['*.rdoc']
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- s.require_paths = ["lib"]
23
- s.rdoc_options = ["--charset=UTF-8"]
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
+ s.require_paths = ['lib']
23
+ s.rdoc_options = ['--charset=UTF-8']
24
24
 
25
- s.add_dependency("padrino-core", Padrino.version)
26
- s.add_dependency("mime-types", ">= 3.1", "< 4")
27
- s.add_dependency("mail", "~> 2.5")
25
+ s.add_dependency('padrino-core', Padrino.version)
26
+ s.add_dependency('mime-types', '>= 3.1', '< 4')
27
+ s.add_dependency('mail', '~> 2.5')
28
28
  end