flexbiz-server
Version:
Flexible Server
4 lines (3 loc) • 1.01 kB
JavaScript
const fs=require("fs"),path=require("path"),pug=require("pug"),moment=require("moment"),numeral=require("numeral");
module.exports=function($template$$,$_data_dir_root$$,$callback$$){const $data$$={...$_data_dir_root$$,...configs};$_data_dir_root$$=configs.paths.template;let $_template$$;$_data_dir_root$$&&($_template$$=$_data_dir_root$$+$template$$.replace(".html",".pug"));$_template$$&&fs.existsSync($_template$$)||($_template$$=path.dirname(__dirname)+"/templates/"+$template$$.replace(".html",".pug"));if(fs.existsSync($_template$$))$data$$.moment=moment,$data$$.numeral=numeral,$callback$$(null,pug.renderFile($_template$$,
$data$$));else{$_template$$=path.dirname(__dirname)+"/templates/"+$template$$;if(!fs.existsSync($_template$$))return $callback$$("Do not find the template file");fs.readFile($template$$,function($error$$,$html$$){if($error$$)return $callback$$($error$$);$html$$=$html$$.toString();$error$$=require("./parse-template").parseTemplate;$error$$($html$$,$data$$,$callback$$)})}};