Last active
October 1, 2015 04:18
-
-
Save julienrf/1918776 to your computer and use it in GitHub Desktop.
Composite UI without boilerplate using Play 2
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
object Application extends Controller { | |
val index = Action { implicit request => | |
Ok(views.html.index()) | |
} | |
val show = Action { implicit request => | |
Ok(views.html.show("42")) | |
} | |
implicit def user(implicit session: Session): Option[User] = { | |
for (name <- session.get("username")) yield User(name) | |
} | |
} |
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
object Application extends Controller { | |
val index = Action { implicit request => | |
Ok(views.html.index(user(session))) | |
} | |
val show = Action { implicit request => | |
Ok(views.html.show(user(session), "42")) | |
} | |
def user(session: Session): Option[User] = { | |
for (name <- session.get("username")) yield User(name) | |
} | |
} |
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
@(user: Option[User], message: String) | |
@main(user) { | |
<h1>@message</h1> | |
} |
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
@(message: String)(implicit user: Option[User]) | |
@main { | |
<h1>@message</h1> | |
} |
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
trait Users { | |
implicit def user(implicit session: Session): Option[User] = { | |
for (name <- session.get("username")) yield User(name) | |
} | |
} | |
object Application extends Controller with Users { | |
val index = Action { implicit request => | |
Ok(views.html.index()) | |
} | |
val show = Action { implicit request => | |
Ok(views.html.show("42")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment