Skip to content

Instantly share code, notes, and snippets.

@goors
Created December 14, 2016 19:59
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 goors/04f3e9597d6d155a7dfa2d97630fa52b to your computer and use it in GitHub Desktop.
Save goors/04f3e9597d6d155a7dfa2d97630fa52b to your computer and use it in GitHub Desktop.
Google/Facebook like comments recursion with node.js jade template enging using mixin
if post.comments != undefined && post.comments.length
.container
.row
.comments-container
h2="Comments"
ul#comments-list.comments-list
mixin commentView(comment)
- var children = post.comments.filter(function(child) { return comment.id === parseInt(child.parent); })
- console.log(children)
if comment.parent != ""
li
.comment-avatar
if comment.user.avatar == ""
img(src='https://ssl.gstatic.com/accounts/ui/avatar_2x.png', alt='')
else
img(src='accounts/' + comment.user.id + "/" + comment.user.avatar, alt='')
.comment-box
.comment-head
h6.comment-name(class=(comment.user.id == post.idOwner ? 'by-author' : ''))
a()=comment.user.first_name + " " + comment.user.last_name
span hace 10 minutos
i.fa.fa-reply(data-ng-click="addComment('" + post.slug + "', '" + comment.id + "')")
.comment-content=comment.comment
each comment in children
ul.comments-list.reply-list
+commentView(comment)
li
each comment in post.comments
if comment.parent == ""
.comment-main-level
.comment-avatar
if comment.user.avatar == ""
img(src='https://ssl.gstatic.com/accounts/ui/avatar_2x.png', alt='')
else
img(src='accounts/' + comment.user.id + "/" + comment.user.avatar, alt='')
.comment-box
.comment-head
h6.comment-name(class=(comment.user.id == post.idOwner ? 'by-author' : ''))
a()=comment.user.first_name + " " + comment.user.last_name
span=moment.unix(comment.createdAt).format("DD-MMM-YYYY, h:mm:ss a")
i.fa.fa-reply(data-ng-click="addComment('" + post.slug + "', '" + comment.id + "')")
.comment-content=comment.comment
+commentView(comment)
.clear
.clear
.clear
.clear
.clear
@goors
Copy link
Author

goors commented Dec 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment