Created
July 10, 2009 09:00
-
-
Save TheNicholasNick/144360 to your computer and use it in GitHub Desktop.
load multiple sinatra apps
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
**After the fact** | |
namelessjon pointed me in the right direction. | |
map /asdasdasd do | |
run app | |
end | |
request.env['SCRIPT_NAME'] = "/asdasdasd" | |
also this is all in gem form: http://github.com/emk/sinatra-url-for/tree/master | |
I needed a way to have my apps be under scm and all config stuff be somewhere else. | |
Then I can do this: | |
* Checkout apps into own directories | |
* Configure config.ru | |
* thin start -R config.ru | |
Considerations: | |
* I'll always run the stack via a config.ru (either standalone app or bunch of standalone apps in a stack) | |
* I want to have a stack as a combo git submodules therefore apps need to be standalone and play nice together | |
* This an idea I came up with quickly - I have limited ruby knowledge, I'm maxing out my ruby fu here ;) | |
* I also use the merb (thor) bundler - for quickness none of that is shown... | |
* As long as the app has a unique name it won't clash with other apps. obviously "blog" would if there were two apps called "blog". My apps aren't named with generic adjectives, I use proper nouns. | |
Directory Structure | |
|_app_dir/ | |
|_lib/ | |
|_ blog/ | |
|_blog/ | |
|_views/ | |
|_posts/ | |
|_index.haml | |
|_new.haml | |
|_static/ | |
|_logo.png | |
|_blog.rb | |
|_config.ru | |
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
# run with thin start -R config.ru | |
require "haml" | |
require "sinatra/base" | |
## | |
$:.unshift "#{pwd}/lib/blog" # <-pretty sure i've read something that discourages this - however I haven't found the "proper" way to do it. Suffice to say this "works".... | |
require "blog" | |
map "/blog" do | |
run Blog::Main | |
end |
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
module Blog | |
class Main < Sinatra::Base | |
set :app_file, __FILE__ | |
set :static, true | |
set :public, Proc.new { File.join(root, "blog", "static") } | |
set :views, Proc.new { File.join(root, "blog", "views") } | |
helpers do | |
# http://github.com/namelessjon has shown me the light ;) | |
def link_to(uri = "/") | |
"#{request.env['SCRIPT_NAME']}#{uri}" | |
end | |
end | |
get "/posts" do | |
haml :"posts/index" | |
end | |
get "/posts/new" do | |
haml :"posts/new" | |
end | |
end | |
end |
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
%img{ :src => link_to("/logo.png"), :alt => "logo"} | |
%h1 Posts - Index | |
%a{ :href => link_to("/posts/new"), :title => "Create a New Post" } New |
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
%img{ :src => link_to("/logo.png"), :alt => "logo"} | |
%h1 Post - New | |
%a{ :href => link_to("/posts"), :title => "Cancel and go back to index" } Cancel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment