Skip to content

Commit

Permalink
upgrading to play 2.5, changed to auto-plugin, fixes #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiti committed Apr 10, 2016
1 parent 9bccb84 commit c7b7349
Show file tree
Hide file tree
Showing 109 changed files with 212 additions and 8,784 deletions.
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The play-compatible-version depends on the version of Playframework being used,
| 2.2.x | 0.6.4 | 2.10 |
| 2.3.x | 0.7.1 | 2.10, 2.11 |
| 2.4.x | 0.8.1 (support for injected routes generator) | 2.11 |
| 2.5.x | 0.9.0 | 2.11 |


3) Import Yeoman classes in the project build adding the following import to `project/Build.scala`,
Expand Down Expand Up @@ -84,6 +85,17 @@ Using >= 0.7.1

```

Using >= 0.9.0 (auto-plugin)

```scala
val appSettings = Seq(version := appVersion, libraryDependencies ++= appDependencies) ++
Yeoman.yeomanSettings

val main = Project(appName, file(".")).enablePlugins(play.PlayScala,Yeoman).settings(
// Add your own project settings here
appSettings: _*
)
```

Note: If you're using build.sbt instead of the full scala build, you need to place the 2 additions above into `build.sbt` as follows:

Expand Down Expand Up @@ -123,6 +135,12 @@ lazy val root = (project in file(".")).enablePlugins(PlayScala)
Yeoman.yeomanSettings ++ Yeoman.withTemplates
```

Using >= 0.9.0 (auto-plugin)

```scala
lazy val root = (project in file(".")).enablePlugins(PlayScala,Yeoman)
```

5) Add yeoman routes to the project, appending the following line in conf/routes files,

```
Expand All @@ -142,8 +160,8 @@ GET / com.tuplejump.playYeoman.Yeoman.redirectRoot(base="/ui/")
```

If using, Play's injected routes generator, prefixing the route with `@` will work except for `yeoman.Routes`. It can be used as is.

Note: If using 0.8.1 and Play's injected routes generator, prefixing the route with `@` will work except for `yeoman.Routes`. It can be used as is.
This is specific to version 0.8.1. From version 0.9.0, `InjectedRoutesGenerator` is default.

6) Start play/sbt in your project folder,

Expand Down Expand Up @@ -250,18 +268,27 @@ Using >= 0.7.1
```

Using >= 0.9.0

```
lazy val root = (project in file(".")).enablePlugins(PlayScala,Yeoman)
Yeoman.withTemplates
```

* Once that is done play will compile the templates from yeoman directory too, and you can use them in your controllers. This helps you keep all your UI files together under the yeoman directory ('ui' by default)

* Look at the yo-demo and yo-injection-demo projects for details!
* Look at the yo-demo!

Note: Starting from 0.7.1, play-yeoman supports compilation of views from the yeoman directory but cannot recompile them when they are modified with the server running. You will need to stop the server and start it again.
For versions 0.7.1 to 0.8.1, you need to run `grunt` prior to compile else the template code will not be generated. This is not required if you execute `dist` or `stage` directly since they have a dependency on grunt.

* If you use scala template support, you need to run grunt prior to compile else the template code will not be generated. This is not required if you execute run or stage directly since they have a dependency on grunt.
From 0.9.0 onwards, the views in yeoman directory are automatically compiled to generate template code.

### Taking it to production

From 0.6.3, play-yeoman updates Play's 'stage' and 'dist' tasks to depend on the grunt task. Thus you don't need any additional step putting this in production. when you run either `sbt dist` or `sbt stage` it will automatically run grunt as part of the build!

From 0.9.0, a boolean key `runGruntInDist` has been provided for helping with Heroku. It can be set to `false` and the yeoman distDirectory should be copied manually.

### Configuring the yeoman directory paths for Play

Expand Down
51 changes: 23 additions & 28 deletions play-yeoman/app/com/tuplejump/playYeoman/Yeoman.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.tuplejump.playYeoman

import java.io.File
import javax.inject.Inject

import controllers.Assets
import play.api._
import play.api.mvc._
import controllers.Assets
import play.api.Play.current
import java.io.File
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

import scala.collection.JavaConverters._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

object Yeoman extends Controller {
class Yeoman @Inject() (environment: play.api.Environment,
devAssets: DevAssets) extends Controller {

def at(file: String): Action[AnyContent] = atHandler(file)

def index = Action.async {
request =>
Expand All @@ -20,6 +25,9 @@ object Yeoman extends Controller {
}
}

def assetHandler(file: String): Action[AnyContent] = {
Assets.at("/public", file)
}

def redirectRoot(base: String = "/ui/") = Action {
request =>
Expand All @@ -30,34 +38,21 @@ object Yeoman extends Controller {
}
}

def assetHandler(file: String): Action[AnyContent] = {
Assets.at("/public", file)
}

lazy val atHandler: String => Action[AnyContent] = if (Play.isProd) assetHandler(_: String) else DevAssets.assetHandler(_: String)

def at(file: String): Action[AnyContent] = atHandler(file)


}

/**
* Class added to support injected route generator (Play 2.4 onwards)
*/
class Yeoman extends Controller {
def index = Yeoman.index
lazy val atHandler: String => Action[AnyContent] = if (environment.mode==Mode.Prod) {
assetHandler(_: String)
} else devAssets.assetHandler(_: String)

def redirectRoot(base: String = "/ui/") = Yeoman.redirectRoot(base)
}

object DevAssets extends Controller {
class DevAssets @Inject() (environment: play.api.Environment,
configuration: play.api.Configuration) extends Controller {
// paths to the grunt compile directory or else the application directory, in order of importance
val runtimeDirs = Play.configuration.getStringList("yeoman.devDirs")
val runtimeDirs = configuration.getStringList("yeoman.devDirs")
val basePaths: List[java.io.File] = runtimeDirs match {
case Some(dirs) => dirs.asScala.map(Play.application.getFile _).toList
case None => List(Play.application.getFile("ui/.tmp"), Play.application.getFile("ui/app"),
case Some(dirs) => dirs.asScala.map(environment.getFile _).toList
case None => List(environment.getFile("ui/.tmp"), environment.getFile("ui/app"),
//added ui to defaults since the newer projects have bower_components in ui directory instead of ui/app/components
Play.application.getFile("ui"))
environment.getFile("ui"))
}

/**
Expand Down
43 changes: 43 additions & 0 deletions play-yeoman/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
val appName = "play-yeoman"
val appVersion = "0.9.0"

val main = Project(appName, file(".")).enablePlugins(PlayScala).settings(
version := appVersion,
scalaVersion in Global := "2.11.7",
// crossScalaVersions := Seq("2.11.7"),
homepage := Some(url("https://github.com/tuplejump/play-yeoman")),
organization := "com.tuplejump",
organizationName := "Tuplejump Software Pvt. Ltd.",
organizationHomepage := Some(new java.net.URL("http://www.tuplejump.com")),
licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
publishMavenStyle := true,
publishTo <<= version {
(v: String) =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
publishArtifact in Test := false,
pomIncludeRepository := {
_ => false
},
pomExtra := (
<scm>
<url>git@github.com:tuplejump/play-yeoman.git</url>
<connection>scm:git:git@github.com:tuplejump/play-yeoman.git</connection>
</scm>
<developers>
<developer>
<id>eraoferrors</id>
<name>Shiti Saxena</name>
<url>https://twitter.com/eraoferrors</url>
</developer>
<developer>
<id>milliondreams</id>
<name>Rohit Rai</name>
<url>https://twitter.com/milliondreams</url>
</developer>
</developers>)
)
58 changes: 0 additions & 58 deletions play-yeoman/project/Build.scala

This file was deleted.

2 changes: 1 addition & 1 deletion play-yeoman/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.8
sbt.version=0.13.11
2 changes: 1 addition & 1 deletion play-yeoman/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ logLevel := Level.Warn
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.4.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.0")

Loading

0 comments on commit c7b7349

Please sign in to comment.