posthtml / posthtml-extend

Template extending (Jade-like)
MIT License
46 stars 9 forks source link

Disable checks for undefined blocks #16

Closed chocolateboy closed 6 years ago

chocolateboy commented 6 years ago
posthtml-extend0.2.1
posthtml0.11.3
Nodev10.9.0
OS Linux (Arch)

Sometimes (most of the time, in fact) I'd like to declare blocks in a child page that aren't declared in its parent page e.g.:

Page 1

<h1>Welcome to 3 Pages!</h1>
<block name="body"></block>

Page 2

<extends src="page1.html">
    <block name="body">
        <form name="login">
            ...
            <block name="submit-button">
                <input type="submit" disabled="disabled" />
            </block>
        </form>
    </block>
</extends>

Page 3

<extends src="page2.html">
    <block name="submit-button">
        <input type="submit" />
    </block>
</extends>

Note: the button doesn't exist on page 1 and is only declared in page 2 so that it can be replaced in page 3.

This currently doesn't work because of the strict check for undeclared blocks here:

https://github.com/posthtml/posthtml-extend/blob/747e8b1b874b5477b1681ab969e1d72729f248a0/lib/extend.es6#L82-L84

- which results in the following error:

page3.html: [posthtml-extend] Unexpected block "submit-button"

If this check is removed, page 2 works as expected and page 3 extends it as expected.

I'd much prefer for blocks to be handled in this "loose" way than the current default, and it would be great if these checks could be bypassed, preferably by default, or at least by opting out e.g.:

extend({ root: rootDir, failOnUndefinedBlocks: false })