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
Wrong boolean attributes conversion #119
Comments
Thanks for reporting this @stephannv. I don't think we can really support this, unless we hard code a list of attributes which should get forced to a boolean. Probably something like: BOOLEAN_ATTRIBUTES = ["required", "disabled", "checked", "hidden", "readonly"] But on the other hand, the output Phlexing is providing is not wrong, HTML boolean can either be written as: <input required> <input required=""> or: <input required="required"> All of them are equally valid. MDN says:
So I'm not sure if this (and/or the boolean attribute mapping) should be handled here or in Phlex itself. Any thoughts? |
I think it's not necessary to map all the possible boolean attributes, because some js frameworks can create new boolean attributes every day, eg. I wrote some tests for this behavior: it "should convert boolean attributes properly" do
html = %(<input required>)
expected = <<~PHLEX.strip
input(required: true)
PHLEX
assert_phlex_template expected, html
end
it "should convert blank attributes properly" do
html = %(<input required="">)
expected = <<~PHLEX.strip
input(required: "")
PHLEX
assert_phlex_template expected, html
end But Nokogiri |
Thanks for providing some test-cases! I think that would make sense.
Yeah, I guess that's the root cause of the issue. I wonder if there's another method inside Nokogiri we might be able to use for that! |
@marcoroth I found a solution, but I don't know if it's the best solution: #120 |
Nokogiri #value is always returning "" to <input required> and <input required="">, so I have to call `#to_html` and check if the `=` character is present. I'm not sure if this is the best way, but I tried a lot of Nokogiri methods and none of them returns `nil`. Closes #119.
ERB Input:
Output:
Expected output:
The text was updated successfully, but these errors were encountered: