Wednesday, September 28, 2016

play-handlebars was published

I published play-handlebars module into the sonatype repository. It could be freely included into the project now. Maven:
libraryDependencies += "com.github.andriykuba" % "play-handlebars" % "2.5.1" 

Monday, September 26, 2016

Handlebars module for Play Framework

I wrap up all my "handlebars around" code in the module play-handlebars. You can use it as easy as
public class HomeController extends Controller { 

    private HandlebarsApi handlebarsApi;

    public Result index() {
        // Data. 
        final Map data = new HashMap<>();
        data.put("title", "Page Title");
        data.put("header", "Header");
        data.put("main", ImmutableMap.of("article", "Main Article"));
        data.put("footer", "Footer");

        // Fill it with the data.
        final Content page = handlebarsApi.html("page", data, Context.current().lang().code());

        // Return the page to the client. 
        return ok(page);
class HomeController @Inject() (val handlebarsApi: HandlebarsApi)extends Controller with HandlebarsSupport{
  def index = Action { implicit request =>{
    val jsonData = 
      Json.obj("users" -> Json.arr(
          "name" -> "Jhon",
          "age" -> 4,
          "role" -> "Worker"
          "name" -> "Duck",
          "age" -> 6,
          "role" -> "Administrator"
    val page = render("page", jsonData)