Skip to content
/ snap Public
forked from bcarlso/snap

Sinatra NAmed Path extension. Adds named path and URL building support to Sinatra

License

Notifications You must be signed in to change notification settings

criminy/snap

This branch is 2 commits ahead of, 12 commits behind bcarlso/snap:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d1dd56a · Sep 4, 2010

History

29 Commits
Mar 9, 2010
Sep 4, 2010
Mar 13, 2010
Jul 25, 2009
Jul 25, 2009
Jul 25, 2009
Mar 9, 2010
Mar 9, 2010
Mar 14, 2010
Mar 14, 2010

Repository files navigation

Sinatra NAmed Paths (snap)

Enables named paths in Sinatra apps.

The SNAP extension is a solution for named paths in Sinatra. It also provides helper methods to build URLs and perform parameter substitution.

Install the gem:

sudo gem install sinatra-snap

Then require it in your application and use away!

require 'rubygems'
require 'sinatra'
require 'sinatra-snap'

paths :add => '/add/:addend/:augend',
      :sum => '/sum/:addend/:augend',

:subtract => ‘/subtract//’, :difference => %r{/difference/(d+)/(d+)}

get :add do
  redirect path_to(:sum).with(params[:addend], params[:augend])
end

get :sum do
  "#{params[:addend]} + #{params[:augend]} = #{params[:addend].to_i + params[:augend].to_i}"
end

get :subtract do
  redirect path_to(:difference).with(params[:splat][0], params[:splat][1])
end

get :difference do
  "#{params[:captures][0]} - #{params[:captures[1]]} = #{params[:captures][0]].to_i - params[:captures][1]].to_i}"
end

Copyright © 2009 Brandon Carlson (bcarlso). See LICENSE for details.

About

Sinatra NAmed Path extension. Adds named path and URL building support to Sinatra

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%