简体   繁体   中英

japid42 template engine - changing default japid root views direcotiry

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)

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.

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);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM