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

html.tag() should accept multiple content items, inline #562

Open
towerofnix opened this issue Sep 29, 2024 · 0 comments
Open

html.tag() should accept multiple content items, inline #562

towerofnix opened this issue Sep 29, 2024 · 0 comments

Comments

@towerofnix
Copy link
Member

towerofnix commented Sep 29, 2024

See previous discussion (#code-quarantine). This is re: addressing the following code sample.

What's this about??

Old:

html.tag('li',
  html.tag('details',
    html.isBlank(slots.items) &&
      {open: true},

    [
      html.tag('summary',
        html.tag('span',
          language.$(capsule, {
            title:
              html.tag('span', {class: 'group-name'},
                slots.title),
          }))),

      html.tag('ul', [
        html.tag('li', {class: 'entry-description'},
          {[html.onlyIfContent]: true},
          slots.description),

        (html.isBlank(slots.items)
          ? html.tag('li',
              language.$(capsule, 'noFilesAvailable'))
          : slots.items),
      ]),
    ])),

New:

html.tag('li',
  html.tag('details',
    html.isBlank(slots.items) &&
      {open: true},

    html.tag('summary',
      html.tag('span',
        language.$(capsule, {
          title:
            html.tag('span', {class: 'group-name'},
              slots.title),
        }))),

    html.tag('ul',
      html.tag('li', {class: 'entry-description'},
        {[html.onlyIfContent]: true},
        slots.description),

      (html.isBlank(slots.items)
        ? html.tag('li',
            language.$(capsule, 'noFilesAvailable'))
        : slots.items)))),

The only difficulty here is disambiguating which items are attributes and which are content. We came up with a "simple" chunk of code that does that:

Slightly terrifying argument parsing for tag()

It works, but it fails at the one point that html.tag() cannot solve on its own: templates whose content resolves to attributes. (For example, generateColorStyleAttribute.) In the algorithm above, "looks like attributes" simply rules that templates are never attributes. This is "fine" as an existing condition which checks the last argument to tag(), but in this context it breaks templates from ever working as attributes. And most templates are content, not attributes, so we can't just rule the other way (templates are never content—lol).

We need html.tag()—and Tag objects themselves, or at least the representative thing which html.tag() returns—to store provided arguments as-is (or "flattened" leaving templates in-place and as-is), for lazy evaluation later, when content is being stringified or otherwise processed. In other words, this most certainly depends on #331, but also extends that principle to the entire argument list for tag().

See also today discussion (#code-quarantine).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant