{"size": 1616, "ext": "js", "max_stars_repo_path": "src/easynode/framework/mvc/SwigTemplateViewRenderer.js", "max_stars_repo_name": "nhipster/easynode", "max_stars_repo_stars_event_min_datetime": "2016-07-07T18:21:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-03-16T07:11:05.000Z", "max_issues_repo_path": "src/easynode/framework/mvc/SwigTemplateViewRenderer.js", "max_issues_repo_name": "nhipster/easynode", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/easynode/framework/mvc/SwigTemplateViewRenderer.js", "max_forks_repo_name": "nhipster/easynode", "max_forks_repo_forks_event_min_datetime": "2016-11-23T02:29:58.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-24T16:10:26.000Z"}
{"max_stars_count": 22, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 26.9333333333, "max_line_length": 124, "alphanum_fraction": 0.5785891089}
var assert = require('assert');
var logger = using('easynode.framework.Logger').forFile(__filename);
var ITemplateViewRenderer = using('easynode.framework.mvc.ITemplateViewRenderer');
var swig = require('swig');
var StringUtil = using('easynode.framework.util.StringUtil');
var _ = require('underscore');

(function() {

  const SWITCH_CACHE = StringUtil.switchState(EasyNode.config('easynode.framework.mvc.view.template.enableCache', 'false'));

        /**
         * Class SwigTemplateViewRenderer，用于渲染swig模板引擎的View
         *
         * @class easynode.framework.mvc.SwigTemplateViewRenderer
         * @extends easynode.framework.mvc.ITemplateViewRenderer
         * @since 0.1.0
         * @author hujiabao
         * */
  class SwigTemplateViewRenderer extends ITemplateViewRenderer {

                /**
                 * 构造函数。
                 *
                 * @method 构造函数
                 * @since 0.1.0
                 * @author hujiabao
                 * */
    constructor() {
      super();
                        // 调用super()后再定义子类成员。
    }

    getCache() {
      if (!SWITCH_CACHE) {
        return false;
      }
      else {
        return 'memory';
      }
    }

    render(actionResult, template) {
      var data = actionResult.toJSON();
      var templateRender = swig.compileFile(template, {cache : this.getCache()});
      return templateRender(data.result);
    }

    _injectHelperFunctions(o) {
                        // TODO 支持格式转换函数
    }

    getClassName() {
      return EasyNode.namespace(__filename);
    }
        }

  module.exports = SwigTemplateViewRenderer;
})();
