Code coverage report for thinkjs/lib/Lib/Behavior/LocateTemplateBehavior.js

Statements: 100% (15 / 15)      Branches: 100% (14 / 14)      Functions: 100% (2 / 2)      Lines: 100% (15 / 15)      Ignored: none     

All files » thinkjs/lib/Lib/Behavior/ » LocateTemplateBehavior.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41          2   2   19 19   4             15   4 3   11 10 10 10 10 10               19      
/**
 * 定位模版路径
 * @return {[type]} [description]
 */
 
module.exports = Behavior(function(){
  'use strict';
  return {
    run: function(templateFile){
      templateFile = templateFile || '';
      if (!templateFile) {
        //根据group, controller, action自动生成
        templateFile = [
          VIEW_PATH, '/', this.http.group, '/',
          this.http.controller.toLowerCase(),
          C('tpl_file_depr'),
          this.http.action.toLowerCase(),
          C('tpl_file_suffix')
        ].join('');
      }else if(templateFile.indexOf('/') > -1){
        //自动追加VIEW_PATH
        if (templateFile.indexOf('/') !== 0) {
          templateFile = VIEW_PATH + '/' + templateFile;
        }
      }else if(templateFile.indexOf(C('tpl_file_suffix')) === -1){
        var path = templateFile.split(':');
        var action = path.pop();
        var controller = path.pop() || this.http.controller.toLowerCase();
        var group = ucfirst(path.pop() || this.http.group);
        templateFile = [
          VIEW_PATH, '/', group, '/',
          controller, 
          C('tpl_file_depr'),
          action,
          C('tpl_file_suffix')
        ].join('');
      }
      return templateFile;
    }
  };
});