This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from romanyanke/process-content
add processContent option
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<header> | ||
<h1>Hi {{name}}!</h1> | ||
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*jshint node: true*/ | ||
|
||
var fs = require("fs"); | ||
var assert = require("assert"); | ||
|
||
var hbsfy = require("hbsfy"); | ||
var Handlebars = require("hbsfy/runtime"); | ||
|
||
|
||
var templatePath = __dirname + "/indentation.hbs"; | ||
var exported = __dirname + "/compiled.js"; | ||
|
||
try { | ||
fs.unlinkSync(exported); | ||
} catch (err) { } | ||
|
||
fs.createReadStream(templatePath) | ||
.pipe(hbsfy(templatePath, { | ||
processContent: function(content) { | ||
return content | ||
.replace(/^[\x20\t]+/mg, '') | ||
.replace(/[\x20\t]+$/mg, '') | ||
.replace(/[\r\n]/g, ''); | ||
} | ||
})) | ||
.pipe(fs.createWriteStream(exported)) | ||
.on("close", function() { | ||
var template = require(exported); | ||
var res = template({ name: "Bob" }); | ||
assert.equal(res, "<header><h1>Hi Bob!</h1></header>"); | ||
}); | ||
|