GithubHelp home page GithubHelp logo

gawkermedia / play2-closure Goto Github PK

View Code? Open in Web Editor NEW
10.0 71.0 0.0 203 KB

Google Closure Templates for the Play! Framework

License: BSD 3-Clause "New" or "Revised" License

Scala 91.09% JavaScript 2.68% Closure Templates 6.22%

play2-closure's Introduction

Play! 2.4.x plugin for Google Closure Templates

This plugin is designed for using Google Closure Templates with Play! 2.4.x

Installation

  1. Clone the repository

  2. Go into play2-closure directory and execute sbt publishLocal

  3. Add the plugin to your application as a dependency:

    libraryDependencies += "com.kinja.play" %% "play2-closure" % "1.0-2.4.11-SNAPSHOT"
  4. Enable the plugin in conf/play.plugins:

    1600:com.kinja.play.plugins.ClosurePlugin
    
  5. Configure the build number in conf/application.conf:

    buildNumber="1"
    
  6. Create at least one soy template file in app/views/closure.

Usage

Rendering templates

The plugins supports Scala data structures for Google Closure Templates which is the preferred way of passing data to the plugin for rendering.

Rendering a template is as simple as calling Closure.render with the template name and the data to be passed.

import com.kinja.play.plugins.Closure
import com.kinja.soy._

val rendered: String = Closure.render("com.example.index.soy", Soy.map("hello" -> "world"))

The template files should be placed in app/views/closure in dev mode and test/views/closure for tests.

Packaging the template files with the application

Template files are not automatically packaged into the output JAR, you need to map them manually. You can achieve this with the mappings SBT setting:

mappings in (Compile, packageBin) ++= {
  val app = baseDirectory.value / "app"
  ((app / "views" / "closure") ** "*.soy").get pair rebase(app, "app")
}

For alternative ways to provide the plugin with the template files (for example when deploying the templates separately from app), see the Templates in production section below.

Setting the locale

Closure.html("com.example.index", Soy.map(
  "locale" -> "hu_HU", // ISO language code: four letter with underscore
  "hello" -> "world"))

The dictionary file pattern is app/locales/{$locale}.xlf

Templates in production

Normally, templates are loaded from the packaged application. However, the plugin allows hot swapping the templates without restarting the Play application. This is useful to do quick template-only deploys. For this, in production mode templates are attempted to be loaded from the following directory: {assetPath}/{buildNumber}/closure. If this directory does not exists, templates are loaded from the application package. assetPath and buildNumber can be set in Play configuration as keys closureplugin.assetPath and buildNumber respectively.

The recommended setup for hot-swapping is as follows:

Add this to conf/application-live.conf:

include "build-number.conf"
closureplugin.assetPath = "/path/to/hotswappable/assets/on/the/production/server"

The file conf/build-number.conf file should be added by the continuous integration tool (e.g. Jenkins) you use before packaging the application to include the current build number of the application.

buildNumber = "8874"

Create an API call which can be used to bump the build number. Be careful not to make this publicly available, the best would be to check the client IP and only allow localhost. The controller method should call Closure.setVersion to tell the plugin where to read templates from. You should probably want to bump it elsewhere (like in a global var) if you use it elsewhere in your application.

import play.api.mvc._
import com.kinja.play.plugins.Closure

object HotSwapController extends Controller {
	
	def hotswap(buildNumber: String) = Action {
		// implement security here!
		Closure.setVersion(buildNumber)
	}
}

The hot-swapping can now be implemented as a separate build job, which copies the templates to your productions servers in the appropriate directory under a new build number and then calls the hotswap API call to set the new build number on all production servers.

Plugins

This plugin supports Closure Template plugins. Play2-closure takes a list of classpaths in closureplugin.plugins. For example, to add the XliffMsgPlugin, you should add this to your application.conf:

closureplugin.plugins = ["com.google.template.soy.xliffmsgplugin.XliffMsgPlugin"]

play2-closure's People

Contributors

kalmiz avatar balagez avatar jeremychase avatar claireneveu avatar privateblue avatar ph2734 avatar

Stargazers

Kyle Shlansker avatar Angus H. avatar SwhGo_oN avatar Takashi Hamada avatar Akihiro Ikezoe avatar Josh Laurito avatar Nicolas Markovic avatar Péter Geszten-Kovács avatar Soheil Hassas Yeganeh avatar Alexis Georges avatar

Watchers

Dustin Anderson avatar Robin Ting avatar  avatar Patrick avatar Gáspár Körtesi avatar Thomas Plunkett avatar Ben Regenspan avatar matiwinnetou avatar Chris Sprehe avatar Michael Butkovic avatar Ashton G. avatar David Judik avatar jvivs avatar Ramesh Kumar avatar James Cloos avatar Sam Scherer avatar  avatar Brandon Comerford avatar  avatar  avatar ber avatar Jamie Levinson avatar Nehéz-Posony Ferenc avatar highmtn avatar Eric Mittelhammer avatar Oleg Dyachenko avatar Gawker Operations Team Bot avatar Lyle Arnot avatar Ganda avatar Alexandre Thomas avatar gergely avatar  avatar Kyle Lucovsky avatar Adam Homolya avatar Margaret Taormina avatar Janos Hegymegi avatar Dima avatar Ihab Rimawi avatar Justin avatar Tibor Botos avatar Kún Ákos avatar Samuel Centurion avatar Kelly Monson avatar Ferenc Tóth avatar  avatar Jennifer Bruno avatar Mylo28 avatar  avatar Cameron Lowe avatar Kelly Bishop avatar Iván Campaña avatar  avatar  avatar Jessica avatar  avatar  avatar Giannella Paredes avatar Nick Eckhart avatar Ben Kim avatar Melissa Patterson avatar  avatar  avatar Anton avatar Levente Molnar avatar  avatar Grace Robertson avatar Michelle avatar Tyler Alicea avatar  avatar Brian Ferch avatar  avatar

play2-closure's Issues

Error while doing a local sbt publish-local

[warn] http://repo1.maven.org/maven2/com/kinja/sbt/sbt-closure-templates_2.9.2_0.12/0.3-SNAPSHOT/sbt-closure-templates-0.3-SNAPSHOT.pom
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.kinja.sbt#sbt-closure-templates;0.3-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.kinja.sbt:sbt-closure-templates:0.3-SNAPSHOT (sbtVersion=0.12, scalaVersion=2.9.2)
[warn]
sbt.ResolveException: unresolved dependency: com.kinja.sbt#sbt-closure-templates;0.3-SNAPSHOT: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:214)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:102)

Support Bean -> SoyData conversion

i am a creator of a spring-soy-view library and it in my library I also provided support for Bean to SoyData conversion.

The rationale is that most clients will not want to work with SoyData objects but instead they will have their cases classes or some other "bean" classes that they will want to convert to SoyData.

It would be good if the library supported this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.