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.
Context
We want to dynamically inject new variables to the
locals
object depending on the user's input. This is useful for several reasons.We want to automatically generate variations of an argument to lighten the templates' code.
a. For exemple, if a user inputs --name 'OrderLine', we want to dynamically add :
myName
: "orderLine"my_name
: "order_line"MyName
: "OrderLine"myNameS
: "orderLines" (forced plural)my_nameS
: "order_lines" (forced plural)MyNameS
: "OrderLines" (forced plural)This allows us the replace the following code :
We can add dynamic variables depending of the user arguments. Internally, we built a 20 field type generators (for input text, select, date picker, autocomplete, etc). Depending on the given field type, we want to make new variables accessible in the template. We prefer this approach over helpers because it makes the code a bit more readable, but also a lot faster. We use complex helpers to add dynamic variables available to the templates, but these are recalculated everytime they are called. Having more than 200 templates, this will greatly improve DX and performance!
How to use