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

Allow null to be used to omit Diet template attributes #520

Closed
s-ludwig opened this Issue Feb 13, 2014 · 5 comments

Comments

Projects
None yet
2 participants
@s-ludwig
Member

s-ludwig commented Feb 13, 2014

String values with the value null should be omitted using a cheap run time test to enable conditional inclusion of attributes:

div(somattr=cond ? "foo" : null)

will yield either <div somattr="foo"> or <div> depending on cond.

See #372 and #375 for the previous discussion.

@nazriel

This comment has been minimized.

Show comment
Hide comment
@nazriel

nazriel Feb 13, 2014

Contributor

@s-ludwig what does "cheap run time test" mean?

Is something like:

@@ -917,10 +920,12 @@ private struct DietCompiler {
                                output.writeExprHtmlAttribEscaped(`join(`~att.va
                                output.writeString(`"`);
                                output.writeCodeLine("} else {");
+                               output.writeCodeLine("if ("~att.value~"){");
                                output.writeString(` `~att.key~`="`);
                                output.writeExprHtmlAttribEscaped(att.value);
                                output.writeString(`"`);
                                output.writeCodeLine("}");
+                               output.writeCodeLine("}");

cheap?

Contributor

nazriel commented Feb 13, 2014

@s-ludwig what does "cheap run time test" mean?

Is something like:

@@ -917,10 +920,12 @@ private struct DietCompiler {
                                output.writeExprHtmlAttribEscaped(`join(`~att.va
                                output.writeString(`"`);
                                output.writeCodeLine("} else {");
+                               output.writeCodeLine("if ("~att.value~"){");
                                output.writeString(` `~att.key~`="`);
                                output.writeExprHtmlAttribEscaped(att.value);
                                output.writeString(`"`);
                                output.writeCodeLine("}");
+                               output.writeCodeLine("}");

cheap?

@nazriel

This comment has been minimized.

Show comment
Hide comment
@nazriel

nazriel Feb 13, 2014

Contributor

Well, my naive take on it: #521

Contributor

nazriel commented Feb 13, 2014

Well, my naive take on it: #521

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Feb 13, 2014

Member

Yes, almost there, but it needs an additional type check. See my earlier #375 (comment). I didn't test that, though, so no guarantees.

Member

s-ludwig commented Feb 13, 2014

Yes, almost there, but it needs an additional type check. See my earlier #375 (comment). I didn't test that, though, so no guarantees.

@nazriel

This comment has been minimized.

Show comment
Hide comment
@nazriel

nazriel Feb 13, 2014

Contributor

Ach, I see.
Updated && seems to pass unittest.

I just wonder...

Is output.writeCodeLine(" if ("~att[0]~" !is null) {\n"); null check here necessary?
Wouldn't be if ("~ att.value ~ ") enough and more flexible?

Contributor

nazriel commented Feb 13, 2014

Ach, I see.
Updated && seems to pass unittest.

I just wonder...

Is output.writeCodeLine(" if ("~att[0]~" !is null) {\n"); null check here necessary?
Wouldn't be if ("~ att.value ~ ") enough and more flexible?

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Feb 14, 2014

Member

In this case, since only string is handled as a type, those two are completely equivalent. But I used !is null because it makes it a bit more obvious that only null should match and not a zero-length string.... not that anybody would read that generated code :P

Member

s-ludwig commented Feb 14, 2014

In this case, since only string is handled as a type, those two are completely equivalent. But I used !is null because it makes it a bit more obvious that only null should match and not a zero-length string.... not that anybody would read that generated code :P

s-ludwig added a commit that referenced this issue Feb 17, 2014

Merge pull request #521 from nazriel/issue520
Fix issue #520: Allow null to be used to omit Diet template attributes

@s-ludwig s-ludwig closed this Jan 10, 2016

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