Skip to content
This repository

Classy web-development dressed in a DSL (official / canonical repo)

Fetching latest commit…

Cannot retrieve the latest commit at this time

README
Sinatra (C) 2007 By Blake Mizerany

= Classy web-development dressed in a DSL

== Install!

  sudo gem install sinatra -y

== Use!

I'm going to move quick.  I'll let you drool at your own pace.

- Create a file called lyrics.rb (or any name you like)

- Add
    require 'rubygems'
    require 'sinatra'

- Run (yes, with just ruby)
    % ruby lyrics.rb
    == Sinata has taken the stage on port 4567!

- Take a moment and view the default page http://localhost:4567.  Go ahead and bask in it's glory.

* Notice:
  * It didn't create any page to show you that default page (just a cool thing to see, that's all)
  * There was nothing generated other than a log file
  * Sinatra is a really cool name for a web-framework that's a DSL

- Modify lyrics.rb by adding:

    get '/' do
      'Hello World'
    end
  
- Refresh (no need to restart Sinatra):

    http://localhost:4567

- Modify again (then refresh):

    get '/' do
      <<-HTML
        <form action='/' method="POST">
          <input type="text" name="name" />
          <input type="submit" value="Say my name!" />
        </form>
      HTML
    end
  
    post '/' do
      "Hello #{params[:name] || 'World'}!"
    end
  
- Homework:

Use the Sinatra::Erb::EventContext or Sinatra::Haml::EventContext to do the same.  Do them inline and as template files.
Something went wrong with that request. Please try again.