简体   繁体   English

japid42模板引擎-更改默认的japid根视图目录

[英]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: 如果使用Play2,和示例应用程序japid42 ,你会看到,它拥有在以下默认结构japid的观点:

{your_app}/japidroot/japidview

How to change it to: {your_app}/app/views ? 如何将其更改为: {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. 此配置告诉japid,“ app”文件夹是japid脚本所在的根目录,然后尝试查找/查找“ japidviews”文件夹。

So, what I need to do: 因此,我需要做的是:

  1. create my rapid templates (html files) in app/rapidviews 在app / rapidviews中创建我的快速模板(html文件)
  2. let japd knows where this 'rapidviews' is located, using setTemplateRoot(..) method 使用setTemplateRoot(..)方法让japd知道此“ rapidviews”的位置

It is OK to me to have "japidviews" but but "views". 我可以拥有“ japidviews”,但可以拥有“ views”。 At least it is in "app" directory but not outside. 至少它在“ app”目录中,但不在外部。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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