Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Class name gets `undefined` #610

Closed
chowey opened this Issue Apr 27, 2012 · 6 comments

Comments

Projects
None yet
6 participants
Contributor

chowey commented Apr 27, 2012

This is a minor bug for class attributes.

The following jade

- var obj = {}
div(class=obj.class) Test

renders like

<div>Test</div>

so that undefined attributes are not added.

However, this jade

- var obj = {}
div.foo(class=obj.class) Test

renders like

<div class="foo undefined">Test</div>

so that the undefined attribute is added.

Contributor

tj commented Apr 28, 2012

ahhh good find thanks for reporting, I bet foo(class=['foo', 'bar', undefined]) is the same too

Contributor

chowey commented May 22, 2012

This could probably be fixed by compiling attrs.class as an Array instead of a String.

In lib/compiler.js#L588:

classes = '[' + classes.join(', ') + ']';

instead of

classes = classes.join(" + ' ' + ");

Then "runtime.js" would need to be updated so attrs will unwrap an Array of Arrays (in case the user passes an Array as a class) to make it one big array.

Plus anywhere else where classes are monkeyed with would need to be checked to make sure it didn't break anything.

insin commented Aug 1, 2012

The suggested fix seems to work, quick test implementation here (with a disgusting in-place filter and flatten!): https://gist.github.com/3221334

skeggse commented Apr 12, 2013

Just came across this bug. Any chance it could be fixed?

Owner

ForbesLindesay commented Apr 25, 2013

If I see a pull request that fixes it, I'll merge it.

Contributor

viatsyshyn commented May 25, 2013

This issues relates to #1024 array in class attribute is joined with ',' instead of ' '

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