test.js 640 B

1234567891011121314151617181920212223242526272829
  1. /*jshint node: true*/
  2. var fs = require("fs");
  3. var assert = require("assert");
  4. var hbsfy = require("hbsfy");
  5. var Handlebars = require("hbsfy/runtime");
  6. Handlebars.registerHelper("upcase", function(s) {
  7. return s.toUpperCase();
  8. });
  9. var templatePath = __dirname + "/hello.hbs";
  10. var exported = __dirname + "/compiled.js";
  11. try {
  12. fs.unlinkSync(exported);
  13. } catch (err) { }
  14. fs.createReadStream(templatePath)
  15. .pipe(hbsfy(templatePath))
  16. .pipe(fs.createWriteStream(exported))
  17. .on("close", function() {
  18. var template = require(exported);
  19. var res = template({ msg: "hi!" });
  20. assert.equal(res, "<h1>HI!</h1>\n");
  21. console.log("ok");
  22. });