Sammy.js
nyc.js / june 3, 2009
nyc.js / june 3, 2009



Sammy is a tiny JavaScript framework,
built on top of jQuery,
inspired by Ruby's Sinatra
# app.rb
class MyApp < Sinatra::Default
get '/user/:name' do
@user = User.find_by_name(params['name'])
erb :user
end
post '/user/' do
@user = User.create(params['user'])
redirect "/user/#{user.name}"
end
end
// app.js
var app = $.sammy(function() { with(this) {
get('#/user/:name', function() { with(this) {
User.get(params['name'], function() {
partial('user.html.erb', {user: user});
});
}});
post('#/user/', function() { with(this) {
User.create(params['user'], function(user) {
redirect('#/user/' + user.name);
});
}});
}});
Like <10K for real.
I know you be sweatin' gmail.
Turtles all the way down (with a crunchy erlang center)
I like Javascript
// routes
get('#/', function() { //... do something ... });
// events
bind('custom-event', function() { //... do something ... });
get('#/', function() {
// this == EventContext
});
bind('custom', function() {
// this == EventContext
});
// helpers
helpers({
autolink: function(text) {
return text.gsub(/(http\:\/\/[^s]+)/, '<a href="$1">$1</a>');
}
});
// befores
before(function() {
if (!loaded) {
// load
return false; // stops the execution of routes.
}
});
Please don't fuck this up . . .
seriously, it's early days