Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #46 from danspam/remove-bom
Browse files Browse the repository at this point in the history
Option to remove BOM from start of file
  • Loading branch information
kirbysayshi committed Oct 12, 2015
2 parents 94e765d + dba2122 commit 76bace1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ function hbsfy(file, opts) {
var compiled = "// hbsfy compiled Handlebars template\n";
var parsed = null;
var partials = null;

if (opts && (opts.b || opts.bom) && buffer.indexOf('') === 0) {
buffer = buffer.substring(1);
}

try {
if (traverse) {
Expand Down
1 change: 1 addition & 0 deletions test/bom.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello {{msg}}!
28 changes: 28 additions & 0 deletions test/bom_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

var assert = require("assert");
var concat = require("concat-stream");
var fs = require("fs");
var hbsfyBom = require("hbsfy");
var hbsfyNoBom = require("hbsfy").configure({
bom: true
});

var templatePath = __dirname + "/bom.hbs";

fs.createReadStream(templatePath)
.pipe(hbsfyBom(templatePath))
.pipe(concat(function(data) {
assert(
//.test(data.toString()),
"The template should contain a bom"
);
}));

fs.createReadStream(templatePath)
.pipe(hbsfyNoBom(templatePath))
.pipe(concat(function(data) {
assert(
//.test(data.toString()) === false,
"The template should not contain a bom"
);
}));

0 comments on commit 76bace1

Please sign in to comment.