3. Sammy is a tiny JavaScript framework,
built on top of jQuery,
inspired by Ruby's Sinatra
4. Sinatra
class MyApp < Sinatra::Base
get '/list/:id' do
@list = List.get(params['id'])
haml :list
end
post '/list/' do
@list = List.create(params['list'])
redirect "/list/#{@list.name}"
end
end
5. Sammy
var app = $.sammy(function() {
this.get('#/list/:id', function() {
var list = List.get(this.params['id']);
this.partial('list.haml', { list: list });
});
this.post('#/list/', function() {
var list = List.create(this.params['list']);
this.redirect('#/list/' + list.id);
});
});
6. What for?
• Single page apps
• Total JavaScript apps
• A controller for widgets
9. Routes Examples
var app = $.sammy(function() {
this.get('#/list/:id', function() {
var list = List.get(this.params['id']);
this.partial('list.haml', { list: list });
});
this.post('#/list/', function() {
var list = List.create(this.params['list']);
this.redirect('#/list/' + list.id);
});
});
10. Events
• Event driven apps with custom events and
namespaces
• Looks like jQuery’s event API
• Some built-in life-cycle events
11. Events Example
var app = $.sammy(function() {
this.bind('markDone', function(e, data) {
// mark the todo as done
});
});
// trigger the markDone event later on
$('...').click(function(e) {
app.trigger('markDone', { id: this.id });
});
Contributing since Aug 2006
Contribute number of plugins like Live Query and bgiframe
Maintain a blog to share knowledge
Nokia in March as a senior technologist to explore the mobile web
Nokia investing significantly in web technologies