Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor argument initialization #1151

Open
markdumay opened this issue Sep 3, 2024 · 3 comments
Open

Refactor argument initialization #1151

markdumay opened this issue Sep 3, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@markdumay
Copy link
Collaborator

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 markdumay added the enhancement New feature or request label Sep 3, 2024
@markdumay
Copy link
Collaborator Author

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
Copy link
Collaborator Author

markdumay commented Sep 14, 2024

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
Copy link
Collaborator Author

markdumay commented Sep 14, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant