indentation_test.js 732 B

1234567891011121314151617181920212223242526272829303132
  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. var templatePath = __dirname + "/indentation.hbs";
  7. var exported = __dirname + "/compiled.js";
  8. try {
  9. fs.unlinkSync(exported);
  10. } catch (err) { }
  11. fs.createReadStream(templatePath)
  12. .pipe(hbsfy(templatePath, {
  13. processContent: function(content) {
  14. return content
  15. .replace(/^[\x20\t]+/mg, '')
  16. .replace(/[\x20\t]+$/mg, '')
  17. .replace(/[\r\n]/g, '');
  18. }
  19. }))
  20. .pipe(fs.createWriteStream(exported))
  21. .on("close", function() {
  22. var template = require(exported);
  23. var res = template({ name: "Bob" });
  24. assert.equal(res, "<header><h1>Hi Bob!</h1></header>");
  25. });