emulsify-ds / emulsify-twig-extensions

Twig.js BEM and Add Attributes Extensions
2 stars 1 forks source link

add_attributes doesn't handle integers #4

Open WidgetsBurritos opened 3 years ago

WidgetsBurritos commented 3 years ago

There is a slight issue with the add_attributes() function on storybook side:

https://github.com/emulsify-ds/emulsify-twig-extensions/blob/master/packages/add-attributes-twig-extension/lib/add-attributes-twig-extension.js#L16-L24

        else {
          // Handle bem() output (pass in exactly the result).
          if (value.includes('=')) {
            attributes.push(value);
          }
          else {
            attributes.push(key + '="' + value + '"');
          }
        }

value.includes('=') assumes that value is a string. If it's an integer, it generates this error:

TypeError: value.includes is not a function

value should either be converted to a string prior to the check, or we should have a separate check to see if value is an integer.

I'm able to fake it for now by just doing something like this in my twig, where I change my value to a string:

{% set td_attributes = td_attributes|merge({'colspan': td.colspan ~ ''}) %}

But that's not a really clean solution. I think it makes more sense to fix it here.

Opening the issue for now, but I can try to open a PR later, if time permits (I'm about to head off on PTO for 2 weeks, so I'm unsure if I'll get to it before then or not).

┆Issue is synchronized with this Clickup task by Unito

callinmullaney commented 3 years ago

PR created - https://github.com/emulsify-ds/emulsify-twig-extensions/pull/6