Skip to content

Commit

Permalink
Use preventIndent option in Handlebars compiler to prevent partials f…
Browse files Browse the repository at this point in the history
…rom getting extra whitespace, closes #113
  • Loading branch information
gakimball committed Apr 13, 2017
1 parent 410cc91 commit dce628e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions __snapshots__/test.js.snap-shot
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
exports['builds a page with a default layout 1'] = "<html>\n <body>\n <p>Body</p>\n \n </body>\n</html>\n"
exports['builds a page with a default layout 1'] = "<html>\n <body>\n <p>Body</p>\n\n </body>\n</html>\n"

exports['builds a page with an alternate layout 1'] = "<html>\n <body class=\"alternate\">\n <p>Body</p>\n \n </body>\n</html>\n"
exports['builds a page with an alternate layout 1'] = "<html>\n <body class=\"alternate\">\n <p>Body</p>\n\n </body>\n</html>\n"

exports['builds a page with preset layouts by folder 1'] = "<html>\n <body class=\"alternate\">\n <p>Body</p>\n \n </body>\n</html>\n"
exports['builds a page with preset layouts by folder 1'] = "<html>\n <body class=\"alternate\">\n <p>Body</p>\n\n </body>\n</html>\n"

exports['builds a page with custom partials 1'] = "<html>\n <body>\n <p>Body</p>\n <p>Partial!</p>\n \n \n </body>\n</html>\n"
exports['builds a page with custom partials 1'] = "<html>\n <body>\n <p>Body</p>\n<p>Partial!</p>\n\n\n </body>\n</html>\n"

exports['builds a page with Front Matter properties added as variables 1'] = "<html>\n <body>\n Layout: Yes, kittens.\n Page: Yes, kittens.\n \n Partial: Yes, kittens.\n \n </body>\n</html>\n"
exports['builds a page with Front Matter properties added as variables 1'] = "<html>\n <body>\n Layout: Yes, kittens.\n Page: Yes, kittens.\n\n Partial: Yes, kittens.\n\n </body>\n</html>\n"

exports['builds a page with custom helpers 1'] = "<html>\n <body>\n Helper!\n \n </body>\n</html>\n"
exports['builds a page with custom helpers 1'] = "<html>\n <body>\n Helper!\n\n </body>\n</html>\n"

exports['builds a page with external JSON data 1'] = "<html>\n <body>\n eggs\n bacon\n toast\n \n </body>\n</html>\n"
exports['builds a page with external JSON data 1'] = "<html>\n <body>\n eggs\nbacon\ntoast\n\n </body>\n</html>\n"

5 changes: 4 additions & 1 deletion engines/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class HandlebarsEngine extends PaniniEngine {
constructor(options) {
super(options);
this.engine = handlebars.create();
this.compilerOpts = {
preventIndent: true
};

if (this.options.builtins) {
this.loadBultins();
Expand All @@ -37,7 +40,7 @@ class HandlebarsEngine extends PaniniEngine {
super.setup(),
mapFiles(this.options.input, this.options.layouts, extensions, (filePath, contents) => {
const name = path.basename(filePath, path.extname(filePath));
this.layouts[name] = this.engine.compile(contents);
this.layouts[name] = this.engine.compile(contents, this.compilerOpts);
}),
mapFiles(this.options.input, this.options.partials, extensions, (filePath, contents) => {
const name = path.basename(filePath, path.extname(filePath));
Expand Down

0 comments on commit dce628e

Please sign in to comment.