actionmailer-with-request 0.1.1 → 0.3.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.
data/.gitignore CHANGED
@@ -1 +1,4 @@
1
- pkg/
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in macair:actionmailer_with_request.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009-2011 Simone Carletti
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 CHANGED
@@ -4,3 +4,33 @@ This is a simple plugin that aims to solve the problem to pass a dynamic host fo
4
4
 
5
5
  For more information, read my blog post at
6
6
  http://www.simonecarletti.com/blog/2009/10/actionmailer-and-host-value/
7
+
8
+
9
+ == Requirements
10
+
11
+ * Rails 3
12
+
13
+ Please note
14
+
15
+ * ActionMailerWithRequest >= 0.3 requires Rails 3. Use TabsOnRails 0.2.x with Rails 2.
16
+
17
+
18
+ == Installation
19
+
20
+ $ gem install actionmailer-with-request
21
+
22
+
23
+ == Author
24
+
25
+ * {Simone Carletti}[http://www.simonecarletti.com] <weppos@weppos.net>
26
+
27
+
28
+ == Contributors
29
+
30
+ Eric Anderson, Didier Lafforgue.
31
+
32
+
33
+ == License
34
+
35
+ ActionMailerWithRequest is Copyright (c) 2009-2011 Simone Carletti.
36
+ This is Free Software distributed under the MIT license.
data/Rakefile CHANGED
@@ -1,16 +1,2 @@
1
- require 'rake'
2
-
3
- begin
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gem|
6
- gem.name = "actionmailer-with-request"
7
- gem.summary = "A simple plugin to make the Rails request context available for generating URLs in ActionMailer. Works with Rails 3 (not tested with 2.3.x)"
8
- gem.email = "weppos@weppos.net"
9
- gem.homepage = "http://github.com/weppos/actionmailer_with_request"
10
- gem.authors = ["Simone Carletti"]
11
- end
12
-
13
- Jeweler::GemcutterTasks.new
14
- rescue LoadError
15
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
16
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -1,44 +1,22 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{actionmailer-with-request}
8
- s.version = "0.1.1"
5
+ s.name = "actionmailer-with-request"
6
+ s.version = "0.3.0"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = "Simone Carletti"
9
+ s.email = "weppos@weppos.net"
10
+ s.homepage = "http://github.com/weppos/actionmailer_with_request"
11
+ s.summary = "Let's ActionMailer know about the website."
12
+ s.description = "Let's ActionMailer know about the request context to avoid having to set a number of defaults manually."
9
13
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Simone Carletti"]
12
- s.date = %q{2010-06-11}
13
- s.email = %q{weppos@weppos.net}
14
- s.extra_rdoc_files = [
15
- "README"
16
- ]
17
- s.files = [
18
- ".gitignore",
19
- "README",
20
- "Rakefile",
21
- "VERSION",
22
- "actionmailer-with-request.gemspec",
23
- "lib/action_mailer_with_request/controller_mixin.rb",
24
- "lib/action_mailer_with_request/mailer_default_url_options.rb",
25
- "lib/action_mailer_with_request/railtie.rb",
26
- "lib/actionmailer_with_request.rb"
27
- ]
28
- s.homepage = %q{http://github.com/weppos/actionmailer_with_request}
29
- s.rdoc_options = ["--charset=UTF-8"]
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
17
  s.require_paths = ["lib"]
31
- s.rubygems_version = %q{1.3.6}
32
- s.summary = %q{A simple plugin to make the Rails request context available for generating URLs in ActionMailer. Works with Rails 3 (not tested with 2.3.x)}
33
18
 
34
- if s.respond_to? :specification_version then
35
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
- s.specification_version = 3
19
+ s.add_dependency "rails", ">= 3"
37
20
 
38
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
39
- else
40
- end
41
- else
42
- end
21
+ s.rdoc_options << "--main" << "README"
43
22
  end
44
-
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'actionmailer_with_request'
@@ -0,0 +1,12 @@
1
+ # This file is required for BC with the existing
2
+ # "actionmailer-with-request" Gem. When Ruby (the Rails process) loads
3
+ # the library, it attempts to require a file called with the same name
4
+ # of the Gem. But because the Gem file is called with underscores,
5
+ # it won't be loaded.
6
+ #
7
+ # The choices were:
8
+ #
9
+ # 1. rename the existing Gem
10
+ # 2. add this hack
11
+ #
12
+ require 'actionmailer_with_request'
@@ -1,4 +1,67 @@
1
- require 'action_mailer_with_request/controller_mixin'
2
- require 'action_mailer_with_request/mailer_default_url_options'
1
+ module ActionMailerWithRequest
3
2
 
4
- require 'action_mailer_with_request/railtie'
3
+ module ControllerMixin
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ before_filter :store_request
8
+ end
9
+ end
10
+
11
+ def store_request
12
+ Thread.current[:request] = request
13
+ end
14
+
15
+ end
16
+
17
+ module MailerDefaultUrlOptions
18
+
19
+ def self.included(base)
20
+ base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
21
+ # Extends ActionMailer#default_url_options capabilities
22
+ # by merging the latest request context into the default url options.
23
+ #
24
+ # Returns the default url options Hash.
25
+ def default_url_options_with_current_request(*args)
26
+ defaults = {}
27
+ request = Thread.current[:request]
28
+
29
+ if request
30
+ host = request.host
31
+ port = request.port
32
+ protocol = request.protocol
33
+ standard_port = request.standard_port
34
+
35
+ defaults[:protocol] = protocol
36
+ defaults[:host] = host
37
+ defaults[:port] = port if port != standard_port
38
+ end
39
+
40
+ default_url_options_without_current_request(*args).merge(defaults)
41
+ end
42
+
43
+ alias_method_chain :default_url_options, :current_request
44
+ RUBY
45
+ end
46
+
47
+ # Get the current request. This assists in making request-based
48
+ # e-mail addresses. For example:
49
+ #
50
+ # mail :from => "no-reply@#{request.try(:domain) || 'example.com'}", .....
51
+ #
52
+ # Remember if the mailer is delivered outside the context of a
53
+ # request then this method returns nil. Hence the try(:domain)
54
+ # as well as the fallback domain.
55
+ def request
56
+ Thread.current[:request]
57
+ end
58
+
59
+ end
60
+
61
+ class Railtie < Rails::Railtie
62
+ initializer 'actionmailer.with_request' do
63
+ ActionController::Base.send :include, ActionMailerWithRequest::ControllerMixin
64
+ ActionMailer::Base.send :include, ActionMailerWithRequest::MailerDefaultUrlOptions
65
+ end
66
+ end
67
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionmailer-with-request
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
4
+ prerelease:
5
+ version: 0.3.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Simone Carletti
@@ -14,57 +10,65 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-06-11 00:00:00 +02:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description:
13
+ date: 2011-04-18 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "3"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: Let's ActionMailer know about the request context to avoid having to set a number of defaults manually.
22
27
  email: weppos@weppos.net
23
28
  executables: []
24
29
 
25
30
  extensions: []
26
31
 
27
- extra_rdoc_files:
28
- - README
32
+ extra_rdoc_files: []
33
+
29
34
  files:
30
35
  - .gitignore
36
+ - Gemfile
37
+ - LICENSE
31
38
  - README
32
39
  - Rakefile
33
- - VERSION
34
40
  - actionmailer-with-request.gemspec
35
- - lib/action_mailer_with_request/controller_mixin.rb
36
- - lib/action_mailer_with_request/mailer_default_url_options.rb
37
- - lib/action_mailer_with_request/railtie.rb
41
+ - init.rb
42
+ - lib/actionmailer-with-request.rb
38
43
  - lib/actionmailer_with_request.rb
39
- has_rdoc: true
40
44
  homepage: http://github.com/weppos/actionmailer_with_request
41
45
  licenses: []
42
46
 
43
47
  post_install_message:
44
48
  rdoc_options:
45
- - --charset=UTF-8
49
+ - --main
50
+ - README
46
51
  require_paths:
47
52
  - lib
48
53
  required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
49
55
  requirements:
50
56
  - - ">="
51
57
  - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
58
  version: "0"
55
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
56
61
  requirements:
57
62
  - - ">="
58
63
  - !ruby/object:Gem::Version
59
- segments:
60
- - 0
61
64
  version: "0"
62
65
  requirements: []
63
66
 
64
67
  rubyforge_project:
65
- rubygems_version: 1.3.6
68
+ rubygems_version: 1.7.2
66
69
  signing_key:
67
70
  specification_version: 3
68
- summary: A simple plugin to make the Rails request context available for generating URLs in ActionMailer. Works with Rails 3 (not tested with 2.3.x)
71
+ summary: Let's ActionMailer know about the website.
69
72
  test_files: []
70
73
 
74
+ has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1
@@ -1,15 +0,0 @@
1
- module ActionMailerWithRequest
2
- module ControllerMixin
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- before_filter :store_request
7
- end
8
- end
9
-
10
- def store_request
11
- Thread.current[:request] = request
12
- end
13
-
14
- end
15
- end
@@ -1,19 +0,0 @@
1
- module ActionMailerWithRequest
2
- module MailerDefaultUrlOptions
3
-
4
- def self.included(base)
5
- base.class_eval do
6
- def default_url_options_with_current_request
7
- host = Thread.current[:request].try(:host)
8
- port = Thread.current[:request].try(:port)
9
- default = {}
10
- default[:host] = host if host
11
- default[:port] = port if port and port != 80
12
- default_url_options_without_current_request.merge(default)
13
- end
14
- alias_method_chain :default_url_options, :current_request
15
- end
16
- end
17
-
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- module ActionMailerWithRequest
2
- class Railtie < Rails::Railtie
3
-
4
- initializer "action_mailer_with_request.default_url_options" do |app|
5
- ActionController::Base.send :include, ActionMailerWithRequest::ControllerMixin
6
- ActionMailer::Base.send :include, ActionMailerWithRequest::MailerDefaultUrlOptions
7
-
8
- Rails.logger.info("** ActionMailerWithRequest: initialized properly") if defined?(Rails)
9
- end
10
- end
11
- end