Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

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

Merged
merged 1 commit into from May 31, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions playapp/app/controllers/Products.java
Expand Up @@ -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"));
}
Expand Down
17 changes: 17 additions & 0 deletions 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>

105 changes: 105 additions & 0 deletions 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");
;
}
}
17 changes: 17 additions & 0 deletions 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...

}
7 changes: 7 additions & 0 deletions 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>
70 changes: 70 additions & 0 deletions 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();
}
40 changes: 40 additions & 0 deletions 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>