Permalink
Browse files

Add Bootstrap

  • Loading branch information...
1 parent ecf41cd commit 5e92362547b83ec33042448fcd7f2f232b5f7887 @jamesward committed Apr 1, 2015
View
2 app/controllers/Application.java
@@ -8,7 +8,7 @@
public class Application extends Controller {
public static Result index() {
- return ok(index.render("hello, world"));
+ return ok(index.render("hello, world", play.data.Form.form(models.Task.class)));
}
public static Result addTask() {
View
28 app/views/index.scala.html
@@ -1,13 +1,25 @@
-@(message: String)
+@(message: String, taskForm: Form[Task])
+@implicitFieldConstructor = @{ helper.FieldConstructor(twitterBootstrapInput.render) }
-@main("Welcome to Play") {
+@main("Welcome to Play 2.0") {
- @message.toUpperCase
+ <div class="navbar navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="container-fluid">
+ <a id="titleLink" class="brand" href="/">@message.toUpperCase</a>
+ </div>
+ </div>
+ </div>
- <ul id="tasks"></ul>
+ <div class="container">
+ <ul id="tasks"></ul>
+
+ @helper.form(action = routes.Application.addTask(), 'class -> "well form-horizontal") {
+ @helper.inputText(taskForm("contents"), '_label -> "Contents")
+ <div class="controls">
+ <input type="submit" class="btn btn-primary"/>
+ </div>
+ }
+ </div>
- @helper.form(action = routes.Application.addTask()) {
- <input name="contents"/>
- <input type="submit"/>
- }
}
View
1 app/views/main.scala.html
@@ -5,6 +5,7 @@
<html>
<head>
<title>@title</title>
+ <link rel="stylesheet" media="screen" href="@routes.Assets.at("lib/bootstrap/css/bootstrap.min.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("lib/jquery/jquery.min.js")" type="text/javascript"></script>
View
9 app/views/twitterBootstrapInput.scala.html
@@ -0,0 +1,9 @@
+@(elements: helper.FieldElements)
+
+<div class="control-group @if(elements.hasErrors) {error}">
+ <label for="@elements.id" class="control-label">@elements.label</label>
+ <div class="controls">
+ @elements.input
+ <span class="help-inline">@elements.errors.mkString(", ")</span>
+ </div>
+</div>
View
4 build.sbt
@@ -13,4 +13,6 @@ libraryDependencies ++= Seq(
javaWs
)
-libraryDependencies += "org.webjars" % "jquery" % "1.11.2"
+libraryDependencies += "org.webjars" % "jquery" % "1.11.2"
+
+libraryDependencies += "org.webjars" % "bootstrap" % "2.1.1"
View
3 public/stylesheets/main.css
@@ -0,0 +1,3 @@
+body {
+ padding-top: 50px;
+}
View
2 test/ApplicationTest.java
@@ -36,7 +36,7 @@ public void simpleCheck() {
@Test
public void renderTemplate() {
- Content html = views.html.index.render("HELLO, WORLD");
+ Content html = views.html.index.render("HELLO, WORLD", play.data.Form.form(models.Task.class));
assertThat(contentType(html)).isEqualTo("text/html");
assertThat(contentAsString(html)).contains("HELLO, WORLD");
}

0 comments on commit 5e92362

Please sign in to comment.