Created
April 28, 2014 16:21
-
-
Save privateblue/11376838 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class PermalinkPageData( | |
post: Post, | |
comments: ReplyList, | |
sidebar: Sidebar) | |
class PermalinkPageDataSoy extends SoyWrites[PermalinkPageData] { | |
def toSoy: Future[SoyMap] = Soy.future { | |
"post" -> post.toSoy, | |
"comments" -> comments.toSoy, | |
"sidebar" -> sidebar.render.map(SoyString(_)) | |
} | |
} | |
case class SidebarData( | |
titles: Future[List[String]]) | |
class SidebarDataSoy extends SoyWrites[SidebarData] { | |
def toSoy = Soy.map { | |
"titles" -> titles.toSoy | |
} | |
} | |
trait PageFragment { | |
val render: Future[String] = data.map(Closure.render(template, _.toSoy)) | |
} | |
class PermalinkPage(postId: Id) extends PageFragment { | |
val template = "permalink.soy" | |
val data: Future[PermalinkPageData] = | |
async { | |
val post = PostApiClient.getPost(postId) | |
val comments = ReplyApiClient.getReplies(postId) | |
val sidebar = new Sidebar(post.authorId) | |
(post, comments, sidebar) | |
} map { | |
case(post, comments, sidebar) => | |
PermalinkPageData( | |
post = post, | |
comments = comments, | |
sidebar = sidebar) | |
} | |
} | |
class Sidebar(authorId: Id) extends PageFragment { | |
val template = "sidebar.soy" | |
val data: Future[SidebarData] = | |
SidebarApiClient.getTitles(authorId).map { | |
SidebarData(titles = _).toSoy | |
} | |
} | |
object PermalinkController { | |
def permalinkPage(postId: Id) = new PermalinkPage(postId).render.map(SimpleResult(_)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment