Created
February 2, 2011 10:56
-
-
Save jeroenvandijk/807545 to your computer and use it in GitHub Desktop.
A tokamak view with nested collections https://github.com/caelum/tokamak
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
collection(@activities) do |collection| | |
collection.members(:root => "activities") do |member, activity| | |
# ... | |
# COMMENTS | |
if comments = @comments.try(:[], activity.id) | |
member.members(:root => "comments", :collection => comments) do |member, comment| | |
member.values { |comment_values| | |
comment_values.timestamp comment.created_at.to_i | |
comment_values.content comment.object.content | |
comment_values.actor { | |
comment_values.type comment.actor_type.downcase | |
comment_values.id comment.actor_id | |
} | |
} | |
end | |
end | |
# LIKES | |
if likes = @likes.try(:[], activity.id) | |
member.members(:root => "likes", :collection => likes) do |member, like| | |
member.values { |like_values| | |
like_values.timestamp like.created_at.to_i | |
like_values.actor { | |
like_values.type like.actor_type.downcase | |
like_values.id like.actor_id | |
} | |
} | |
end | |
end | |
# ... | |
end | |
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
{ "activities": | |
[ | |
{ | |
"comments": [ | |
{ | |
"timestamp": 1296039053, | |
"content" : "Alias omnis tenetur assumenda eligendi nisi.", | |
"actor": { | |
"id": 2, | |
"type": "user" | |
} | |
} | |
], | |
"likes": [ | |
{ | |
"timestamp": 1296039053, | |
"actor": { | |
"id": 2, | |
"type": "user" | |
} | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment