<?xml version="1.0" encoding="UTF-8"?>
<codes type="array">
  <code>
    <code>  module Rack
    class Request
      def subdomains
        @env['rack.env.subdomains'] ||= lambda {
          return [] if (host.nil? ||
          /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
          host.split('.')[0...-2]
          }.call
        end
      end
    end

    before do
      @purl_base = if request.subdomains.empty? then request.host else request.host.sub("#{request.subdomains.join('.')}.", "") end #personalurl.com
      @purl = Purl.first(:purl =&gt; @purl_base)
      Purl.current = @purl
      @user = CData.first(:unique_name =&gt; request.subdomains.join('.')) unless request.subdomains.empty? #g.manley
    end

    get '/' do
      if
        request.subdomains.empty?
        then
        erb :"#{@purl.name}/blank"
      else
        erb :"#{@purl.name}/index"
      end
    end</code>
    <comment>So i need to define @purl_base and @user. @user needs to be defined only if the url navigated to has a subdomain (g.manley.personalurl.com). @purl_base is currently being defined by sub'ing out the subdomain but if there is no subdomain then obviously it doesn't need to be subbed out. I currently have a semi working version of it but its pretty clunky and wanted to see if there was a better way like maybe even a rack function that i missed that defines the base url.

Its a sinatra app using datamapper.</comment>
    <created-at type="datetime">2010-01-11T22:25:10+00:00</created-at>
    <id type="integer">1140</id>
    <language>Ruby</language>
    <permalink>personalized-url-purl-subdomain-sub</permalink>
    <refactors-count type="integer">0</refactors-count>
    <title>Personalized URL (Purl) Subdomain Sub</title>
    <trackback-url></trackback-url>
    <updated-at type="datetime">2010-01-11T22:27:03+00:00</updated-at>
    <user-id type="integer">1876</user-id>
    <user>
      <id type="integer">1876</id>
      <identity-url>http://openid.aol.com/grayfm</identity-url>
      <name>grayfm</name>
      <rating type="float">0.0</rating>
      <refactors-count type="integer">0</refactors-count>
      <website></website>
    </user>
  </code>
  <code>
    <code># This is what an application build with our framework would look like.
# Run with:
#   rackup app.ru

app = App.new do
  
  get "" do
    render "hi" # Specifies the body of the response
  end
  
  get "echo/(.*)" do |text| # Regexp matches are passed as block args
    render text
  end
  
  get "session/set" do
    session[params.first.key] = params.first.value
  end
  get "session" do
    render session.inspect
  end
  
  get "form" do
    render erb(:form) # Can have helper methods to render erb and the like
  end
  
  post "form" do
    render params.inspect
  end
  
end

run app</code>
    <comment>I'll be presenting http://rack.rubyforge.org this Tuesday at the first Montreal Against Rails (http://www.montrealonrails.com/2008/09/11/montreal_against_rails-tuesday).

I'll show how to use Rack and then I'd like to try something new (and probably crazy-stupid). Building a web framework with Rack is so easy, I'll be doing pair programming with anyone from the audience to create our own custom framework live during the presentation (in 30 min). We'll start with the code posted here on RefactorMyCode as the application code, we'll implement the framework code during the presentation. So submit your ideas here before the event.

And make sure to RSVP (http://upcoming.yahoo.com/event/1093407) if your in Montreal next Tuesday!


</comment>
    <created-at type="datetime">2008-09-14T18:11:09+00:00</created-at>
    <id type="integer">491</id>
    <language>Ruby</language>
    <permalink>very-simple-rack-framework</permalink>
    <refactors-count type="integer">1</refactors-count>
    <title>Very Simple Rack framework</title>
    <trackback-url>http://macournoyer.wordpress.com/2008/09/14/presenting-at-montreal-against-rails/trackback</trackback-url>
    <updated-at type="datetime">2008-09-14T18:48:08+00:00</updated-at>
    <user-id type="integer">1</user-id>
    <user>
      <id type="integer">1</id>
      <identity-url>http://macournoyer.myopenid.com/</identity-url>
      <name>macournoyer</name>
      <rating type="float">3.6667</rating>
      <refactors-count type="integer">72</refactors-count>
      <website>http://macournoyer.com</website>
    </user>
  </code>
</codes>
