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

id and class attribute not according to jade #1312

Closed
WebFreak001 opened this Issue Oct 31, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@WebFreak001
Contributor

WebFreak001 commented Oct 31, 2015

According to http://jade-lang.com/reference/attributes/ (Class Attributes) you are allowed to write class="foo" and id="foo", but there are special things about them:

  • if a id already exists using the hashtag notation it should throw an error when trying to set it using id="foo" (Diet just replaces the id)
  • if classes already exist using the dot notation it should append the class (Diet just replaces the class)

Maybe, because = should be assign there could be a new operator += which will append attributes, which could also append to already defined attributes. For example description="Image #" description+=imageNum could be description="Image #4"

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig Nov 2, 2015

Member

It does append classes, see the corresponding unit test: https://github.com/rejectedsoftware/vibe.d/blob/0248af36005e5206b22f8addcb46dd693ceccaf9/source/vibe/templ/diet.d#L1466

Multiple class attributes don't throw an error, though (it's also possible to do span(id="foo", id="bar")), so that would be a good enhancement.

Member

s-ludwig commented Nov 2, 2015

It does append classes, see the corresponding unit test: https://github.com/rejectedsoftware/vibe.d/blob/0248af36005e5206b22f8addcb46dd693ceccaf9/source/vibe/templ/diet.d#L1466

Multiple class attributes don't throw an error, though (it's also possible to do span(id="foo", id="bar")), so that would be a good enhancement.

@WebFreak001

This comment has been minimized.

Show comment
Hide comment
@WebFreak001

WebFreak001 Nov 2, 2015

Contributor

Ok sorry, here updated information + way to reproduce the issue:

So with static strings the code worked:

assert(compile!(`div.foo(class="bar")`) == `<div class="bar foo"></div>`);
// This works just fine

But when using some dynamic expression in there like this:

string a = "a";
string b = "b";
// This doesn't work as expected

assert(compile!(`div.foo(class=(a == "a" ? "yes" : "no"))`, a) == `<div class="yes foo"></div>`, "Actual output: " ~ compile!(`div.foo(class=(a == "a" ? "yes" : "no"))`, a));
// Actual output: <div class="yes"></div>

assert(compile!(`div.foo(class=b == "a" ? "yes" : "no")`, b) == `<div class="no foo"></div>`, "Actual output: " ~ compile!(`div.foo(class=b == "a" ? "yes" : "no")`, b));
// Actual output: <div class="no"></div>
// Both with or without parentheses this issue occurs

So I expect them to prepend/append yes or no according to the variables a or b but instead they only outputted "yes" or "no" without "foo". However this worked just fine when directly writing yes or no in the class.

Contributor

WebFreak001 commented Nov 2, 2015

Ok sorry, here updated information + way to reproduce the issue:

So with static strings the code worked:

assert(compile!(`div.foo(class="bar")`) == `<div class="bar foo"></div>`);
// This works just fine

But when using some dynamic expression in there like this:

string a = "a";
string b = "b";
// This doesn't work as expected

assert(compile!(`div.foo(class=(a == "a" ? "yes" : "no"))`, a) == `<div class="yes foo"></div>`, "Actual output: " ~ compile!(`div.foo(class=(a == "a" ? "yes" : "no"))`, a));
// Actual output: <div class="yes"></div>

assert(compile!(`div.foo(class=b == "a" ? "yes" : "no")`, b) == `<div class="no foo"></div>`, "Actual output: " ~ compile!(`div.foo(class=b == "a" ? "yes" : "no")`, b));
// Actual output: <div class="no"></div>
// Both with or without parentheses this issue occurs

So I expect them to prepend/append yes or no according to the variables a or b but instead they only outputted "yes" or "no" without "foo". However this worked just fine when directly writing yes or no in the class.

@s-ludwig s-ludwig closed this in 19ccdee Nov 12, 2015

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