123456789101112131415161718192021222324252627282930313233343536373839404142 |
- /**
- * @Author HonorLee (dev@honorlee.me)
- * @Version 1.0 (2018-05-04)
- * @License MIT
- */
- 'use strict'
- var View = function(src,params){
- if(!src) return null;
- this.html = '';
- this.params = params?params:{};
- let viewPath = src;
- if(!src.match(Core.Path.View)){
- viewPath = Core.Path.View + '/' + src + '.html';
- }
- try{
- FILE.statSync(viewPath);
- }catch(e){
- viewPath = Core.Path.View + '/' + src;
- try{
- FILE.statSync(viewPath);
- }catch(e){
- LOGGER.error('No such view template ['+src+']');
- return null;
- }
- }
- let content = FILE.readFileSync(viewPath,'UTF-8');
- if(this.params){
- try{
- this.html = EJS.render(content,this.params);
- }catch(e){
- LOGGER.error('View template render error ['+src+']');
- LOGGER.error(e);
- return null;
- }
- }else{
- this.html = content;
- }
- }
- module.exports = View;
|