Closed mjmeintjes closed 2 years ago
Thanks for the PR. Can you remove the extraneous commits?
Sure. I see I also forgot the deps.edn file in the commit - are you ok if I leave it in or do you prefer I take it out?
Please leave it out.
I've squashed the commits and removed the deps.edn commit.
You still have the str/trim
change. Can you remove that as well?
You'll also need to add in some tests.
You still have the
str/trim
change. Can you remove that as well?You'll also need to add in some tests.
I've added a test.
I included the str/trim to prevent having to change existing tests, as without it 20 tests fail.
Eg without str/trim:
FAIL in (auto-escaping) (core_test.clj:182)
elements
expected: (= (str (html [:p {:class ["<\">"]}])) "<p class=\"<">\"></p>")
actual: (not (= "<p class=\" <">\"></p>" "<p class=\"<">\"></p>"))
What's causing the failure when str/trim
is omitted?
If classes
is nil (ie if the element name is bare and contains no "sugared" classes), then merge-classes
will prepend a leading space without the str/trim
.
All the existing tests assume that merge-classes
won't even be called when classes
is nil, with with the new change in this PR, merge-classes
gets called even if classes
is nil. So the tests either need to be updated, or the resulting class string needs to be trimmed. I prefer going with the trim version as it does not effect existing output, and it looks cleaner.
Ah, okay, now with the tests I see what you're doing. I don't think we want to have special behavior for the classes
attribute in particular. Instead, lets change this line to make all keywords render as strings when used in attributes.
I've pushed a change to make all keywords render as strings when used in attributes. It is a bit more than one line change, because I assume that you want to support integers and other non-Named values in attributes.
There's already a protocol function, hiccup.util/to-str
that will convert objects to strings.
I've changed the code to use the hiccup.util/to-str
function.
You should now be able to remove the other changes as well, as they shouldn't be necessary.
Done, now only a couple of characters change.
Reminds me of this story.
Thanks. Let's fix the commit message next so that it reflects the content of the commit. Can you change the commit message to:
Map sequential attribute values through to-str
Closed by #195.
When classes is nil, the merge code that converts keyword class names to strings is not being called. This commit ensures that the code gets called if there are any classes.