USWDS-Site - Spacing token - Repair converted tokens - #1949
Conversation
…acing-token-05
|
@mejiaj This PR creates a workaround for the confusion that happens with the leading zero and quotes between files. I tried to prevent the confusion with different methods of making |
There was a problem hiding this comment.
I can see the benefit of having the ability to override a conversion. We could also approach this from another angle.
The issue seems to be is_number.html and how it treats the 05 value:
https://github.com/uswds/uswds-site/blob/aa4c540b646af56c01250e1dc5f3ef8fb2191446/_includes/tokens/is_number.html#L22-L30
We could add an additional check that would give us the number or the converted value, instead of both (because we're already checking in the template):
{% if is_number %}
{% assign converted = false %}
{% else %}
{% assign conversion =
site.data.tokens.conversion
| where: 'token', item.token %}
{% if conversion[0].number %}
{% assign converted = conversion[0].number %}
{% endif %}
{% endif %}This resulted in a table that no longer has 0.5 as a value of 5:

What do you think @amyleadem @thisisdano?
|
@mejiaj I attempted to implement your suggested solution. It fixed the false association with the |
I think that's what It looks like |
| {% if is_number %} | ||
| {% assign converted = false %} | ||
| {% else %} |
There was a problem hiding this comment.
Checking if the item is a number first prevents the 5 token from incorrectly receiving a converted value.
| small: | ||
| - token: '05' | ||
| value: 4px | ||
| conversion: 0.5 |
There was a problem hiding this comment.
Created an explicit equivalent number value here because it could not recognize the '05' token when assigning converted in is_number.html
| type: token | ||
| changelogURL: | ||
| items: | ||
| - date: 2022-12-19 |
There was a problem hiding this comment.
Need to update this date prior to merge
|
@mejiaj I was not able to get Also - the checks are currently failing because snyk ignore needs to be updated. The forthcoming snyk fix is in this PR: #2013 |
…acing-token-05
mejiaj
left a comment
There was a problem hiding this comment.
Nice work fixing this issue! The output table on the spacing units page looks good.
Just a minor question on the PR date in changelog. Otherwise LGTM!
| type: token | ||
| changelogURL: | ||
| items: | ||
| - date: 2022-12-19 |
There was a problem hiding this comment.
This should be merge date right?
| <span class="text-no-wrap padding-right-4"> | ||
| {% if converted %} | ||
| <code>{{ converted }}</code>, | ||
| {% elsif item.conversion %} |
There was a problem hiding this comment.
I would just suggest we add a note for what this means. That way we can understand the logic flow in the future.

Summary
Related issue
Closes #1934
Preview links
Problem statement
On the spacing tokens page, the token
5is incorrectly linked to the0.5number equivalent.0.5should instead be linked to token'05'. This appears to happen because of confusion with the leading zero and quotes in'05'– something is getting lost in translation between the files that prevents'05'from receiving anyconvertedvalue.5receives the converted value instead.On the spacing unit page, we need to both:
5token from receiving the0.5number equivalent AND'05'token with the0.5number equivalentAdditionally, the following pages also need to break the association between the
5token and the0.5conversion:Solution
The
convertedassignment inis_number.htmlconsistently ignored the leading zero in the'05'token and would assign theconvertedvalue to5instead. Attempts to explicitly declare'05'as a string to force the leading zero were not successful.As a workaround, this PR creates an explicit
conversionvalue for'05'inspacing.yml. Declaring an explicit value here removes the confusion that is currently happening between files.The spacing unit page appears to be the only instance of
'05'token that is problematic.Screenshots
Final result:
Testing and review
To review:
5token does not have the0.5number equivalent on any of the preview pages.'05'has the0.5equivalent on the spacing tokens page.{{ converted }}display correct values.