Coder Social home page Coder Social logo

snap's Introduction

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.

snap's People

Contributors

bcarlso avatar

Stargazers

sheenobu avatar

Watchers

sheenobu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.