tannerburson / multi-sinatra-sample

Sample application showing how to use multiple sinatra subclass applications in a single process.

This URL has Read+Write access

multi-sinatra-sample / sample.rb
100644 34 lines (29 sloc) 0.844 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Require sinatra/base instead of sinatra to avoid some of the magic
# This keeps us from polluting the top level namespace with sinatra's
# magic methods.
require 'sinatra/base'
 
module Sample
  class SampleBase < Sinatra::Base
    # setup some options we want shared between all 'controllers'
    set :static, true
    set :public, File.join(File.dirname(__FILE__),'public')
    enable :sessions
  end
 
  class Main < SampleBase
    set :views, File.join(File.dirname(__FILE__),'views','main')
    # Pretty normal application here
    get '/' do
      erb :index
    end
  end
 
  class Blog < SampleBase
    set :views, File.join(File.dirname(__FILE__),'views','blog')
    # We define it this way to not require a hard / at the end of the url
    get '/?' do
      erb :blog
    end
 
    get '/list' do
      erb :blog_list
    end
  end
end