view.js 673 B

123456789101112131415161718192021222324252627282930
  1. var View = function(src,params){
  2. if(!src) return null;
  3. this.html = '';
  4. this.params = params?params:{};
  5. let viewPath = src;
  6. if(!src.match(Core.Path.View)){
  7. viewPath = Core.Path.View + '/' + src + '.html';
  8. }
  9. try{
  10. FILE.statSync(viewPath);
  11. }catch(e){
  12. LOGGER.error('No such view template ['+src+']');
  13. return null;
  14. }
  15. try{
  16. var data = FILE.readFileSync(viewPath,'UTF-8');
  17. this.html = EJS.render(data,this.params);
  18. }catch(e){
  19. LOGGER.error('View template render error ['+src+']');
  20. LOGGER.error(e);
  21. return null;
  22. }
  23. return this;
  24. }
  25. module.exports = View;