Permalink
Browse files

init

  • Loading branch information...
0 parents commit 5d5467a30470564d5fa50148beb40aa6f03abbea @zzak zzak committed Feb 25, 2011
@@ -0,0 +1,4 @@
+Gemfile.lock
+.sass-cache
+.rvmrc
+
@@ -0,0 +1,4 @@
+source :rubygems
+gem "sinatra"
+gem "sass"
+gem "rdiscount"
@@ -0,0 +1,66 @@
+Sinatra Book Contrib
+--------------------
+
+Community contributed documentation for the [Sinatra Book][sinatra-book], a
+cookbook for the [Sinatra Web Framework][sinatra].
+
+## Why yet another doc project?
+
+Quite simply, the Sinatra README and Book have become long in the tooth.
+
+This project is to extract any redundant and overlap between the two sources,
+and create a home for user contributed recipes and documentation to take form.
+
+## How can I help?
+
+Got a recipe or tutorial for the [Sinatra Book][sinatra-book]? Awesome, this is
+the first place you should go if you're looking to contribute.
+
+Once you have [forked the project][github-forking] send a [pull
+request][github-pull-requests], just be sure to follow the [styling
+guidelines][style-guidelines].
+
+You can also get a hold of us on [irc][irc] or the [mailinglist][mailinglist].
+
+## Here's the run down
+
+To get started you should clone the repository from github:
+
+ git clone git://github.com/sinatra/sinatra-book-contrib.git
+
+Now once you `cd` into `sinatra-book-contrib` you should see a few things.
+
+First you should take note of the application files:
+
+ app.rb # a tiny application for displaying the contributed recipes
+ config.ru # rackup file for deploying to heroku
+ Gemfile # dependencies file for bundler to run the app
+
+If you want to run the application yourself first you need the `bundler` gem.
+
+ gem install bundler
+
+ # then install the application dependencies
+ bundle install
+
+Once that is complete, you should only need to run `rackup` in the application
+root and visit: [localhost:9292](http://localhost:9292)
+
+Since the application just maps the flat files, you can browse either the
+source or the web app to view recipes.
+
+If you check out the source you will see a few folders listed, in each folder
+there is a `README.md` that will briefly explain the topic. This can also be
+view by going to `/p/:topic` where `topic` is the folder you wish to view.
+
+In each folder there should be a number of recipes pertaining to each topic.
+
+[sinatra]: http://www.sinatrarb.com/
+[sinatra-book]: http://github.com/sinatra/sinatra-book
+[style-guidelines]: http://github.com/sinatra/sinatra-book-contrib/wiki/Style-Guidelines
+[irc]: irc://irc.freenode.net/#sinatra
+[mailinglist]: http://groups.google.com/group/sinatrarb
+[github-forking]: http://help.github.com/forking/
+[github-pull-requests]: http://help.github.com/pull-requests/
+
+
131 app.rb
@@ -0,0 +1,131 @@
+require 'sinatra'
+require 'rdiscount'
+require 'erb'
+require 'sass'
+
+before do
+ Dir.chdir('.')
+ flist = Dir['**/**'].select { |i| i.match(/\//) }.reject { |i| i.match(/README\.md/) }
+ @menu = {}
+ flist.collect { |i| m = i.split('/'); @menu[:"#{m[0]}"] = [] unless @menu[:"#{m[0]}"].is_a?(Array); @menu[:"#{m[0]}"].push(m[1]); }
+end
+
+get '/' do
+ readme = File.new "README.md"
+ output = RDiscount.new(readme.read).to_html
+ erb output
+end
+
+get '/p/:topic' do
+ readme = File.new "#{params[:topic]}/README.md"
+ output = RDiscount.new(readme.read).to_html
+ erb output
+end
+
+get '/p/:topic/:article' do
+ post = File.new "#{params[:topic]}/#{params[:article]}"
+ output = RDiscount.new(post.read).to_html
+ erb output
+end
+
+get '/style.css' do
+ sass :style
+end
+
+__END__
+
+@@ layout
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset='utf-8'>
+ <meta http-equiv="X-UA-Compatible" content="chrome=1">
+ <title>Sinatra Book Contrib</title>
+ <link rel="stylesheet" type="text/css" href="/style.css" />
+ </head>
+ <body>
+ <div id="header">
+ <h2>Community contributed recipes and techniques</h2>
+ <h1><a href="/">
+ <img src="http://github.com/sinatra/sinatra-book/raw/master/images/logo.png" />
+ </a></h1>
+ </div>
+ <div id="menu">
+ <ul>
+ <% @menu.each_key do |me| %>
+ <li><a href="/p/<%= "#{me}" %>"><%= me %></a>
+ <ul>
+ <% @menu[:"#{me}"].each do |mi| %>
+ <li><a href="/p/<%= "#{me}/#{mi}" %>"><%= mi.gsub('_', ' ').gsub('.md', '') %></a></li>
+ <% end %>
+ </ul></li>
+ <% end %>
+ </ul>
+ </div>
+ <div id="content">
+ <%= yield %>
+ </div>
+
+ <a href="http://github.com/sinatra">
+ <img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub" />
+ </a>
+ </body>
+</html>
+
+@@ style
+body
+ font-family: 'Lucida Grande', Verdana, sans-serif
+ margin: 0 auto
+ max-width: 800px
+
+h1, h2, h3, h4, h5
+ font-family: georgia, 'bitstream vera serif', serif
+ font-weight: normal
+ font-size: 2em
+
+a:link, a:visited
+ color: #3F3F3F
+
+a:hover, a:active
+ color: #8F8F8F
+
+.small
+ font-size: .7em
+
+#header
+ margin: 10px 0px
+
+#header a
+ text-decoration: none
+
+#header h1
+ float: left
+ width: 300px
+
+#header h2
+ text-align: right
+ font-style: oblique
+ font-size: 1em
+ float: right
+ width: 450px
+
+#menu
+ float: left
+ max-width: 320px
+ word-wrap: break-word
+ font-size: .9em
+ clear: left
+
+#content
+ float: right
+ width: 470px
+
+#content pre
+ padding: 10px
+ max-width: 470px
+ overflow: auto
+ overflow-Y: hidden
+ background: #EEE
+
+
+
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'bundler/setup'
+require 'app'
+run Sinatra::Application
@@ -0,0 +1,19 @@
+Deployment
+----------
+
+This section covers techniques and software used for deploying your Sinatra
+applications. Whether you're [deploying to Heroku][deploy-heroku] or a more
+advanced setup with [nginx and unicorn][nginx-unicorn], you should be able to
+find what your looking.
+
+## Did we miss something?
+
+It's very possible we've left something out, thats why we need your help! This
+is a community driven project after all. Feel free to fork the project and send
+us a pull request to get your recipe or tutorial included in the book.
+
+See the [README][readme] for more details.
+
+[readme]: http://github.com/sinatra/sinatra-book-contrib/blob/master/README.md
+[deploy-heroku]: http://sinatra-book.gittr.com/#heroku
+[nginx-unicorn]: http://sinatra-book-contrib.com/p/deployment/nginx_proxied_to_unicorn.md
@@ -0,0 +1,99 @@
+Apache and Passenger (mod rails)
+--------------------------------
+
+Hate deployment via FastCGI? You're not alone. But guess what, Passenger
+supports Rack; and this book tells you how to get it all going.
+
+You can find additional documentation at the [official modrails
+website](http://modrails.com/documentation.html).
+
+The easiest way to get started with Passenger is via the gem.
+
+### Installation
+
+First you will need to have [Apache
+installed](http://httpd.apache.org/docs/2.2/install.html), then you can move
+onto installing passenger and the apache passenger module.
+
+You have a number of options when [installing phusion
+passenger](http://modrails.com/documentation/Users%20guide%20Apache.html#_installing_upgrading_and_uninstalling_phusion_passenger),
+however the gem is likely the easiest way to get started.
+
+ gem install passenger
+
+Once you've got that installed you can build the passenger apache module.
+
+ passenger-install-apache2-module
+
+Follow the instructions given by the installer.
+
+### Deploying your app
+
+Passenger lets you easily deploy Sinatra apps through the Rack interface.
+
+There are some assumptions made about your application, however, particularly
+the `tmp` and `public` sub-directories of your application.
+
+In order to fit these prerequisites, simply make sure you have the following
+setup:
+
+ mkdir public
+ mkdir tmp
+ config.ru
+
+The public directory is for serving static files and tmp directory is for the
+`restart.txt` application restart mechanism. `config.ru` is where you will
+place your rackup configuration.
+
+**Rackup**
+
+Once you have these directories in place, you can setup your applications
+rackup file, `config.ru`.
+
+ require 'rubygems'
+ require 'sinatra'
+ require 'app.rb'
+
+ run Sinatra::Application
+
+**Virtual Host**
+
+Next thing you'll have to do is setup the [Apache Virtual
+Host](http://httpd.apache.org/docs/2.2/vhosts/) for your app.
+
+ <VirtualHost *:80>
+ ServerName www.yourapplication.com
+ DocumentRoot /path/to/app/public
+ <Directory /path/to/app/public>
+ Allow from all
+ Options -MultiViews
+ </Directory>
+ </VirtualHost>
+
+That should just about do it for your basic apache and passenger configuration.
+For more specific information please visit the [official modrails
+documentation](http://modrails.com/documentation/Users%20guide%20Apache.html).
+
+### A note about restarting the server
+
+Once you've got everything configured it's time to [restart
+Apache](http://httpd.apache.org/docs/2.2/stopping.html).
+
+On most debian-based systems you should be able to:
+
+ sudo apache2ctl stop
+ # then
+ sudo apache2ctl start
+
+To restart Apache. Check the link above for more detailed information.
+
+In order to [restart the Passenger
+application](http://www.modrails.com/documentation/Users%20guide%20Apache.html#_redeploying_restarting_the_ruby_on_rails_application),
+all you need to do is run this simple command for your application root:
+
+ touch tmp/restart.txt
+
+You should be up and running now with [Phusion Passenger](http://modrails.com/)
+and [Apache](http://httpd.apache.org/), if you run into any problems please
+consult the official docs.
+
@@ -0,0 +1,60 @@
+Dreamhost Deployment via Passenger
+----------------------------------
+
+You can deploy your Sinatra apps to Dreamhost, a shared web hosting service,
+via Passenger with relative ease. Here's how.
+
+1. Setting up the account in the Dreamhost interface
+
+ Domains -> Manage Domains -> Edit (web hosting column)
+ Enable 'Ruby on Rails Passenger (mod_rails)'
+ Add the public directory to the web directory box. So if you were using 'rails.com', it would change to 'rails.com/public'
+ Save your changes
+
+2. Creating the directory structure
+
+ domain.com/
+ domain.com/tmp
+ domain.com/public
+ # a vendored version of sinatra - not necessary if you use the gem
+ domain.com/sinatra
+
+3. Here is an example config.ru file that does two things. First, it requires
+ your main app file, whatever it's called. In the example, it will look for
+ `myapp.rb`. Second, run your application. If you're subclassing, use the
+ subclass's name, otherwise use Sinatra::Application.
+
+ require "myapp"
+
+ run Sinatra::Application
+
+4. A very simple Sinatra application
+
+ # this is myapp.rb referred to above
+ require 'sinatra'
+ get '/' do
+ "Worked on dreamhost"
+ end
+
+ get '/foo/:bar' do
+ "You asked for foo/#{params[:bar]}"
+ end
+
+And that's all there is to it! Once it's all setup, point your browser at your
+domain, and you should see a 'Worked on Dreamhost' page. To restart the
+application after making changes, you need to run `touch tmp/restart.txt`.
+
+Please note that currently passenger 2.0.3 has a bug where it can cause Sinatra to not find
+the view directory. In that case, add `:views => '/path/to/views/'` to the Sinatra options
+in your Rackup file.
+
+You may encounter the dreaded "Ruby (Rack) application could not be started"
+error with this message "can't activate rack (>= 0.9.1, < 1.0, runtime),
+already activated rack-0.4.0". This happens because DreamHost has version 0.4.0
+installed, when recent versions of Sinatra require more recent versions of Rack.
+The solution is to explicitly require the rack and sinatra gems in your
+config.ru. Add the following two lines to the start of your config.ru file:
+
+ require '/home/USERNAME/.gem/ruby/1.8/gems/rack-VERSION-OF-RACK-GEM-YOU-HAVE-INSTALLELD/lib/rack.rb'
+ require '/home/USERNAME/.gem/ruby/1.8/gems/sinatra-VERSION-OF-SINATRA-GEM-YOU-HAVE-INSTALLELD/lib/sinatra.rb'
+
Oops, something went wrong.

0 comments on commit 5d5467a

Please sign in to comment.