Created
April 10, 2012 19:04
-
-
Save santiagobasulto/2353715 to your computer and use it in GitHub Desktop.
Mustache + 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
# From this: | |
content: (post_id,user_name,user_picture)-> | |
li = "<li class='comment-box'><a href='#' class='img tooltip'>" | |
img = "<img src='"+user_picture+"' width='40' height='40'>" | |
tooltip = "<small style='width: 68px; margin-left: -46px; '>"+user_name+"</small></a><section>" | |
form = $("<form></form>") | |
form.attr('action', '/comments/post/') | |
form.attr('method','POST') | |
csrf_value = $("input[name='csrfmiddlewaretoken']").val() | |
form.append($("<input type='hidden' name='csrfmiddlewaretoken' value='"+csrf_value+"'></input>")) | |
form.append($("<input type='hidden' name='content_type' value='profile.post' id='id_content_type'>")) | |
form.append($("<input type='hidden' name='object_pk' value='"+post_id+"' id='id_object_pk'>")) | |
form.append($("<input type='hidden' name='honeypot' id='id_honeypot'>")) | |
form.append($("<input type='text' name='comment'></input>")) | |
form.append($("<footer class='enter'>Hit enter to post <em>↵</em></footer>")) | |
last = """ | |
</section> | |
</li> | |
""" | |
li+img+tooltip+form.html()+last | |
# to this: | |
content: (post_id,user_name,user_picture)-> | |
variables = | |
post_id: post_id | |
user_name: user_name | |
user_picture: user_picture | |
csrf_token: $("input[name='csrfmiddlewaretoken']").val() | |
Mustache.render(template,variables) | |
# Template | |
<li class="comment-box"> | |
<a href="#" class="img tooltip"> | |
<img src="{{user_picture}}" width="40" height="40"> | |
<small style="width: 68px; margin-left: -46px; ">{{user_name}}</small> | |
</a> | |
<section> | |
<input type="hidden" name="csrfmiddlewaretoken" value="{csrf_token}"> | |
<input type="hidden" name="object_pk" value="{{post_id}}" id="id_object_pk"> | |
<input type="hidden" name="honeypot" id="id_honeypot"> | |
<input type="text" name="comment"> | |
<footer class="enter">Hit enter to post <em>↵</em></footer> | |
</section> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment