Created
March 9, 2011 00:35
-
-
Save cmilfont/861452 to your computer and use it in GitHub Desktop.
Consumindo a API do Call4paperz com o Sammy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//API do https://gist.github.com/850289#comments | |
//Exemplo funcionando http://braziljs.com.br/2011#!/agenda | |
/*Callback que vai renderizar o template na pagina*/ | |
var call4paperz = { | |
url: "http://call4paperz.com/events/13.jsonp", | |
callback: function() { | |
/* contexto de this aqui é repassado para o Sammy, vou precisar abaixo*/ | |
var sammy = this; | |
/* quando o Sammy carrega ele poe os dados em this.content */ | |
var proposals = sammy.content.event.proposals; | |
/* consultinha com o JQuery */ | |
$("td.lightning", "table#programacao table tr") | |
.each(function(index) { | |
/* | |
aqui eu carrego o template | |
que será renderizado em html com a proposta passada | |
depois faço o replace no td apropriado | |
*/ | |
sammy.render('/views/lightning.html', proposals[index]).replace($(this)); | |
}); | |
} | |
}; | |
/* construção baunilha do Sammy, nada demais */ | |
;(function($) { | |
var app = $.sammy('#corpo .container', function() { | |
/* engine de template que usei */ | |
this.use(Sammy.Mustache, "html"); | |
/* a rota que vai ser executada*/ | |
this.get('#!/agenda', function() { | |
/* carrego a pagina da agenda primeiro*/ | |
this.partial('/views/agenda.html') | |
.then(function() { | |
/*aqui que esta a brincadeira, carrego o JSON do C4P, e repasso para aquele callback que vimos */ | |
this.load(call4paperz.url, {dataType: "jsonp"}, call4paperz.callback); | |
}); | |
}); | |
}); | |
$(function() { | |
app.run('#!/home'); | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#user}} {{name}} {{/user}}<br/> | |
{{name}}<br/> | |
Votos válidos: {{acceptance_points}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment