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

Support programmatically-generated tag attributes #43

Open
quickfur opened this issue Dec 9, 2017 · 3 comments
Open

Support programmatically-generated tag attributes #43

quickfur opened this issue Dec 9, 2017 · 3 comments

Comments

@quickfur
Copy link

quickfur commented Dec 9, 2017

I have no idea if this is actually already supported because the docs are very incomplete, but I'm having a frustrating time trying to figure out how to generate a <meter> tag whose list of attributes is generated by embedded D code. (It's not just the values of the attributes that are unknown, but whether or not certain attributes even appear in the tag in the first place. The former is easy; the latter I'm having a really hard time with.) Is this even remotely possible, or do I have to generate the tag from D code and inject it into the output?

I found something about &attributes online in the Jade Template spec, but it seems Diet doesn't support this syntax. If such a thing is not yet supported by Diet, it would be very nice if this feature could be added. Perhaps something along the lines of:

html
    body
        - auto attrs = [ "min": "0", "max": "100" ];
        - if (hasOptimal) attrs["optimal"] = optimalValue;
        meter(value=#{value})&attributes(attrs)

Or if this feature already exists in some form, please at least mention it in the docs.

@s-ludwig
Copy link
Member

s-ludwig commented Dec 9, 2017

There is currently just one way implemented to have attributes omitted at runtime, which is having the type of argument given as a string or char array and setting the value to null.

But I didn't know about the &attributes syntax until now, and it unfortunately conflicts with the i18n syntax foo& This is translated text, so something else will have to be used for Diet.

meter(min=0, max=100, optimal=hasOptimal ? optimalValue.to!string : null)

@quickfur
Copy link
Author

OK, using null strings to suppress attributes should suffice for now. I can work with that.

I'm not too concerned about the exact syntax for transforming an AA into an attribute list, and honestly I think the &attributes syntax is rather ugly. But having some way of doing this would be very nice. Thanks!

@quickfur
Copy link
Author

P.S. Also, is the null string thing documented anywhere? I don't remember seeing a reference to it. It would be nice to at least mention it somewhere so that people like me can find the information. :)

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

No branches or pull requests

2 participants