Skip to content

Instantly share code, notes, and snippets.

@evanxg852000
Created December 24, 2018 10:45
Show Gist options
  • Save evanxg852000/bdd199c18f88e9a6c7f848057b89cdd3 to your computer and use it in GitHub Desktop.
Save evanxg852000/bdd199c18f88e9a6c7f848057b89cdd3 to your computer and use it in GitHub Desktop.
class Templater {
...
render(file, context){
let sourceFile = path.join(this._dir, file)
let compiledFile = this._compiledFile(file)
if(!fs.existsSync(sourceFile)){
throw Error('Template not found!')
}
let render = null
//checks if compiled file exist
if(this._cached && fs.existsSync(compiledFile)){
render = require(compiledFile)
return render(context)
}
let ast = this.compile(file)
this._saveGenCode(file, this.generate(ast))
render = require(compiledFile)
return render(context)
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment