rails-named-routes-options 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/CHANGELOG +5 -0
- data/Gemfile +7 -0
- data/LICENSE +20 -0
- data/README.textile +13 -0
- data/lib/rails-named-routes-options.rb +45 -0
- data/rails-named-routes-options.gemspec +34 -0
- data/rails-named-routes-options.pre.gemspec +8 -0
- data/spec/rails-named-routes-options_spec.rb +10 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +11 -0
- metadata +76 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Jakub Stastny aka Botanicus
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
h1. About
|
2
|
+
|
3
|
+
This Rails plugin adds @default_named_routes_options@ to the controllers and mailers. It comes handy for example when you are working on mailers. You have to specify the whole URI in your links, because otherwise these links obviously can't work in these emails. To ensure this works, you have to specify a host via @default_url_options@ method and then you need to specify @only_path: false@ for each link in your mailer views. This is pretty annoying and of course when you forget about it, your clients won't be very happy.
|
4
|
+
|
5
|
+
h1. Usage
|
6
|
+
|
7
|
+
<pre>
|
8
|
+
# this comes from Rails itself
|
9
|
+
ActionMailer::Base.default_url_options[:host] = "http://example.com"
|
10
|
+
|
11
|
+
# and this from the plugin
|
12
|
+
ActionMailer::Base.default_named_routes_options[:only_path] = false
|
13
|
+
</pre>
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# === Usage ===
|
4
|
+
# class InvitationsMailer < ActionMailer::Base
|
5
|
+
# default_named_routes_options[:only_path] = false
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# or just:
|
9
|
+
# ActionMailer::Base.default_named_routes_options[:only_path] = false
|
10
|
+
|
11
|
+
module NamedRoutesOptions
|
12
|
+
def routes_names
|
13
|
+
methods = self.instance_methods
|
14
|
+
methods.grep(/_path$/).inject(Array.new) do |result, method|
|
15
|
+
name = method.match(/^(.+)_path$/)[1]
|
16
|
+
result.push(name) if methods.include?("#{name}_url")
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# NOTE: this can't be a class variable, because class variables are shared
|
22
|
+
attr_writer :default_named_routes_options
|
23
|
+
def default_named_routes_options
|
24
|
+
@default_named_routes_options ||= Hash.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.extended(mailer)
|
28
|
+
super(mailer)
|
29
|
+
mailer.class_eval do
|
30
|
+
self.routes_names.each do |route|
|
31
|
+
helper_method "#{route}_path", "#{route}_url"
|
32
|
+
define_method("#{route}_path") do |*args|
|
33
|
+
options = args.last.is_a?(Hash) ? args.pop : Hash.new
|
34
|
+
args.push(options.reverse_merge!(:only_path => false))
|
35
|
+
super(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method "#{route}_url", "#{route}_path"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
ActionMailer::Base.extend(NamedRoutesOptions) if defined?(ActionMailer)
|
45
|
+
ActionController::Base.extend(NamedRoutesOptions) if defined?(ActionController)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env gem build
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "base64"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rails-named-routes-options"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
s.authors = ["Jakub Stastny aka Botanicus"]
|
10
|
+
s.homepage = "http://github.com/botanicus/rails-named-routes-options"
|
11
|
+
s.summary = "This Rails plugin adds default_named_routes_options to your controllers and mailers"
|
12
|
+
s.description = "#{s.summary}, so you can specify default options for named routes like ActionMailer::Base.default_named_routes_options[:only_path] = false"
|
13
|
+
s.cert_chain = nil
|
14
|
+
s.email = Base64.decode64("c3Rhc3RueUAxMDFpZGVhcy5jeg==\n")
|
15
|
+
s.has_rdoc = true
|
16
|
+
|
17
|
+
# files
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# runtime dependencies
|
22
|
+
s.add_dependency "actionpack" # and probably actionmailer, but hey, it's up to you mate
|
23
|
+
|
24
|
+
begin
|
25
|
+
require "changelog"
|
26
|
+
rescue LoadError
|
27
|
+
warn "You have to have changelog gem installed for post install message"
|
28
|
+
else
|
29
|
+
s.post_install_message = CHANGELOG.new.version_changes
|
30
|
+
end
|
31
|
+
|
32
|
+
# RubyForge
|
33
|
+
s.rubyforge_project = "rails-named-routes-options"
|
34
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env gem build
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# You might think this is a terrible mess and guess what, you're
|
5
|
+
# right mate! However say thanks to authors of RubyGems, not me.
|
6
|
+
eval(File.read("rails-named-routes-options.gemspec")).tap do |specification|
|
7
|
+
specification.version = "#{specification.version}.pre"
|
8
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative "spec_helper"
|
4
|
+
|
5
|
+
describe Rails-named-routes-options do
|
6
|
+
it "should have VERSION constant" do
|
7
|
+
Rails-named-routes-options::VERSION.should be_kind_of(String)
|
8
|
+
Rails-named-routes-options::VERSION.should match(/^\d+\.\d+\.\d+$/)
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# constants
|
4
|
+
SPEC_ROOT = File.dirname(__FILE__)
|
5
|
+
ROOT = File.expand_path(File.join(SPEC_ROOT, ".."))
|
6
|
+
LIBDIR = File.join(ROOT, "lib")
|
7
|
+
|
8
|
+
# load paths
|
9
|
+
$:.unshift(LIBDIR)
|
10
|
+
|
11
|
+
require "spec" # so you can run ruby spec/rails-named-routes-options/whatever_spec.rb
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-named-routes-options
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jakub Stastny aka Botanicus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
date: 2010-01-15 00:00:00 +00:00
|
12
|
+
default_executable:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: actionpack
|
16
|
+
type: :runtime
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
description: This Rails plugin adds default_named_routes_options to your controllers and mailers, so you can specify default options for named routes like ActionMailer::Base.default_named_routes_options[:only_path] = false
|
25
|
+
email: stastny@101ideas.cz
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- CHANGELOG
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.textile
|
38
|
+
- lib/rails-named-routes-options.rb
|
39
|
+
- rails-named-routes-options.gemspec
|
40
|
+
- rails-named-routes-options.pre.gemspec
|
41
|
+
- spec/rails-named-routes-options_spec.rb
|
42
|
+
- spec/spec.opts
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/botanicus/rails-named-routes-options
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message: "[\e[32mVersion 0.0.1\e[0m] NamedRoutesOptions mixin\n\
|
49
|
+
[\e[32mVersion 0.0.1\e[0m] The mixin is automatically included to the ActionMailer::Base\n\
|
50
|
+
[\e[32mVersion 0.0.1\e[0m] The mixin is automatically included to the ActionController::Base\n\
|
51
|
+
[\e[32mVersion 0.0.1\e[0m] Added basic README\n"
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: rails-named-routes-options
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: This Rails plugin adds default_named_routes_options to your controllers and mailers
|
75
|
+
test_files: []
|
76
|
+
|