Created
October 12, 2009 00:04
-
-
Save nathany/207983 to your computer and use it in GitHub Desktop.
Heroku is great to host single-page "sites" for all those domains I'm not using.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
require 'haml' | |
Domains = %w{gemsmith vogsphere youngman seraph intercessory cyaonline significantwhitespace 14159265358979} | |
DefaultDomain = 'default' | |
# what domain does the host contain? | |
# put this here because helpers are a pain to test! | |
def view_for_domain(host) | |
return DefaultDomain if host.nil? | |
Domains.find do |domain| | |
host.include?(domain) | |
end || DefaultDomain | |
end | |
def view_exists?(view) | |
File.exists?(Dir.pwd + "/views/#{view}.haml") | |
end | |
# the catch-all route | |
get '/*' do | |
# parse domain | |
@view = view_for_domain(request.env["HTTP_HOST"]) | |
# override with text anywhere in url (for testing) | |
splat = params['splat'].first | |
if(@view == DefaultDomain && !splat.empty?) then | |
@view = view_for_domain(splat) | |
end | |
# ensure view exists, and load | |
@view = DefaultDomain unless view_exists?(@view) | |
haml @view.to_sym | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment