subdomain-fu 0.4.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +7 -0
- data/README.rdoc +19 -1
- data/Rakefile +27 -0
- data/VERSION.yml +2 -2
- data/lib/subdomain-fu.rb +11 -0
- data/rails/init.rb +1 -3
- data/spec/subdomain_fu_spec.rb +27 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -45,6 +45,20 @@ users_path(:subdomain => false) # => /users
|
|
45
45
|
In this way you can rest assured that you will never misdirect your links to the
|
46
46
|
same subdomain when you meant to change it.
|
47
47
|
|
48
|
+
== Use in controllers and views
|
49
|
+
|
50
|
+
You have access to current_subdomain and current_domain methods.
|
51
|
+
|
52
|
+
current_subdomain - returns all subdomains.
|
53
|
+
Example for the URL http://awesome.website.stuff.example.com current_subdomain will return "awesome.website.stuff"
|
54
|
+
|
55
|
+
current_domain - returns all subdomains except for the subdomain, including the TLD.
|
56
|
+
Example for the URL http://awesome.website.stuff.example.com current_subdomain will return "website.stuff.example.com"
|
57
|
+
|
58
|
+
If what you really want is the entire domain, then use <tt>request.domain</tt> in
|
59
|
+
your controllers. The purpose of current_domain is to only strip off the first
|
60
|
+
subdomain, if any, and return what's left.
|
61
|
+
|
48
62
|
== Configuration
|
49
63
|
|
50
64
|
You may need to configure SubdomainFu based on your development setup. The
|
@@ -82,10 +96,14 @@ will default to the preferred mirror.
|
|
82
96
|
|
83
97
|
SubdomainFu can also work within Rails' routing for subdomain-specific routes. For instance, if you only wanted your administrative tools available in the "admin" subdomain you could add this to your routes.rb file:
|
84
98
|
|
85
|
-
map.with_options :conditions => {:subdomain => 'admin} do |admin|
|
99
|
+
map.with_options :conditions => {:subdomain => 'admin'} do |admin|
|
86
100
|
admin.resources :posts
|
87
101
|
admin.resources :users
|
88
102
|
end
|
103
|
+
|
104
|
+
In addition to specifying a string, you could also specify <tt>false</tt> to
|
105
|
+
require no subdomain (this includes mirrors that you've set up such as www)
|
106
|
+
or a regular expression to match a range of subdomains.
|
89
107
|
|
90
108
|
== Resources
|
91
109
|
|
data/Rakefile
CHANGED
@@ -26,3 +26,30 @@ rescue LoadError
|
|
26
26
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
27
27
|
end
|
28
28
|
|
29
|
+
|
30
|
+
# These are new tasks
|
31
|
+
begin
|
32
|
+
require 'rake/contrib/sshpublisher'
|
33
|
+
namespace :rubyforge do
|
34
|
+
|
35
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
36
|
+
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
37
|
+
|
38
|
+
namespace :release do
|
39
|
+
desc "Publish RDoc to RubyForge."
|
40
|
+
task :docs => [:rdoc] do
|
41
|
+
config = YAML.load(
|
42
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
43
|
+
)
|
44
|
+
|
45
|
+
host = "#{config['username']}@rubyforge.org"
|
46
|
+
remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
|
47
|
+
local_dir = 'rdoc'
|
48
|
+
|
49
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
rescue LoadError
|
54
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
55
|
+
end
|
data/VERSION.yml
CHANGED
data/lib/subdomain-fu.rb
CHANGED
@@ -137,14 +137,25 @@ module SubdomainFu
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
#Enables subdomain-fu to more completely replace DHH's account_location plugin
|
141
|
+
def self.current_domain(request)
|
142
|
+
domain = ""
|
143
|
+
domain << request.subdomains[1..-1].join(".") + "." if request.subdomains.length > 1
|
144
|
+
domain << request.domain + request.port_string
|
145
|
+
end
|
146
|
+
|
140
147
|
module Controller
|
141
148
|
def self.included(controller)
|
142
149
|
controller.helper_method(:current_subdomain)
|
150
|
+
controller.helper_method(:current_domain)
|
143
151
|
end
|
144
152
|
|
145
153
|
protected
|
146
154
|
def current_subdomain
|
147
155
|
SubdomainFu.current_subdomain(request)
|
148
156
|
end
|
157
|
+
def current_domain
|
158
|
+
SubdomainFu.current_domain(request)
|
159
|
+
end
|
149
160
|
end
|
150
161
|
end
|
data/rails/init.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
$:.unshift "#{File.dirname(__FILE__)}/../lib"
|
3
|
-
|
1
|
+
#Allow whatever Ruby Package tool is being used ot manage load paths. gem auto adds the gem's lib dir to load path.
|
4
2
|
require 'subdomain-fu' unless defined?(SubdomainFu)
|
5
3
|
|
6
4
|
ActionController::Base.send :include, SubdomainFu::Controller
|
data/spec/subdomain_fu_spec.rb
CHANGED
@@ -159,6 +159,33 @@ describe "SubdomainFu" do
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
+
describe "#current_domain" do
|
163
|
+
it "should return the current domain if there is one" do
|
164
|
+
request = mock("request", :subdomains => [], :domain => "example.com", :port_string => "")
|
165
|
+
SubdomainFu.current_domain(request).should == "example.com"
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should return empty string if there is no domain" do
|
169
|
+
request = mock("request", :subdomains => [], :domain => "", :port_string => "")
|
170
|
+
SubdomainFu.current_domain(request).should == ""
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should return the current domain if there is only one level of subdomains" do
|
174
|
+
request = mock("request", :subdomains => ["www"], :domain => "example.com", :port_string => "")
|
175
|
+
SubdomainFu.current_domain(request).should == "example.com"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should return everything but the first level of subdomain when there are multiple levels of subdomains" do
|
179
|
+
request = mock("request", :subdomains => ["awesome","rad","cheese","chevy","ford"], :domain => "example.com", :port_string => "")
|
180
|
+
SubdomainFu.current_domain(request).should == "rad.cheese.chevy.ford.example.com"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should return the domain with port if port is given" do
|
184
|
+
request = mock("request", :subdomains => ["awesome","rad","cheese","chevy","ford"], :domain => "example.com", :port_string => ":3000")
|
185
|
+
SubdomainFu.current_domain(request).should == "rad.cheese.chevy.ford.example.com:3000"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
162
189
|
describe "#same_subdomain?" do
|
163
190
|
it { SubdomainFu.same_subdomain?("www","www.localhost").should be_true }
|
164
191
|
it { SubdomainFu.same_subdomain?("www","localhost").should be_true }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subdomain-fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-13 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|