Support template inheritance from content files #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I don't expect this to be accepted, but would like it to instigate a discussion on supporting something similar to this. I think more automation (ie. not having users specify block patterns manually) and testing with different templating libraries (tested only with jade and swig) would be required before this is ready for public consumption. Perhaps consolidate.js -like wrapper for templating libraries that support blocks would help as well.
The base of the idea is that for template languages that support blocks (atpl, dust, ect, Hogan, just, nunjucks, swig and potentially liquor), there is no way to override template blocks from content files without creating dummy content-file specific templates (template file per content file).
The changes cause content files to extend a template (given the proper setup in front-matter) and thus allow overriding of blocks specified in the template. Optionally, the content can also be wrapped in a block itself, giving a bit more flexibility to templating.
Because there is no universal way of specifying blocks, the current implementation expects the user to specify block definition of their templating language of choice (
extendsPattern
,blockPattern
).If none of the new options are used when setting up the plugin in metalsmith, the plugin works as normal without any side effects. New functionality will be triggered only when
useExtends
is specified in plugin setup and a content file has anextends
keyword in front-matter.Any flames, blames, ideas or comments are welcome.