eXist-db / templating

HTML Templating Library for eXist-db
GNU Lesser General Public License v2.1
5 stars 8 forks source link

unify all templating attributes to have the same prefix #23

Open line-o opened 1 year ago

line-o commented 1 year ago

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 commented 1 year ago

This will also make #22 easier to implement.

yamahito commented 1 year ago

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?

line-o commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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!