/play-yeoman

Play + Yeoman integration sbt and play plugins

Primary LanguageScalaApache License 2.0Apache-2.0

play-yeoman

play-yeoman is a sbt+play plugin that brings the streamlined frontend development workflow and optimized build system of yeoman to Play 2.0.

In this approach, you would use play for developing the application backend/services and develop the frontend/ui using the yeoman toolchain, all in a totally integrated workflow and single unified console.

Play + Yeoman integration sbt and play plugins. Inspired and copied to quite some extent from, https://github.com/leon/play-grunt-angular-prototype

Support

If you face any issues using this plugin, please feel free to report to | opensource [at] tuplejump [dot] com | or shout out at twitter mentioning @tuplejump or @milliondreams. You can also create a issue in the github issue tracker.

If you found a bug and fixed it, please do raise a pull request, all users will appreciate that.

If you want some new feature to be implemented, please mail us.

How to use it?

Prerequisites

Let's get started,

  1. Create a new play project or open an existing play project

  2. Add the yeoman sbt plugin to the project. Edit project/plugins.sbt to add the following line,

addSbtPlugin("com.tuplejump" % "sbt-yeoman" % "0.6.2")

  1. Import Yeoman classes in the project build adding the following import to project/Build.scala,

import com.tuplejump.sbt.yeoman.Yeoman

  1. In the same file, add the yeoman settings to your Play project like this,
  val main = play.Project(appName, appVersion, appDependencies).settings(
    // Add your own project settings here
    Yeoman.yeomanSettings : _*
  )

  1. Add yeoman routes to the project, appending the following line in conf/routes files,

GET     /ui         com.tuplejump.playYeoman.Yeoman.index

->	    /ui/        yeoman.Routes


Optionally, you can also redirect your root url,


GET     /           com.tuplejump.playYeoman.Yeoman.redirectRoot(base="/ui/")

  1. Start play/sbt in your project folder,
user yo-demo> sbt

  1. Update the project to pull in the new dependencies,
[yo-demo] update

  1. Generate the yeoman application
[yo-demo] yo angular

  1. Edit the Gruntfile.js to disable the Yeoman "connect" server as we will be using play to serve our application, This can be done by commenting out the relevant line in the server task towards the end of the file,
  grunt.registerTask('server', [
    'clean:server',
    'coffee:dist',
    'compass:server',
    'livereload-start',
    //'connect:livereload',	//THIS LINE SHOULD BE COMMENTED or REMOVED
    'open',
    'watch'
  ]);

  1. Run your play application,
[yo-demo] run

  1. Click on the liveReload plugin in the browser to connect and navigate to http://localhost:9000/ui/

Support for Scala Templates

To use Scala templates you have 2 options,

  1. The old way is to create your templates in app/views and create a route for,
    GET /ui/views/{view_name}.html      controllers.Application.{your_action_handler}
  1. Begining, 0.6.3, play-yeoman supports compilation of views from the yeoman directory too.
  • All you have to do to enable it is add Yeoman.withTemplates settings to the app settings, so your play project will now look like this,
  val main = play.Project(appName, appVersion, appDependencies).settings(
    // Add your own project settings here
    (Yeoman.yeomanSettings ++ 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 project for details!

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!

Licence

This software is licensed under the Apache 2 license, quoted below.

Copyright 2013 Tuplejump Software Pvt. Ltd. (http://www.tuplejump.com).

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.