Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support for Nested Partials #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,56 @@ class HtmlWebpackPartialsPlugin {
// to index.html if not set

return partial.should_inject && (
partial.template_filename === data.plugin.options.filename ||
partial.template_filename === data.plugin.options.filename ||
Array.isArray(partial.template_filename)
? partial.template_filename.includes(data.plugin.options.filename)
: partial.template_filename === '*'
);

}).forEach(partial => {
}).forEach(partial => this.buildTemplate(partial, data));

// Once we know we're using the partial, read the file and create a template
callback(null, data);

});

partial.createTemplate();
});

// Finally inject the partial into the HTML stream
}

data.html = Util.injectPartial(data.html, {
options: partial.options,
html: partial.template(partial.options),
priority: partial.priority,
location: partial.location,
});

});
/**
* Build template from Partial object and data.html, returning new html.
*/
buildTemplate(partial, data){
// Once we know we're using the partial, read the file and create a template

callback(null, data);
partial.createTemplate();

// Get partial HTML
let partial_html = partial.template(partial.options);

// Iterate through sub-partials and build into partial_html
if(partial.options.subPartials != null && Array.isArray(partial.options.subPartials)){

partial.options.subPartials.map(subpartial => {
return new Partial(subpartial);
}).forEach(subpartial => {
partial_html = this.buildTemplate(subpartial, { html: partial_html });
});

}


// Finally inject the partial into the HTML stream

data.html = Util.injectPartial(data.html, {
options: partial.options,
html: partial_html,
priority: partial.priority,
location: partial.location,
});

return data.html;
}

}
Expand Down