Integrating a Sinatra and toto application is a little tricky for those unfamiliar with hosting multiple Rack applications in a single Rack instance. To integrate these two for AutoMapper.org, I followed similar instructions from the toto wiki:
- cd your_sinatra_app
- mkdir blog
- cd blog
- git clone git://github.com/cloudhead/dorothy.git .
- merge the contents of the dorothy .gems file with the .gems file in the root of your Sinatra application
- remove the files needed for a standalone toto install
- rm README
- rm Rakefile (you may want to move the toto rakefile to the root directory to take advantage of the “new” task for creating new posts.)
- rm config.ru
- rm .gems
- rm -rf public
- rm -rf .git
- cd .. (back to the root of your Sinatra app)
- create a Rack config file, config.ru, in your Sinatra root, if it doesn’t already exist
- Open config.ru in your favorite text editor and add the following:
require 'toto' require './app' use Rack::ShowExceptions use Rack::CommonLogger #run the toto application toto = Toto::Server.new do #override the default location for the toto directories Toto::Paths = { :templates => "blog/templates", :pages => "blog/templates/pages", :articles => "blog/articles" } #set your config variables here set :title, "Your Blog Title" set :date, lambda {|now| now.strftime("%B #{now.day.ordinal} %Y") } set :summary, :max => 500 set :root, "blog" set :url, "http://your-blog.heroku.com/blog/" end #create a rack app app = Rack::Builder.new do use Rack::CommonLogger #map requests to /blog to toto map '/blog' do run toto end #map all the other requests to sinatra map '/' do run SinatraApp end end.to_app run app - Open your Sinatra app and wrap any Sinatra code with a class “SinatraApp” that inherits from Sinatra::Base:
require 'rubygems' require 'sinatra' class SinatraApp < Sinatra::Base get '/' do "I love lamp" end end
Now test your code with thin or any other rack-enabled test web server and push! A full working application can be found at my github.
Post Footer automatically generated by Add Post Footer Plugin for wordpress.
