Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

use the Japid template engine with Play to get 25X more performance #1

Merged
merged 1 commit into from

2 participants

@branaway

added japid port to the playapp. use localhost:9000/product/indexj to access it.

Japid port is about 25X faster than the plain Play app.

@branaway

please run "play dependencies" to install the japid module

@branaway

The port is in the same playapp. The access point is localhost:9000/products/indexj

@jtdev jtdev merged commit 16ccd5e into from
@jtdev
Owner

Thanks branaway, Japid seems to be very fast indeed!
I'm going to update the blogpost with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 31, 2011
  1. @branaway
This page is out of date. Refresh to see the latest.
View
16 playapp/app/controllers/Products.java
@@ -5,15 +5,21 @@
import java.util.*;
+import cn.bran.play.JapidController;
+
import models.*;
import s.*;
-public class Products extends Controller {
- public static void index() {
+public class Products extends JapidController {
+ public static void index() {
List<Product> products = Service.getProducts();
- render(products);
- }
-
+ render(products);
+ }
+
+ public static void indexj() {
+ List<Product> products = Service.getProducts();
+ renderJapid(products);
+ }
public static void env() {
renderText(play.Play.configuration.get("application.mode"));
}
View
17 playapp/app/japidviews/Products/indexj.html
@@ -0,0 +1,17 @@
+`import s.*
+`args List<Product> products
+`extends main
+`set title:"Product listing"
+`set pagename: "Product listing"
+`trim on
+<table>
+ `for (Product product:products) {
+ <tr>
+ <td>`t ProductDetail(product)`</td>
+ <td>
+ `for(Category category: product.getCategories()){` ${category.getName()}, `}
+ </td>
+ </tr>
+ `}
+</table>
+
View
105 playapp/app/japidviews/Products/indexj.java
@@ -0,0 +1,105 @@
+package japidviews.Products;
+
+import java.util.*;
+import java.io.*;
+import cn.bran.japid.tags.Each;
+import s.*;
+import static play.templates.JavaExtensions.*;
+import static cn.bran.play.JapidPlayAdapter.*;
+import static play.data.validation.Validation.*;
+import japidviews._layouts.*;
+import static japidviews._javatags.JapidWebUtil.*;
+import play.data.validation.Validation;
+import play.mvc.Scope.*;
+import models.*;
+import play.data.validation.Error;
+import japidviews._tags.*;
+import controllers.*;
+import play.mvc.Http.*;
+import japidviews._javatags.*;
+//
+// NOTE: This file was generated from: japidviews/Products/indexj.html
+// Change to this file will be lost next time the template file is compiled.
+//
+
+public class indexj extends main {
+ public static final String sourceTemplate = "japidviews/Products/indexj.html";
+ {
+ headers.put("Content-Type", "text/html; charset=utf-8");
+ }
+
+ // - add implicit fields with Play
+
+ final Request request = Request.current();
+ final Response response = Response.current();
+ final Session session = Session.current();
+ final RenderArgs renderArgs = RenderArgs.current();
+ final Params params = Params.current();
+ final Validation validation = Validation.current();
+ final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(
+ validation);
+ final play.Play _play = new play.Play();
+
+ // - end of implicit fields with Play
+
+ // -- set up the tag objects
+ final ProductDetail _ProductDetail2 = new ProductDetail(getOut());
+ {
+ _ProductDetail2.setActionRunners(getActionRunners());
+ }
+
+ // -- end of the tag objects
+
+ public indexj() {
+ super(null);
+ }
+
+ public indexj(StringBuilder out) {
+ super(out);
+ }
+
+ private List<Product> products;
+
+ public cn.bran.japid.template.RenderResult render(List<Product> products) {
+ this.products = products;
+ long t = -1;
+ super.layout();
+ return new cn.bran.japid.template.RenderResultPartial(this.headers,
+ getOut(), t, actionRunners);
+ }
+
+ @Override
+ protected void doLayout() {
+ //------
+ p("<table>");
+ for (Product product : products) {
+ p("<tr>\n" +
+ " <td>");
+ _ProductDetail2.setOut(getOut());
+ _ProductDetail2.render(product);
+
+ p("</td>\n" +
+ " <td>");
+ for (Category category : product.getCategories()) {
+ p(category.getName());
+ p(",");
+ }
+ p("</td>\n" +
+ " </tr>");
+ }
+ p("</table>");
+
+ }
+
+ @Override
+ protected void title() {
+ p("Product listing");
+ ;
+ }
+
+ @Override
+ protected void pagename() {
+ p("Product listing");
+ ;
+ }
+}
View
17 playapp/app/japidviews/_javatags/JapidWebUtil.java
@@ -0,0 +1,17 @@
+package japidviews._javatags;
+
+/**
+ * a well-know place to add all the static method you want to use in your
+ * templates.
+ *
+ * All the public static methods will be automatically "import static " to the
+ * generated Java classes by the Japid compiler.
+ *
+ */
+public class JapidWebUtil {
+ public static String hi() {
+ return "Hi";
+ }
+ // your utility methods...
+
+}
View
7 playapp/app/japidviews/_layouts/SampleLayout.html
@@ -0,0 +1,7 @@
+A sample layout generated by the Japid Eclipse plugin. Will be auto-regenerated.
+<p>
+#{get 'title'/};
+</p>
+<div>
+#{doLayout /}
+</div>
View
70 playapp/app/japidviews/_layouts/SampleLayout.java
@@ -0,0 +1,70 @@
+package japidviews._layouts;
+
+import java.util.*;
+import java.io.*;
+import cn.bran.japid.tags.Each;
+import static play.templates.JavaExtensions.*;
+import static cn.bran.play.JapidPlayAdapter.*;
+import static play.data.validation.Validation.*;
+import japidviews._layouts.*;
+import static japidviews._javatags.JapidWebUtil.*;
+import play.data.validation.Validation;
+import play.mvc.Scope.*;
+import models.*;
+import play.data.validation.Error;
+import japidviews._tags.*;
+import controllers.*;
+import play.mvc.Http.*;
+import japidviews._javatags.*;
+//
+// NOTE: This file was generated from: japidviews/_layouts/SampleLayout.html
+// Change to this file will be lost next time the template file is compiled.
+//
+
+public abstract class SampleLayout extends
+ cn.bran.japid.template.JapidTemplateBase {
+ public static final String sourceTemplate = "japidviews/_layouts/SampleLayout.html";
+ {
+ headers.put("Content-Type", "text/html; charset=utf-8");
+ }
+
+ // - add implicit fields with Play
+
+ final Request request = Request.current();
+ final Response response = Response.current();
+ final Session session = Session.current();
+ final RenderArgs renderArgs = RenderArgs.current();
+ final Params params = Params.current();
+ final Validation validation = Validation.current();
+ final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(
+ validation);
+ final play.Play _play = new play.Play();
+
+ // - end of implicit fields with Play
+
+ public SampleLayout() {
+ super(null);
+ }
+
+ public SampleLayout(StringBuilder out) {
+ super(out);
+ }
+
+ @Override
+ public void layout() {
+ p("A sample layout generated by the Japid Eclipse plugin. Will be auto-regenerated.\n"
+ +
+ "<p>\n");// line 1
+ title();// line 3
+ p(";\n" +
+ "</p>\n" +
+ "<div>\n");// line 3
+ doLayout();// line 6
+ p("</div>\n");// line 6
+ }
+
+ protected void title() {
+ };
+
+ protected abstract void doLayout();
+}
View
40 playapp/app/japidviews/_layouts/main.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+
+ <title>#{get 'title' /}</title>
+
+ <link rel="stylesheet" media="screen" href="@{'/public/default.css'}">
+ #{get 'moreStyles' /}
+ <link rel="shortcut icon" type="image/png" href="@{'/public/images/favicon.png'}">
+ #{get 'moreScripts' /}
+ </head>
+
+ <body>
+ <div id="maincontainer">
+ <div id="topsection">
+ <div class="innertube"><h1>Company Title .....</h1></div>
+ </div>
+ <div id="contentwrapper">
+ <div id="contentcolumn">
+
+ <!-- Page name needs to be injected -->
+ <div><h2>#{get 'pagename' /}</h2></div>
+ <div class="innertube">
+ #{doLayout /}
+ </div>
+ </div>
+ </div>
+
+ <div id="leftcolumn">
+ <div class="innertube">
+ <h3>Side bar.....</h3>
+ </div>
+ </div>
+
+ <div id="footer">footer.....</div>
+ </div>
+ </body>
+</html>
View
132 playapp/app/japidviews/_layouts/main.java
@@ -0,0 +1,132 @@
+package japidviews._layouts;
+
+import java.util.*;
+import java.io.*;
+import cn.bran.japid.tags.Each;
+import static play.templates.JavaExtensions.*;
+import static cn.bran.play.JapidPlayAdapter.*;
+import static play.data.validation.Validation.*;
+import japidviews._layouts.*;
+import static japidviews._javatags.JapidWebUtil.*;
+import play.data.validation.Validation;
+import play.mvc.Scope.*;
+import models.*;
+import play.data.validation.Error;
+import japidviews._tags.*;
+import controllers.*;
+import play.mvc.Http.*;
+import japidviews._javatags.*;
+//
+// NOTE: This file was generated from: japidviews/_layouts/main.html
+// Change to this file will be lost next time the template file is compiled.
+//
+
+public abstract class main extends cn.bran.japid.template.JapidTemplateBase {
+ public static final String sourceTemplate = "japidviews/_layouts/main.html";
+ {
+ headers.put("Content-Type", "text/html; charset=utf-8");
+ }
+
+ // - add implicit fields with Play
+
+ final Request request = Request.current();
+ final Response response = Response.current();
+ final Session session = Session.current();
+ final RenderArgs renderArgs = RenderArgs.current();
+ final Params params = Params.current();
+ final Validation validation = Validation.current();
+ final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(
+ validation);
+ final play.Play _play = new play.Play();
+
+ // - end of implicit fields with Play
+
+ public main() {
+ super(null);
+ }
+
+ public main(StringBuilder out) {
+ super(out);
+ }
+
+ @Override
+ public void layout() {
+ p("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
+ +
+ "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
+ +
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n"
+ +
+ " <head>\n"
+ +
+ " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n"
+ +
+ " \n" +
+ " <title>");// line 1
+ title();// line 7
+ p("</title>\n" +
+ "\n" +
+ " <link rel=\"stylesheet\" media=\"screen\" href=\"");// line 7
+ p(lookupStatic("/public/default.css"));// line 9
+ p("\">\n" +
+ " ");// line 9
+ moreStyles();// line 10
+ p(" <link rel=\"shortcut icon\" type=\"image/png\" href=\"");// line 10
+ p(lookupStatic("/public/images/favicon.png"));// line 11
+ p("\">\n" +
+ " ");// line 11
+ moreScripts();// line 12
+ p(" </head>\n"
+ +
+ " \n"
+ +
+ " <body>\n"
+ +
+ " <div id=\"maincontainer\">\n"
+ +
+ " <div id=\"topsection\">\n"
+ +
+ " <div class=\"innertube\"><h1>Company Title .....</h1></div>\n"
+ +
+ " </div>\n" +
+ " <div id=\"contentwrapper\">\n" +
+ " <div id=\"contentcolumn\">\n" +
+ " \n" +
+ " <!-- Page name needs to be injected -->\n"
+ +
+ " <div><h2>");// line 12
+ pagename();// line 24
+ p("</h2></div>\n" +
+ " <div class=\"innertube\"> \n" +
+ " ");// line 24
+ doLayout();// line 26
+ p(" </div>\n" +
+ " </div>\n" +
+ " </div>\n" +
+ "\n" +
+ " <div id=\"leftcolumn\">\n" +
+ " <div class=\"innertube\">\n" +
+ " <h3>Side bar.....</h3>\n" +
+ " </div>\n" +
+ " </div>\n" +
+ "\n" +
+ " <div id=\"footer\">footer.....</div>\n" +
+ " </div>\n" +
+ " </body>\n" +
+ "</html>\n");// line 26
+ }
+
+ protected void moreStyles() {
+ };
+
+ protected void title() {
+ };
+
+ protected void pagename() {
+ };
+
+ protected void moreScripts() {
+ };
+
+ protected abstract void doLayout();
+}
View
7 playapp/app/japidviews/_tags/ProductDetail.html
@@ -0,0 +1,7 @@
+`import s.*
+`args Product product
+`trim off
+<div class="product">
+ <img src="${product.getName()}.jpg" />
+ <span class="productname">${product.getName()}</span>, <span class="price">$${product.getPrice()}</span>
+</div>
View
79 playapp/app/japidviews/_tags/ProductDetail.java
@@ -0,0 +1,79 @@
+package japidviews._tags;
+
+import java.util.*;
+import java.io.*;
+import cn.bran.japid.tags.Each;
+import s.*;
+import static play.templates.JavaExtensions.*;
+import static cn.bran.play.JapidPlayAdapter.*;
+import static play.data.validation.Validation.*;
+import japidviews._layouts.*;
+import static japidviews._javatags.JapidWebUtil.*;
+import play.data.validation.Validation;
+import play.mvc.Scope.*;
+import models.*;
+import play.data.validation.Error;
+import japidviews._tags.*;
+import controllers.*;
+import play.mvc.Http.*;
+import japidviews._javatags.*;
+//
+// NOTE: This file was generated from: japidviews/_tags/ProductDetail.html
+// Change to this file will be lost next time the template file is compiled.
+//
+
+public class ProductDetail extends cn.bran.japid.template.JapidTemplateBase {
+ public static final String sourceTemplate = "japidviews/_tags/ProductDetail.html";
+ {
+ headers.put("Content-Type", "text/html; charset=utf-8");
+ }
+
+ // - add implicit fields with Play
+
+ final Request request = Request.current();
+ final Response response = Response.current();
+ final Session session = Session.current();
+ final RenderArgs renderArgs = RenderArgs.current();
+ final Params params = Params.current();
+ final Validation validation = Validation.current();
+ final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(
+ validation);
+ final play.Play _play = new play.Play();
+
+ // - end of implicit fields with Play
+
+ public ProductDetail() {
+ super(null);
+ }
+
+ public ProductDetail(StringBuilder out) {
+ super(out);
+ }
+
+ private Product product;
+
+ public cn.bran.japid.template.RenderResult render(Product product) {
+ this.product = product;
+ long t = -1;
+ super.layout();
+ return new cn.bran.japid.template.RenderResultPartial(this.headers,
+ getOut(), t, actionRunners);
+ }
+
+ @Override
+ protected void doLayout() {
+ //------
+ p("<div class=\"product\">\n" +
+ " <img src=\"");// line 3
+ p(product.getName());// line 5
+ p(".jpg\" />\n" +
+ " <span class=\"productname\">");// line 5
+ p(product.getName());// line 6
+ p("</span>, <span class=\"price\">$");// line 6
+ p(product.getPrice());// line 6
+ p("</span>\n" +
+ "</div>\n");// line 6
+
+ }
+
+}
View
2  playapp/app/japidviews/_tags/SampleTag.html
@@ -0,0 +1,2 @@
+` args String a
+Hi $a!
View
71 playapp/app/japidviews/_tags/SampleTag.java
@@ -0,0 +1,71 @@
+package japidviews._tags;
+
+import java.util.*;
+import java.io.*;
+import cn.bran.japid.tags.Each;
+import static play.templates.JavaExtensions.*;
+import static cn.bran.play.JapidPlayAdapter.*;
+import static play.data.validation.Validation.*;
+import japidviews._layouts.*;
+import static japidviews._javatags.JapidWebUtil.*;
+import play.data.validation.Validation;
+import play.mvc.Scope.*;
+import models.*;
+import play.data.validation.Error;
+import japidviews._tags.*;
+import controllers.*;
+import play.mvc.Http.*;
+import japidviews._javatags.*;
+//
+// NOTE: This file was generated from: japidviews/_tags/SampleTag.html
+// Change to this file will be lost next time the template file is compiled.
+//
+
+public class SampleTag extends cn.bran.japid.template.JapidTemplateBase {
+ public static final String sourceTemplate = "japidviews/_tags/SampleTag.html";
+ {
+ headers.put("Content-Type", "text/html; charset=utf-8");
+ }
+
+ // - add implicit fields with Play
+
+ final Request request = Request.current();
+ final Response response = Response.current();
+ final Session session = Session.current();
+ final RenderArgs renderArgs = RenderArgs.current();
+ final Params params = Params.current();
+ final Validation validation = Validation.current();
+ final cn.bran.play.FieldErrors errors = new cn.bran.play.FieldErrors(
+ validation);
+ final play.Play _play = new play.Play();
+
+ // - end of implicit fields with Play
+
+ public SampleTag() {
+ super(null);
+ }
+
+ public SampleTag(StringBuilder out) {
+ super(out);
+ }
+
+ private String a;
+
+ public cn.bran.japid.template.RenderResult render(String a) {
+ this.a = a;
+ long t = -1;
+ super.layout();
+ return new cn.bran.japid.template.RenderResultPartial(this.headers,
+ getOut(), t, actionRunners);
+ }
+
+ @Override
+ protected void doLayout() {
+ //------
+ p("Hi ");// line 1
+ p(a);// line 2
+ p("!\n");// line 2
+
+ }
+
+}
View
1  playapp/conf/dependencies.yml
@@ -2,3 +2,4 @@
require:
- play
+ - play -> japid 0.8.3.1
View
BIN  playapp/lib/commons-codec-1.4.jar
Binary file not shown
View
BIN  playapp/lib/commons-collections-3.2.1.jar
Binary file not shown
View
BIN  playapp/lib/commons-logging-1.1.1.jar
Binary file not shown
View
BIN  playapp/lib/joda-time-1.6.jar
Binary file not shown
View
1  playapp/modules/japid-0.8.3.1
@@ -0,0 +1 @@
+D:\home\bran\projects\play-git\modules\japid-0.8.3.1
Something went wrong with that request. Please try again.