Permalink
Browse files

merge leehambley/master

  • Loading branch information...
2 parents 00d1ef9 + a7aafed commit dd06bced120cc0f251952f9a27bca8582b0808b7 @pboling pboling committed Jun 17, 2011
Showing with 214 additions and 224 deletions.
  1. +42 −42 README.rdoc
  2. +39 −11 Rakefile
  3. +4 −3 VERSION.yml
  4. +22 −0 config/database.yml
  5. +0 −6 init.rb
  6. +0 −2 install.sh
  7. +61 −39 lib/subdomain-fu.rb
  8. +7 −0 lib/subdomain_fu/rails.rb
  9. +0 −61 lib/subdomain_fu/routing_extensions.rb
  10. +13 −42 lib/subdomain_fu/url_rewriter.rb
  11. +14 −7 spec/spec_helper.rb
  12. +12 −11 subdomain-fu.gemspec
View
@@ -5,17 +5,20 @@ It takes aspects from account_location, request_routing, and other snippets
found around the web and combines them to provide a single, simple solution
for subdomain-based route and url management.
+**Note**: SubdomainFu has been rewritten to be compatible with Rails 3. If
+you are looking to use it on Rails 2.x, please install version v0.5.x instead.
+
== Installation
SubdomainFu is available both as a traditional plugin and a GemPlugin. To
-install it as a traditional plugin (Rails 2.1 or later):
+install it as a traditional plugin:
- script/plugin install git://github.com/mbleigh/subdomain-fu.git
+ script/plugin install git://github.com/intridea/subdomain-fu.git
-To use it as a GemPlugin, add it to your environment.rb:
-
- config.gem 'mbleigh-subdomain-fu', :source => "http://gems.github.com", :lib => "subdomain-fu"
+To use it as a gem, add it to your Gemfile. Until Rails 3 is officially released,
+the Rails 3 version of the plugin is only available as a prerelease gem:
+ gem 'subdomain-fu', '1.0.0.beta2'
== Examples
@@ -26,14 +29,14 @@ option both in named and non-named routes as well as in generated resources rout
Let's say my domain is 'intridea.com'. Here are some examples of the use of the :subdomain
option:
-url_for(:controller => "my_controller",
- :action => "my_action",
- :subdomain => "awesome") # => http://awesome.intridea.com/my_controller/my_action
+ url_for(:controller => "my_controller",
+ :action => "my_action",
+ :subdomain => "awesome") # => http://awesome.intridea.com/my_controller/my_action
Now let's say I'm at http://awesome.intridea.com/ and I want back to the root.
Specifying "false" will remove any current subdomain:
-users_url(:subdomain => false) # => http://intridea.com/users
+ users_url(:subdomain => false) # => http://intridea.com/users
You should exercise caution using the :only_path option when you want to change
subdomains. If you want the plugin to ensure that you switch subdomains when
@@ -42,9 +45,9 @@ application configuration. This will disregard :only_path in routing helpers.
With this option, if I were at http://intridea.com
again:
-users_path(:subdomain => "fun") # => http://fun.intridea.com/users
-users_path(:subdomain => false) # => /users
-
+ users_path(:subdomain => "fun") # => http://fun.intridea.com/users
+ users_path(:subdomain => false) # => /users
+
In this way you can rest assured that you will never misdirect your links to the
same subdomain when you meant to change it.
@@ -56,66 +59,63 @@ and so may constitute a change for you when upgrading to the latest and greatest
You have access to current_subdomain and current_domain methods.
-current_subdomain - returns all subdomains.
- http://awesome.website.stuff.example.com => "awesome.website.stuff"
+[current_subdomain] returns all subdomains. For the URL http://awesome.website.stuff.example.com, it will return "awesome.website.stuff"
-current_domain - returns all domains, except for the first subdomain and the TLD.
- Example for the URL http://awesome.website.stuff.example.com current_subdomain will return "website.stuff.example.com"
+[current_domain] returns the domain excluding for the subdomain, including the TLD. For the URL http://awesome.website.stuff.example.com, it will return "website.stuff.example.com"
If what you really want is the entire domain, then use <tt>request.domain</tt> in
your controllers. The purpose of current_domain is to only strip off the first
subdomain, if any, and return what's left.
== Configuration
-You may need to configure SubdomainFu based on your development setup. The
-configuration required is:
+You may need to configure SubdomainFu based on your development setup. To configure
+SubdomainFu simply call a block in an initializer like so:
-=== TLD Size
+ SubdomainFu.configure do |config|
+ config.option_name = value
+ end
+
+Some available options are enumerated below.
+
+=== tld_size
A hash for each environment of the size of the top-level domain name.
(something.com = 1, localhost = 0, etc.)
-SubdomainFu.tld_size = 1 # sets for current environment
-SubdomainFu.tld_sizes = {:development => 0,
- :test => 0,
- :production => 1} # set all at once (also the defaults)
+ config.tld_size = 1 # sets for current environment
+ config.tld_sizes = {:development => 0,
+ :test => 0,
+ :production => 1} # set all at once (also the defaults)
-=== Mirrors
+=== mirrors
Mirrors are the subdomains that are equivalent to no subdomain (i.e. they 'mirror')
the usage of the root domain.
-SubdomainFu.mirrors = %w(www site we) # Defaults to %w(www)
+ config.mirrors = %w(www site we) # Defaults to %w(www)
-=== Preferred Mirror
+=== preferred_mirror
SubdomainFu also understands the notion of a 'preferred mirror', that is, if you
always want your links going to 'www.yourdomain.com' instead of 'yourdomain.com',
you can set the preferred mirror like so:
-SubdomainFu.preferred_mirror = "www"
+ config.preferred_mirror = "www"
-Now when you create a link with subdomain => false in the options the subdomain
+Now when you create a link with <tt>:subdomain => false</tt> in the options the subdomain
will default to the preferred mirror.
-== Routing
+== Routing (Deprecated)
-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:
-
- map.with_options :conditions => {:subdomain => 'admin'} do |admin|
- admin.resources :posts
- admin.resources :users
- end
-
-In addition to specifying a string, you could also specify <tt>false</tt> to
-require no subdomain (this includes mirrors that you've set up such as www)
-or a regular expression to match a range of subdomains.
+Subdomain constraint routing has been removed from the scope of this plugin as Rails 3
+provides the functionality by default. For more info, see this blog post:
+http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/
== Resources
-* GitHub Repository: http://github.com/mbleigh/subdomain-fu
-* RDocs: http://rdoc.info/projects/mbleigh/subdomain-fu
+* GitHub Repository: http://github.com/intridea/subdomain-fu
+* RDocs: http://rdoc.info/projects/intridea/subdomain-fu
-Copyright (c) 2008 Michael Bleigh (http://www.mbleigh.com/) and
+Copyright (c) 2008-2010 Michael Bleigh (http://www.mbleigh.com/) and
Intridea, Inc. (http://www.intridea.com/). Released under the MIT license
View
@@ -1,14 +1,14 @@
require 'rake'
-require 'spec/rake/spectask'
-
-desc 'Default: run specs.'
-task :default => :spec
-
-desc 'Run the specs'
-Spec::Rake::SpecTask.new(:spec) do |t|
- t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
- t.spec_files = FileList['spec/**/*_spec.rb']
-end
+# require 'spec/rake/spectask'
+#
+# desc 'Default: run specs.'
+# task :default => :spec
+#
+# desc 'Run the specs'
+# Spec::Rake::SpecTask.new(:spec) do |t|
+# t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
+# t.spec_files = FileList['spec/**/*_spec.rb']
+# end
begin
require 'jeweler'
@@ -18,11 +18,39 @@ begin
gemspec.summary = "SubdomainFu is a Rails plugin that provides subdomain routing and URL writing helpers."
gemspec.email = "michael@intridea.com"
gemspec.homepage = "http://github.com/mbleigh/subdomain-fu"
- gemspec.files = FileList["[A-Z]*", "{lib,spec,rails}/**/*"] - FileList["**/*.log"]
+ gemspec.files = FileList["[A-Z]*", "{lib}/**/*"] - FileList["**/*.log"]
gemspec.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)."
gemspec.authors = ["Michael Bleigh"]
end
+ Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
+
+# These are new tasks
+# begin
+# require 'rake/contrib/sshpublisher'
+# namespace :rubyforge do
+#
+# desc "Release gem and RDoc documentation to RubyForge"
+# task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
+#
+# namespace :release do
+# desc "Publish RDoc to RubyForge."
+# task :docs => [:rdoc] do
+# config = YAML.load(
+# File.read(File.expand_path('~/.rubyforge/user-config.yml'))
+# )
+#
+# host = "#{config['username']}@rubyforge.org"
+# remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
+# local_dir = 'rdoc'
+#
+# Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
+# end
+# end
+# end
+# rescue LoadError
+# puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
+# end
View
@@ -1,4 +1,5 @@
---
-:minor: 6
-:patch: 1
-:major: 0
+:major: 1
+:build: beta2
+:minor: 0
+:patch: 0
View
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
View
@@ -1,6 +0,0 @@
-#Allow whatever Ruby Package tool is being used ot manage load paths. gem auto adds the gem's lib dir to load path.
-require 'subdomain-fu' unless defined?(SubdomainFu)
-
-ActionController::Base.send :include, SubdomainFu::Controller
-
-RAILS_DEFAULT_LOGGER.info("** SubdomainFu: initialized properly")
View
@@ -1,2 +0,0 @@
-# I use this to make life easier when installing and testing from source:
-rm -rf subdomain-fu-*.gem && gem build subdomain-fu.gemspec && sudo gem uninstall subdomain-fu && sudo gem install subdomain-fu-0.6.1.gem --no-ri --no-rdoc
Oops, something went wrong.

0 comments on commit dd06bce

Please sign in to comment.