Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Jan 29, 2014
0 parents commit 7340c6e
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
logs
project/project
project/target
target
tmp
.history
dist
/.idea
/*.iml
/out
/.idea_modules
/.classpath
/.project
/RUNNING_PID
/.settings
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is your new Play application
=====================================

This file will be packaged with your application, when using `play dist`.
39 changes: 39 additions & 0 deletions app/actors/MessageStream.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package actors

import scala.collection.parallel.ParSet

import play.api.libs.ws.WS
import play.api.libs.iteratee.{ Iteratee, Enumerator, Concurrent }
import play.api.libs.concurrent.Execution.Implicits._

import akka.actor.{Props, ActorRef, Actor}

object MessageStream {

case class Subscribe(actor: ActorRef)

case class Unsubscribe(actor: ActorRef)

}

class MessageStream extends Actor {

import MessageStream._

type Message = String

var subscribers = ParSet[ActorRef]()

val messages = Enumerator[Message]("The discarded bicycle pressures the rod.", "How does the definitive plaster honor an appointed scholar?", "A hollow parade tends a worthwhile deaf. Why can't the circle migrate?")

val (streamEnumerator, streamChannel) = Concurrent.broadcast[Message]

streamEnumerator |>>> Iteratee.foreach[Message](m => subscribers.foreach(_ ! m))

def receive = {

case Subscribe(actor: ActorRef) => subscribers = subscribers + actor

case Unsubscribe(actor: ActorRef) => subscribers = subscribers - actor
}
}
12 changes: 12 additions & 0 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package controllers

import play.api._
import play.api.mvc._

object Application extends Controller {

def index = Action {
Ok(views.html.index("Your new application is ready."))
}

}
7 changes: 7 additions & 0 deletions app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@(message: String)

@main("Welcome to Play") {

@play20.welcome(message)

}
15 changes: 15 additions & 0 deletions app/views/main.scala.html
Original file line number 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.9.0.min.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name := "reactive-tweets"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
jdbc,
anorm,
cache
)

play.Project.playScalaSettings
59 changes: 59 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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="I7INou2GZa_eGmWTbIDEyE>pAwNU:WewGvH?bQpMS6jdaMf`UbaAmc/H@loO=gfx"

# The application languages
# ~~~~~
application.langs="en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# application.router=my.application.Routes

# 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 an application-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

9 changes: 9 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET / controllers.Application.index

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.0
8 changes: 8 additions & 0 deletions project/plugins.sbt
Original file line number 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("com.typesafe.play" % "sbt-plugin" % "2.2.1")
Binary file added public/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/javascripts/jquery-1.9.0.min.js

Large diffs are not rendered by default.

Empty file added public/stylesheets/main.css
Empty file.
30 changes: 30 additions & 0 deletions test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._

import play.api.test._
import play.api.test.Helpers._

/**
* Add your spec here.
* You can mock out a whole application including requests, plugins etc.
* For more information, consult the wiki.
*/
@RunWith(classOf[JUnitRunner])
class ApplicationSpec extends Specification {

"Application" should {

"send 404 on a bad request" in new WithApplication{
route(FakeRequest(GET, "/boum")) must beNone
}

"render the index page" in new WithApplication{
val home = route(FakeRequest(GET, "/")).get

status(home) must equalTo(OK)
contentType(home) must beSome.which(_ == "text/html")
contentAsString(home) must contain ("Your new application is ready.")
}
}
}
24 changes: 24 additions & 0 deletions test/IntegrationSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._

import play.api.test._
import play.api.test.Helpers._

/**
* add your integration spec here.
* An integration test will fire up a whole play application in a real (or headless) browser
*/
@RunWith(classOf[JUnitRunner])
class IntegrationSpec extends Specification {

"Application" should {

"work from within a browser" in new WithBrowser {

browser.goTo("http://localhost:" + port)

browser.pageSource must contain("Your new application is ready.")
}
}
}

0 comments on commit 7340c6e

Please sign in to comment.