Refactor argument initialization
Problem or enhancement idea
Partials and shortcode use a structured approach to validate their arguments. However, there is still quite a lot of boilerplate code to initialize the arguments. For example, the card-group partial uses about 30 lines of code to initialize the local variables based on the arguments passed to the partial.
Proposed solution
Refactor the utility function utilities/IsInvalidArgs.html defined in mod-utils to not only validate the arguments, but to initialize them too. Partials could then simply use them as map entries, unless they would need to override their values.
In addition to the proposal, the arguments should support common definitions too. For example, the class arguments is defined in 30 data files. Using common definitions would improve standardization and limit rework.
Another refinement is to validate nested argument types too. Currently, nested types are not validated beyond their map type at all.
The following example illustrates the definition of a heading type.
arguments:
heading:
type: map[string]interface {}
optional: true
comment: >-
Convenience argument to pass preheading, heading, content, align, and
width with one structured argument.
In the actual code, the heading supports the following nested map entries:
preheading:
preheadingPlacement:
heading:
content:
align:
width:
Thirdly, the utilities/IsInvalidArgs.html partial should also support reading default values from the site configuration. The initialization order would be the following:
- The value of the passed argument
- The default value defined in the site parameters, identified by key
- The default value defined in the structure file