Created
May 22, 2012 22:24
-
-
Save tbeseda/2772033 to your computer and use it in GitHub Desktop.
How I do one-off front-end templating with Handlebars, HAML, and CoffeeScript.
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
%script#instagram-thumbnail-popover{type: "text/x-handlebars-template"} | |
%img{src: "{{images.low_resolution.url}}"}/ | |
%i.icon-heart/ | |
{{likes.count}} likes | |
%script#instagram-thumbnails{type: "text/x-handlebars-template"} | |
%ul.thumbnails | |
{{#data}} | |
%li.span1 | |
%a.thumbnail{href: "{{link}}", title: "{{caption.text}}", data: {content:"{{> popover}}"}} | |
%img{src: "{{images.thumbnail.url}}"} | |
{{/data}} |
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
$ -> | |
Handlebars.registerPartial 'popover', $('#instagram-thumbnail-popover').html() | |
instagram_template = Handlebars.compile $('#instagram-thumbnails').html() | |
$.getJSON "/instagram/#{instagram_handle}", (response) -> | |
instagram_html = instagram_template response | |
$instagram.append instagram_html | |
$instagram.find('.thumbnail').popover placement: 'bottom' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not advisable to compile templates at runtime at any sort of significant scale, but works great for single page apps when you can compile templates one at time, as needed, on the fly.