pboling-subdomain-fu 0.3.0 → 0.5.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/README.rdoc CHANGED
@@ -10,11 +10,11 @@ for subdomain-based route and url management.
10
10
  SubdomainFu is available both as a traditional plugin and a GemPlugin. To
11
11
  install it as a traditional plugin (Rails 2.1 or later):
12
12
 
13
- script/plugin install git://github.com/pboling/subdomain-fu.git
13
+ script/plugin install git://github.com/mbleigh/subdomain-fu.git
14
14
 
15
15
  To use it as a GemPlugin, add it to your environment.rb:
16
16
 
17
- config.gem 'pboling-subdomain-fu', :source => "http://gems.github.com", :lib => "subdomain-fu"
17
+ config.gem 'mbleigh-subdomain-fu', :source => "http://gems.github.com", :lib => "subdomain-fu"
18
18
 
19
19
 
20
20
  == Examples
@@ -45,13 +45,30 @@ 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 first subdomain and the domain with TLD.
56
+ Example for the URL http://awesome.website.stuff.example.com current_subdomain will return "website.stuff.example.com"
57
+
58
+ This might appear strange at first, but the original plugin in this space was account_location,
59
+ which had this behavior for current domain. Subdomain-fu did not use the same style as account_location
60
+ with current_subdomain, thus the overlap. However Subdomain-fu has created a lot of utility in its implementation of
61
+ current_subdomain, so the overlap stays!
62
+
63
+ If what you really want is just the domain, then use request.domain. The purpose of current_domain is to only strip
64
+ off the first subdomain, if any, and return what's left.
65
+
48
66
  == Configuration
49
67
 
50
68
  You may need to configure SubdomainFu based on your development setup. The
51
69
  configuration required is:
52
70
 
53
- tld_size
54
- --------
71
+ === TLD Size
55
72
 
56
73
  A hash for each environment of the size of the top-level domain name.
57
74
  (something.com = 1, localhost = 0, etc.)
@@ -61,16 +78,14 @@ SubdomainFu.tld_sizes = {:development => 0,
61
78
  :test => 0,
62
79
  :production => 1} # set all at once (also the defaults)
63
80
 
64
- mirrors
65
- -------
81
+ === Mirrors
66
82
 
67
83
  Mirrors are the subdomains that are equivalent to no subdomain (i.e. they 'mirror')
68
84
  the usage of the root domain.
69
85
 
70
86
  SubdomainFu.mirrors = %w(www site we) # Defaults to %w(www)
71
87
 
72
- preferred_mirror
73
- ----------------
88
+ === Preferred Mirror
74
89
 
75
90
  SubdomainFu also understands the notion of a 'preferred mirror', that is, if you
76
91
  always want your links going to 'www.yourdomain.com' instead of 'yourdomain.com',
@@ -81,17 +96,19 @@ SubdomainFu.preferred_mirror = "www"
81
96
  Now when you create a link with subdomain => false in the options the subdomain
82
97
  will default to the preferred mirror.
83
98
 
84
- == Known Issues / Future Work
99
+ == Routing
100
+
101
+ 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:
85
102
 
86
- SubdomainFu will eventually integrate with Rails' routing internals to provide
87
- the ability to specify routes based on the condition of a specific subdomain or
88
- simply whether a subdomain is present (or a mirror).
103
+ map.with_options :conditions => {:subdomain => 'admin} do |admin|
104
+ admin.resources :posts
105
+ admin.resources :users
106
+ end
89
107
 
90
108
  == Resources
91
109
 
92
- * Acts As Community Project: http://actsascommunity.com/projects/subdomain-fu
93
110
  * GitHub Repository: http://github.com/mbleigh/subdomain-fu
94
- * Lighthouse: http://mbleigh.lighthouseapp.com/projects/13148-subdomain-fu
111
+ * RDocs: http://rdoc.info/projects/mbleigh/subdomain-fu
95
112
 
96
113
  Copyright (c) 2008 Michael Bleigh (http://www.mbleigh.com/) and
97
114
  Intridea, Inc. (http://www.intridea.com/). Released under the MIT license
data/Rakefile CHANGED
@@ -14,6 +14,7 @@ begin
14
14
  require 'jeweler'
15
15
  Jeweler::Tasks.new do |gemspec|
16
16
  gemspec.name = "subdomain-fu"
17
+ gemspec.rubyforge_project = 'subdomain-fu'
17
18
  gemspec.summary = "SubdomainFu is a Rails plugin that provides subdomain routing and URL writing helpers."
18
19
  gemspec.email = "michael@intridea.com"
19
20
  gemspec.homepage = "http://github.com/mbleigh/subdomain-fu"
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
- ---
2
- :major: 0
3
- :minor: 3
1
+ ---
2
+ :minor: 5
4
3
  :patch: 0
4
+ :major: 0
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
@@ -19,7 +19,7 @@ module ActionController
19
19
  if SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port)) || options[:only_path] == false
20
20
  options[:only_path] = false if SubdomainFu.override_only_path?
21
21
  options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || @request.host_with_port)
22
- puts "options[:host]: #{options[:host].inspect}"
22
+ # puts "options[:host]: #{options[:host].inspect}"
23
23
  else
24
24
  options.delete(:subdomain)
25
25
  end
@@ -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,27 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pboling-subdomain-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
- - Peter Boling
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2009-08-24 00:00:00 -07:00
12
+ date: 2009-08-31 00:00:00 -07:00
14
13
  default_executable:
15
14
  dependencies: []
16
15
 
17
16
  description: SubdomainFu is a Rails plugin to provide all of the basic functionality necessary to handle multiple subdomain applications (such as Basecamp-esque subdomain accounts and more).
18
- email: michael@intridea.com peter.boling@gmail.com
17
+ email: michael@intridea.com
19
18
  executables: []
20
19
 
21
20
  extensions: []
22
21
 
23
- extra_rdoc_files: []
24
-
22
+ extra_rdoc_files:
23
+ - README.rdoc
25
24
  files:
26
25
  - CHANGELOG
27
26
  - MIT-LICENSE
@@ -36,7 +35,7 @@ files:
36
35
  - spec/spec_helper.rb
37
36
  - spec/subdomain_fu_spec.rb
38
37
  - spec/url_rewriter_spec.rb
39
- has_rdoc: true
38
+ has_rdoc: false
40
39
  homepage: http://github.com/mbleigh/subdomain-fu
41
40
  post_install_message:
42
41
  rdoc_options:
@@ -57,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
56
  version:
58
57
  requirements: []
59
58
 
60
- rubyforge_project:
59
+ rubyforge_project: subdomain-fu
61
60
  rubygems_version: 1.2.0
62
61
  signing_key:
63
62
  specification_version: 3