public
Last active

  • Download Gist
.gitignore
1
target
README
1
play 2.0.4 example project for answer on stackoverflow http://stackoverflow.com/questions/13847704/how-to-create-a-list-of-links/13859170#13859170
app/controllers/Application.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13
package controllers
 
import play.api._
import play.api.mvc._
import so13847704._
 
object Application extends Controller {
def index = Action { implicit request =>
Ok(views.html.list(Link.allLinks))
}
}
app/controllers/Products.scala
Scala
1 2 3 4 5 6 7 8 9 10 11
package controllers
 
import play.api.mvc._
 
object Products extends Controller {
def list = Action {
Ok("Products")
}
}
app/controllers/SomeModels.scala
Scala
1 2 3 4 5 6 7 8 9 10 11
package controllers
 
import play.api.mvc._
 
object SomeModels extends Controller {
def list = Action {
Ok("SomeModels")
}
}
app/views/index.scala.html
HTML
1 2 3 4 5 6 7
@(message: String)
 
@main("Welcome to Play 2.0") {
@play20.welcome(message)
}
app/views/list.scala.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13
@(links: List[so13847704.Link])(implicit flash: Flash, lang: Lang)
 
@main("welcome to my awesome play app") {
<dl class="models">
@for(link <- links) {
<dt>
<a href=@link.route>
@link.name
</a>
</dt>
}
</dl>
}
app/views/main.scala.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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>
conf/application.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
# 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="4u;2XGpBiv>T?<]7dapuE]tV>nWLyO4klATX:EyA7OT2DqQ`wa_aGq73SHCoj=U["
 
# 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"
# db.default.user=sa
# db.default.password=
 
# 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
conf/routes
1 2 3 4 5 6 7 8 9 10 11
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
 
# Home page
GET / controllers.Application.index
GET /p controllers.Products.list
GET /s controllers.SomeModels.list
 
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
project/Build.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import sbt._
import Keys._
import PlayProject._
 
object ApplicationBuild extends Build {
 
val appName = "How to create a list of links"
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
)
 
}
project/build.properties
INI
1
sbt.version=0.11.3
project/plugins.sbt
Scala
1 2 3 4 5 6 7 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.4")
public/images/favicon.png