Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sinatra: A whirlwind tour!!

Karmen Blake
September 26, 2011

Sinatra: A whirlwind tour!!

Karmen Blake

September 26, 2011
Tweet

More Decks by Karmen Blake

Other Decks in Programming

Transcript

  1. "Sinatra is a DSL for quickly creating web applications in

    Ruby with minimal effort" http://www.sinatrarb.com/intro
  2. Setup Bundler Gemfile source :rubygems gem 'rack', '~> 1.1' gem

    'sinatra', :git => "git://github.com/sinatra/sinatra.git" # reload code in development gem 'rerun' # or shotgun
  3. Setup Bundler Sinatra app file, you need to add these

    lines: require 'bundler' Bundler.setup
  4. Routing RESTful get '/' do "hello world" end post '/'

    do # create something end put '/' do # update end delete '/' do # boom! end
  5. Routing named routes and parameters get '/hola' do "hello world"

    end get '/hola/:name' do "hello world " + params[:name] end get '/hola/:name' do |your_name| "hello world #{your_name}" end get '/hola.json' do {:greeting => "hello world"}.to_json end
  6. SCSS Templates get '/styles.css' do scss :styles end Looks for

    views/styles.scss Template reference to generated css: <link href='/styles.css' rel='stylesheet' />
  7. Helpers #define the helpers block in your app helpers do

    def project_options(projects) projects.map do |project| "<option value='#{project.id}'>#{project.name}</option>" end.join end end Call helper methods in templates and route handlers
  8. Settings Set application-level variables set :member_name, 'John Doe' set :token,

    '1234' set :wip_story_limit, '3' Get variables from anywhere in application settings.member_name settings.token settings.wip_story_limit
  9. Demo "A Work In Progress (WIP) Limit Helps You Focus.

    If you set your WIP limit to two or three for tasks being “in progress”, it helps you focus on exactly those tasks. And you have an explicit motivation for getting those tasks done as you should only start new stuff if there is an empty space on your Kanban board for another “in progress” task. " http://www.agileweboperations.com/kanban- wip-limits-the-fine-art-of-focus