You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// usagetempura.compile('...',{blocks: {// section opener'#section': args=>{lettxt='<section>';if(args.title)txt+=`<h2>${args.title}</h2>`;returntxt;},// section closer'/section': ()=>'</section>',// does NOT expect children// ~> no "/partial" key'#partial': asyncargs=>{// ...return'something';}}});
With this approach, the tempura parse will infer whether or not it should expect a {{/NAME}} based on /NAME's existence in the options.block dictionary. In other words, defining a "/partial": args => {} in this example – without modifying the template – would throw:
Expected to close "partial" block; closed "section" instead
Option B
Rely on the template tag itself to determine if this block should be stateful.
Additionally, any stateful blocks would have to return string[] instead of string:
// usagetempura.compile('...',{blocks: {// #section block// must return string[]section(args){letopen='<section>';if(args.title)open+=`<h2>${args.title}</h2>`;return[open,//=> #section'</section>'//=> /section];},// #partial block// ~> does NOT have children// must return stringasyncpartial(args){// ...return'something';}}});
Here, the {{#/partial}} syntax means that it's self-closing, just like a JSX or HTML <input /> element.
I think Option B is a bit sleeker, but both approaches have a potential authoring and/or usage issue. They both require that the author & user of a block are aware of its type, affecting both how it must be defined and how it must be used.
I intentionally don't want a block to work both ways. The rigidity here is fine, but just thinking about which approach may feel better.
The text was updated successfully, but these errors were encountered:
There are two ways to do this:
Option A
Rely on the
options.blocks
key name(s) to decide whether or not a custom directive is "stateful" / will have a closing tag:With this approach, the tempura parse will infer whether or not it should expect a
{{/NAME}}
based on/NAME
's existence in theoptions.block
dictionary. In other words, defining a"/partial": args => {}
in this example – without modifying the template – would throw:Option B
Rely on the template tag itself to determine if this block should be stateful.
Additionally, any stateful blocks would have to return
string[]
instead ofstring
:Here, the
{{#/partial}}
syntax means that it's self-closing, just like a JSX or HTML<input />
element.I think Option B is a bit sleeker, but both approaches have a potential authoring and/or usage issue. They both require that the author & user of a block are aware of its type, affecting both how it must be defined and how it must be used.
I intentionally don't want a block to work both ways. The rigidity here is fine, but just thinking about which approach may feel better.
The text was updated successfully, but these errors were encountered: