hinode icon indicating copy to clipboard operation
hinode copied to clipboard

Refactor argument initialization

Open markdumay opened this issue 1 year ago • 3 comments

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.

markdumay avatar Sep 03 '24 13:09 markdumay

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.

markdumay avatar Sep 14 '24 06:09 markdumay

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:

markdumay avatar Sep 14 '24 06:09 markdumay

Thirdly, the utilities/IsInvalidArgs.html partial should also support reading default values from the site configuration. The initialization order would be the following:

  1. The value of the passed argument
  2. The default value defined in the site parameters, identified by key
  3. The default value defined in the structure file

markdumay avatar Sep 14 '24 07:09 markdumay