I'm trying to build some partial files. Some of my partials have a long list of options.
For example, let's say a button partial has something like 20 options, eg: ['background', 'color', 'width', 'height', 'text', ...]. If you don't use locals, then you have to include every variable possible or else they would be undefined. It wouldn't be sane to have to write every option every time you want to include it:
<button style="<%- width ? `width:${width}px;`: '' %>"><%= text -%></button>
Because variable inheritance is forced, and not optional, that means both <dialog> and <button> with both have the same value in locals.width. That means the <button> will also get the same width as the dialog. The only alternative I've found is to either create unique variable names for each and every partial (eg: buttonText, dialogText, buttonWidth, etc), though that gets really convoluted. Also, it means parameters of each partials are no longer unique, requiring a new JSDoc for each and every partial, instead of something that can be shared.
It seems that instead of include being called a function in an isolated scope, it's instead embedding the called function inside itself with a closure. (ie: dialogFn executes buttonFn within itself, instead of calling a function and only caring about the return). Basically, I would want every include to be static. The concept of local would be just that, just local to the function itself, not globally inheriting all the variables that came before it (ie: "Functional Programming"), If I need to pass down a function, I would do that imperatively.
I'm not sure if I'm missing something in the CLI, or options, but it really doesn't currently seem possible.
I'm trying to build some partial files. Some of my partials have a long list of options.
For example, let's say a button partial has something like 20 options, eg:
['background', 'color', 'width', 'height', 'text', ...]
. If you don't uselocals
, then you have to include every variable possible or else they would be undefined. It wouldn't be sane to have to write every option every time you want to include it:If you use
locals
, then you can do:The problem arises when you are using an include inside another include. Let's say
dialog.ejs
looks like this:Because variable inheritance is forced, and not optional, that means both
<dialog>
and<button>
with both have the same value inlocals.width
. That means the<button>
will also get the same width as the dialog. The only alternative I've found is to either create unique variable names for each and every partial (eg:buttonText
,dialogText
,buttonWidth
, etc), though that gets really convoluted. Also, it means parameters of each partials are no longer unique, requiring a newJSDoc
for each and every partial, instead of something that can be shared.It seems that instead of
include
being called a function in an isolated scope, it's instead embedding the called function inside itself with a closure. (ie:dialogFn
executesbuttonFn
within itself, instead of calling a function and only caring about the return). Basically, I would want everyinclude
to be static. The concept oflocal
would be just that, just local to the function itself, not globally inheriting all the variables that came before it (ie: "Functional Programming"), If I need to pass down a function, I would do that imperatively.I'm not sure if I'm missing something in the CLI, or options, but it really doesn't currently seem possible.