japid42 template engine - changing default japid root views direcotiry

189 views Asked by At

If use Play2, and sample application of japid42, you will see that it holds japid's view under the following default structure:

{your_app}/japidroot/japidview

How to change it to: {your_app}/app/views ? (to standard/classic play's structure)

2

There are 2 answers

0
SeanSnow On
import play.Play;
import play.mvc.Http.RequestHeader;
import play.mvc.Result;
import play.mvc.Results;
import cn.bran.japid.template.JapidRenderer;
import cn.bran.play.JapidController;

public class Global extends JapidRenderer {
  @Override
  public void onStartJapid() {
    setTemplateRoot("japidroot");
    setLogVerbose(true);
    setKeepJavaFiles(false); // keep the Java code derived from Japid scripts in memory only
  }

  @Override
  public Result onError(RequestHeader h, Throwable t) {
    if (Play.application().isProd())
      return Results.internalServerError(JapidController.renderJapidWith("onError.html", h, t));
    else
      return super.onError(h, t);
  }

  @Override
  public Result onBadRequest(RequestHeader r, String s) {
    if (Play.application().isProd())
      return Results.badRequest(JapidController.renderJapidWith("onBadRequest.html", r, s));
    else
      return super.onBadRequest(r, s);
  }

  @Override
  public Result onHandlerNotFound(RequestHeader r) {
    // usually one needs to use a customized error reporting in production.
    //
    if (Play.application().isProd() || Play.application().isDev())
      return Results.notFound(JapidController.renderJapidWith("onHandlerNotFound.html", r));
    else
      return super.onHandlerNotFound(r);
  }
}
0
ses On

Ok. I've figured this out.

public class Global extends JapidRenderer {
    @Override
    public void onStartJapid() {
        setTemplateRoot("app");
...

This configuration says japid that "app" folder is root where japid scripts located, then it tries to find/look-up for 'japidviews' folder.

So, what I need to do:

  1. create my rapid templates (html files) in app/rapidviews
  2. let japd knows where this 'rapidviews' is located, using setTemplateRoot(..) method

It is OK to me to have "japidviews" but but "views". At least it is in "app" directory but not outside.