Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Elad Meidar
committed
Aug 13, 2012
1 parent
d9b5bf1
commit 709ff28
Showing
17 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
logs | |||
project/project | |||
project/target | |||
target | |||
tmp | |||
.history | |||
dist |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
This is your new Play 2.0 application | |||
===================================== | |||
|
|||
This file will be packaged with your application, when using `play dist`. |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
$ -> | |||
$.get "/listBars", (data) -> | |||
$.each data, (index, item) -> | |||
$("#bars").append "<li>" + item.name + " was here</li>" |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
package controllers | |||
|
|||
import play.api.data.Form | |||
import play.api.data.Forms.{single, nonEmptyText} | |||
import play.api.mvc.{Action, Controller} | |||
|
|||
import com.codahale.jerkson.Json | |||
|
|||
import anorm.NotAssigned | |||
|
|||
import models.Bar | |||
|
|||
|
|||
object Application extends Controller { | |||
|
|||
val barForm = Form( | |||
single("name" -> nonEmptyText) | |||
) | |||
|
|||
def index = Action { | |||
Ok(views.html.index(barForm)) | |||
} | |||
|
|||
def addBar() = Action { implicit request => | |||
barForm.bindFromRequest.fold( | |||
errors => BadRequest, | |||
{ | |||
case (name) => | |||
Bar.create(Bar(NotAssigned, name)) | |||
Redirect(routes.Application.index()) | |||
} | |||
) | |||
} | |||
|
|||
def listBars() = Action { | |||
val bars = Bar.findAll() | |||
|
|||
val json = Json.generate(bars) | |||
|
|||
Ok(json).as("application/json") | |||
} | |||
|
|||
} |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
package models | |||
|
|||
import play.api.db._ | |||
import play.api.Play.current | |||
|
|||
import anorm._ | |||
import anorm.SqlParser._ | |||
|
|||
case class Bar(id: Pk[Long], name: String) | |||
|
|||
object Bar { | |||
|
|||
val simple = { | |||
get[Pk[Long]]("id") ~ | |||
get[String]("name") map { | |||
case id~name => Bar(id, name) | |||
} | |||
} | |||
|
|||
def findAll(): Seq[Bar] = { | |||
DB.withConnection { implicit connection => | |||
SQL("select * from bar").as(Bar.simple *) | |||
} | |||
} | |||
|
|||
def create(bar: Bar): Unit = { | |||
DB.withConnection { implicit connection => | |||
SQL("insert into bar(name) values ({name})").on( | |||
'name -> bar.name | |||
).executeUpdate() | |||
} | |||
} | |||
|
|||
} |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
@(form: play.api.data.Form[String]) | |||
|
|||
@main("Elad's tests") { | |||
|
|||
@helper.form(action = routes.Application.addBar) { | |||
@helper.inputText(form("name")) | |||
<input type="submit"/> | |||
} | |||
|
|||
<script src="@routes.Assets.at("javascripts/index.js")" type="text/javascript"></script> | |||
<ul id="bars">koko</ul> | |||
} |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
@(title: String)(content: Html) | |||
|
|||
<!DOCTYPE html> | |||
|
|||
<html> | |||
<head> | |||
<title>@title</title> | |||
<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("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script> | |||
</head> | |||
<body> | |||
@content | |||
</body> | |||
</html> |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
# This is the main configuration file for the application. | |||
# ~~~~~ | |||
|
|||
# Secret key | |||
# ~~~~~ | |||
# The secret key is used to secure cryptographics functions. | |||
# If you deploy your application to several instances be sure to use the same key! | |||
application.secret="mtcN0fdBoU1L:VaDpE;uYm2EVkoiknKeOS>aKLRdeb_MaLt17Ag4D3CekVrq42Qy" | |||
|
|||
# The application languages | |||
# ~~~~~ | |||
application.langs="en" | |||
|
|||
# Global object class | |||
# ~~~~~ | |||
# Define the Global object class for this application. | |||
# Default to Global in the root package. | |||
# global=Global | |||
|
|||
# Database configuration | |||
# ~~~~~ | |||
# You can declare as many datasources as you want. | |||
# By convention, the default datasource is named `default` | |||
# | |||
db.default.driver=org.h2.Driver | |||
db.default.url="jdbc:h2:mem:play" | |||
|
|||
# Evolutions | |||
# ~~~~~ | |||
# You can disable evolutions if needed | |||
# evolutionplugin=disabled | |||
|
|||
# Logger | |||
# ~~~~~ | |||
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory . | |||
|
|||
# Root logger: | |||
logger.root=ERROR | |||
|
|||
# Logger used by the framework: | |||
logger.play=INFO | |||
|
|||
# Logger provided to your application: | |||
logger.application=DEBUG | |||
|
Empty file.
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
# --- First database schema | |||
|
|||
# --- !Ups | |||
|
|||
CREATE TABLE bar ( | |||
id SERIAL PRIMARY KEY, | |||
name VARCHAR(255) NOT NULL | |||
); | |||
|
|||
# --- !Downs | |||
|
|||
DROP TABLE IF EXISTS bar; |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
# Routes | |||
# This file defines all application routes (Higher priority routes first) | |||
# ~~~~ | |||
|
|||
# Home page | |||
GET / controllers.Application.index | |||
POST /addBar controllers.Application.addBar | |||
GET /listBars controllers.Application.listBars | |||
|
|||
# Map static resources from the /public folder to the /assets URL path | |||
GET /assets/*file controllers.Assets.at(path="/public", file) |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
import sbt._ | |||
import Keys._ | |||
import PlayProject._ | |||
|
|||
object ApplicationBuild extends Build { | |||
|
|||
val appName = "foobar" | |||
val appVersion = "1.0-SNAPSHOT" | |||
|
|||
val appDependencies = Seq( | |||
// Add your project dependencies here, | |||
) | |||
|
|||
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings( | |||
// Add your own project settings here | |||
) | |||
|
|||
} |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
sbt.version=0.11.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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
// Comment to get more information during initialization | |||
logLevel := Level.Warn | |||
|
|||
// The Typesafe repository | |||
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | |||
|
|||
// Use the Play sbt plugin for Play projects | |||
addSbtPlugin("play" % "sbt-plugin" % "2.0.1") |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.