Created
April 22, 2011 08:57
-
-
Save imanel/936312 to your computer and use it in GitHub Desktop.
New templating system idea
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
<!-- 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> |
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
<!-- 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 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
// 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 |
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
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