Skip to content

Instantly share code, notes, and snippets.

@imanel
Created April 22, 2011 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imanel/936312 to your computer and use it in GitHub Desktop.
Save imanel/936312 to your computer and use it in GitHub Desktop.
New templating system idea
<!-- Some JS loading JSON from /users/index.json and put it to #users via jTemplates -->
<div id="users">
</div>
<script type="text/javascript" id="Templates">
{#template USERS}
<div class="user">
<p>{$T.name}</p>
<p>{$T.email}</p>
<ul>
{#foreach $T.comments as comment}
{#include comment root=$T.comment}
{#/for}
</ul>
</div>
{/#template USERS}
{#template COMMENT}
<li>{$T.content}</li>
{/#template COMMENT}
</script>
<!-- No JS used -->
<div id="users">
<div class="user">
<p>First</p>
<p>first@example.org</p>
<ul>
<li>first comment</li>
<li>second comment</li>
</ul>
</div>
<div class="user">
<p>Second</p>
<p>seconf@example.org</p>
<ul>
<li>third comment</li>
<li>fourtn comment</li>
</ul>
</div>
</div>
// This could be also used in ERB or anything else...
#users
= @source.users.each do |user|
.user
%p
= user.name
%p
= user.email
%ul
- user.comments.each do |comment|
%li
= comment.content
class UsersController < ApplicationController
def index
respond_to do |format|
format.html
format.json { render :json => User.all }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment