Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added subdomain and redirect_to_subdomain methods to ActionDispatch::…

…Routing::Mapper
  • Loading branch information...
commit df5bf8e8f95a5449061d847b806bab96f3f17982 0 parents
Jared Grippe authored deadlyicon committed
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in subrails.gemspec
+gemspec
26 README.markdown
@@ -0,0 +1,26 @@
+# Subrails
+
+ Adding better subdomain support to raisl
+
+
+# Routing
+
+## Methods:
+
+### subdomain
+
+ # An alias for constraints :subdomain => 'www' do…
+ subdomain :www do
+ …
+ end
+
+ # An alias for constraints :subdomain => /things|stuff|radsauce/ do…
+ subdomain :things, :stuff, :radsauce do
+ …
+ end
+
+
+### redirect\_to_subdomain
+
+
+ match 'posts(/:id)' => redirect_to_subdomain(:www, 'blog/posts/%{id}')
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
6 lib/subrails.rb
@@ -0,0 +1,6 @@
+require "subrails/version"
+
+module Subrails
+end
+
+require 'subrails/action_dispatch/routing/mapper/subdomains'
26 lib/subrails/action_dispatch/routing/mapper/subdomains.rb
@@ -0,0 +1,26 @@
+require 'action_dispatch/routing/mapper'
+
+module ActionDispatch::Routing::Mapper::Subdomains
+
+ def subdomain *subdomains, &block
+ subdomain = subdomains.length == 1 ? subdomains.first.to_s : /#{subdomains.join('|')}/
+ constraints(:subdomain => subdomain, &block)
+ end
+
+ def redirect_to_subdomain subdomain, path='/', &block
+ redirect{ |params, req|
+ path = block.call(params, req) if block
+ path = path % params
+ uri = URI.parse(path)
+ uri.scheme = req.scheme
+ uri.host = req.host
+ uri.subdomain = subdomain
+ uri.port = req.port unless req.standard_port?
+ uri.to_s
+ }
+ end
+
+ ActionDispatch::Routing::Mapper.send :include, self
+
+end
+
3  lib/subrails/version.rb
@@ -0,0 +1,3 @@
+module Subrails
+ VERSION = "0.0.1"
+end
25 subrails.gemspec
@@ -0,0 +1,25 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "subrails/version"
+
+Gem::Specification.new do |s|
+ s.name = "subrails"
+ s.version = Subrails::VERSION
+ s.authors = ["Jared Grippe"]
+ s.email = ["jared@change.org"]
+ s.homepage = "http://github.com/change/subrails"
+ s.summary = %q{Adding better subdomain support to rails}
+ s.description = %q{Adding better subdomain support to rails}
+
+ s.rubyforge_project = "subrails"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ s.add_development_dependency "rake"
+ s.add_runtime_dependency "rails", "~> 3.0.0"
+ s.add_runtime_dependency "uri-subdomain"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.