Giter VIP home page Giter VIP logo

sammy's Introduction

Sammy

http://sammyjs.org

Description

Sammy is a tiny javascript framework built on top of jQuery inspired by Ruby's Sinatra.

Installation

Download Sammy.js and install it in your public javascripts directory. Include it in your document AFTER jQuery.

Usage

Like Sinatra, a Sammy application revolves around 'routes'. Routes in Sammy are a little different, though. Not only can you define 'get' and 'post' routes, but you can also bind routes to custom events triggered by your application.

You set up a Sammy Application by passing a Function to the $.sammy (which is a shortcut for the Sammy.Application constructor).

$.sammy(function() {

  this.get('#/', function() {
    $('#main').text('Welcome!');
  });

});

Inside the 'app' function() this is the Application. This is where you can configure the application and add routes.

Above, we defined a get() route. When the browser is pointed to #/ the function passed to that route will be run. Inside the route function, this is a Sammy.EventContext. EventContext has a bunch of special methods and properties including a params hash, the ability to redirect, render partials, and more.

In its coolness, Sammy can handle multiple chained asynchronous callbacks on a route.

this.get('#/', function(context,next) {
  $('#main').text('Welcome!');
		$.get('/some/url',function(){
			// save the data somewhere
			next();
		});
}, function(context,next) {
		$.get('/some/other/url',function(){
			// save this data too
			next();
		});
	});

Once you've defined an application the only thing left to do is run it. The best-practice behavior is to encapsulate run() in a document.ready block:

var app = $.sammy(...)

$(function() {
  app.run();
});

This will guarantee that the DOM is loaded before we try to apply functionality to it.

Dependencies

Sammy requires jQuery >= 1.4.1 Get it from: http://jquery.com

More!

Learn!

Keep informed!

Authors

Sammy.js was created and is maintained by Aaron Quint with additional features and fixes contributed by these talented individuals:

  • Frank Prößdorf / endor
  • Alexander Lang / langalex
  • Scott McMillin / scottymac
  • ZhangJinzhu / jinzhu
  • Jesse Hallett / hallettj
  • Jonathan Vaught / gravelpup
  • Jason Davies / jasondavies
  • Russell Jones / CodeOfficer
  • Geoff Longman
  • Jens Bissinger / dpree
  • Tim Caswell / creationix
  • Mark Needham
  • SamDeLaGarza
  • Mickael Bailly / dready92
  • Rich Manalang / manalang
  • Brian Mitchell / binary42
  • Assaf Arkin / assaf
  • James Rosen / jamesrosen
  • Chris Mytton
  • kbuckler
  • dvv
  • Ben Vinegar / benvinegar
  • Avi Deitcher / deitch

Donate!

If you're using Sammy.js in production or just for fun, instead of gifting me a beer - please consider donating to the Code for Other People Fund. - you can probably spare a dollar or ten and it will be greatly appreciated.

License

Sammy is covered by the MIT License. See LICENSE for more information.

sammy's People

Contributors

quirkey avatar endor avatar rikkert avatar deitch avatar le0pard avatar dfunckt avatar erpheus avatar jpgarcia avatar creationix avatar vicb avatar crofty avatar stephen101 avatar bsingr avatar jinzhu avatar teelahti avatar stevenharman avatar flashingpumpkin avatar assaf avatar hallettj avatar kbuckler avatar kevingessner avatar mtscout6 avatar rmanalan avatar fhemberger avatar delrosario avatar tdetoux avatar samdelagarza avatar piecioshka avatar nur-psoehnlein avatar plasticlizard avatar

Watchers

James Cloos avatar  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.