Skip to content

Commit

Permalink
Instantiate a new panini instance in each gulp task and patch panini …
Browse files Browse the repository at this point in the history
…to refresh the partials in all renderers

Panini exports an singleton, through that it holds all options and they can not be overwritten. This change adds a new panini instance for each task to hold it's own options.

Panini is patched because Handlebars is also a singleton, so the partials will be overwritten. You can find more infos here: foundation/panini#81 (comment)
  • Loading branch information
marvinhuebner committed Nov 16, 2018
1 parent 6c126e9 commit 9f182e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
18 changes: 11 additions & 7 deletions helper/inky.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
return [];
}

plugins.panini.refresh();
var Panini = require('panini').Panini;

var panini = new Panini({
root: srcBase + '/',
layouts: srcBase + '/email/layouts/',
partials: srcBase + '/email/partials/',
helpers: srcBase + '/email/helpers/'
});

panini.loadBuiltinHelpers();

return gulp.src(
file || srcBase + '/**/*.email.hbs',
Expand All @@ -37,12 +46,7 @@ module.exports = function(gulp, plugins, config, name, file) { // eslint-disable
})
)
)
.pipe(plugins.panini({
root: srcBase + '/',
layouts: srcBase + '/email/layouts/',
partials: srcBase + '/email/partials/',
helpers: srcBase + '/email/helpers/'
}))
.pipe(panini.render())
.pipe(plugins.if(!enableInliner, plugins.replace('###THEME-NAME###', themeName)))
.pipe(plugins.inky())
.pipe(plugins.replace(/(\\?{!!)(\s+)?/g, '{{'))
Expand Down
26 changes: 11 additions & 15 deletions patches/panini+1.6.3.patch
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
patch-package
--- a/node_modules/panini/index.js
+++ b/node_modules/panini/index.js
@@ -38,10 +38,12 @@ module.exports = function(options) {
if (!panini) {
panini = new Panini(options);
panini.loadBuiltinHelpers();
- panini.refresh();
- module.exports.refresh = panini.refresh.bind(panini);
}
--- a/node_modules/panini/lib/render.js
+++ b/node_modules/panini/lib/render.js
@@ -21,6 +21,10 @@ function render(file, enc, cb) {
var page = fm(stripBom(file.contents.toString()));
var pageData;

+ panini.options = options;
+ panini.refresh();
+ module.exports.refresh = panini.refresh.bind(panini);
+ // Rendering is processed in asynchronous strem - therefore you need to refresh Handlebars Configuration when in multi-instance mode
+ this.Handlebars.partials = {};
+ this.refresh();
+
// Compile pages with the above helpers
return panini.render();
}
// Determine which layout to use
var basePath = path.relative(this.options.root, path.dirname(file.path));
var layout =
--- a/node_modules/panini/lib/utils.js
+++ b/node_modules/panini/lib/utils.js
@@ -16,7 +16,12 @@ exports.loadFiles = function(dir, pattern) {
Expand Down

0 comments on commit 9f182e3

Please sign in to comment.