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

unify all templating attributes to have the same prefix #23

Open
line-o opened this issue Feb 8, 2023 · 7 comments
Open

unify all templating attributes to have the same prefix #23

line-o opened this issue Feb 8, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@line-o
Copy link
Member

line-o commented Feb 8, 2023

Status quo

At the moment we have most of the templating attributes share the prefix data-template
There is two exceptions

  1. data-target to identify a node/ slot where children of the calling element with data-template="templates:include" be placed
  2. the templating function itself just uses data-template

Proposed change

Disambiguate and unify

I would propose to unify those two to

  1. data-template-target making its purpose more obvious
  2. data-template-function for the same reason

Template function parameters

Additional parameters to template functions are also placed alongside other template attributes.

The parameter value $arg for a template function declared as my:func($node, $model, $arg) is defined in the
template with data-template-arg. This can lead to hard to debug naming collisions.

A hypothetical template function my:clash($node, $model, $use-when) would collide with the newly added
data-template-use-when (see #20).

We can mitigate that by defining that additional template function parameter must be declared with
data-template-parameter-<name>.

@line-o line-o added the enhancement New feature or request label Feb 8, 2023
@line-o line-o mentioned this issue Feb 8, 2023
5 tasks
@line-o
Copy link
Member Author

line-o commented Feb 10, 2023

This will also make #22 easier to implement.

@yamahito
Copy link

I think the issue here is with legacy template code, particularly for the data-template-function and data-template-parameter- parts of the proposal.

I'm not sure that the use case for renaming data-template is as compelling as the other; there is no name collision problem that I can see; perhaps encourage data-template-function but allow both?

Although it is extra work, is it worth considering considering data-template-arg iff there is no data-template-parameter-arg and there is no other function of that name?

@eXist-db eXist-db deleted a comment from open-collective-bot bot Feb 10, 2023
@line-o
Copy link
Member Author

line-o commented Feb 10, 2023

I am aware that renaming data-template will break existing templates as data-template-<parameter-name> to data-template-parameter-<parameter-name> will.
Do you think it is feasible to allow both? I consider the code that gathers the extra function parameters hot-code as it checks for the existence whenever a data-template attribute is present on a node. But maybe we have enough time-budget left.
If it is too expensive, then I would lean towards leaving it as it is.

Although it is extra work, is it worth considering considering data-template-arg if there is no data-template-parameter-arg and there is no other function of that name?

Do you want data-template-arg-<parameter-name> as an alternative to data-template-parameter-<parameter-name> or the above to allow both current and unified attribute names?

@PieterLamers
Copy link

I agree with Tomos that I see no particular need for renaming data-template. I think there are many reasons to rename data-target though as it seems way too generic. I have to admit that I have no experience using the template module itself so my two cents are as good as any other's.

@yamahito
Copy link

yamahito commented Feb 13, 2023

Do you want data-template-arg-<parameter-name> as an alternative to data-template-parameter-<parameter-name> or the above to allow both current and unified attribute names?

Sorry for being unclear: "arg" in my example represents the parameter name, not the string arg : I was following your syntax established under "Template Function Parameters" in the original description! :)

To restate, I was suggesting data-template-<parameter-name> as a fall back to data-template-parameter-<parameter-name> in the case where the latter is not supplied for a given template function with that parameter.

@line-o
Copy link
Member Author

line-o commented Mar 20, 2023

How about a - default - legacy mode that will accept both data-template and data-template-<parameter-name>?
When a user opts-in to the new strict(?) mode than only templates with data-template-function and data-template-parameter-<parameter-name> are acceptable.

Doing this would then enable to select any prefix to be used instead of data-template. t-function and t-parameter-<parameter-name> would then become available and even namespaces would become availabe @t:*.

@yamahito
Copy link

Sounds like the right sort of approach: I would advise caution at treating namespace prefixes in the same way as prefixes within the attribute name, however - as I'm sure you already appreciate, they are not the same thing!

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

3 participants