simplifying templates

This commit is contained in:
Troy Goode 2012-08-23 00:35:31 -04:00
parent 507540af1d
commit deb84431d2
6 changed files with 36 additions and 25 deletions

View file

@ -13,5 +13,12 @@
<div class="comment-text">{{body}}</div>
<a href="#" class="comment-reply">Reply</a>
</div>
<ul class="comment-children">
{{#each comments}}
{{#with this}}
{{> comment}}
{{/with}}
{{/each}}
</ul>
</li>
</template>

View file

@ -10,3 +10,9 @@ Template.comment.ago = function(){
var submitted = new Date(this.submitted);
return submitted.toString();
};
Template.comment.comments = function(){
var post = Session.get('selected_post');
var comments = Comments.find({ post: post._id, parent: this._id });
return comments;
};

View file

@ -1,11 +0,0 @@
<template name="comments">
{{#if show}}
<ul>
{{#each comments}}
{{> comment}}
{{/each}}
</ul>
{{else}}
<p>No comments.</p>
{{/if}}
</template>

View file

@ -1,11 +0,0 @@
Template.comments.show = function(){
var post = Session.get('selected_post');
var comments = Comments.find({ post: post._id });
return comments.count() > 0;
};
Template.comments.comments = function(){
var post = Session.get('selected_post');
var comments = Comments.find({ post: post._id });
return comments;
};

View file

@ -1,11 +1,12 @@
<template name="selected_post">
{{#if show}}
{{#with post}}
<div class="selected-post grid">
{{#with post}}
{{> post}}
{{#if body}}
<div class="post-message">{{body}}</div>
{{/if}}
{{/with}}
<div class="comment-new">
<div class="comment-field">
<textarea id="comment" rows="3" autofocus="autofocus"></textarea>
@ -14,8 +15,15 @@
<input type="submit" value="Add Comment" />
</div>
</div>
{{> comments}}
{{#if has_comments}}
<ul>
{{#each comments}}
{{> comment}}
{{/each}}
</ul>
{{else}}
<p>No comments.</p>
{{/if}}
</div>
{{/with}}
{{/if}}
</template>

View file

@ -21,3 +21,15 @@ Template.selected_post.post = function(){
var post = Session.get('selected_post');
return post;
};
Template.selected_post.has_comments = function(){
var post = Session.get('selected_post');
var comments = Comments.find({ post: post._id, parent: null });
return comments.count() > 0;
};
Template.selected_post.comments = function(){
var post = Session.get('selected_post');
var comments = Comments.find({ post: post._id, parent: null });
return comments;
};