-
Notifications
You must be signed in to change notification settings - Fork 17
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
Erector allows nil for text content of tag/text methods #12
Comments
Hmmm. I'm having trouble reproducing this, which I'd imagine should be easy. Can you post a stack trace? I just added specs ( fortitude/spec/system/tag_rendering_system_spec.rb Lines 14 to 32 in 4441327
rawtext nil did indeed fail, although I fixed it in my latest commit (4441327). But the others seemed to be working fine previously…
Also, I was seeing However, my biggest concern is that we seem to be seeing different behavior from Fortitude. If you’re still seeing this, could you post stack traces for the errors, and full sample code for any rendering differences? I'm happy to separate out base classes or whatever…just concerned that we see different behavior (and different from the specs, which Travis runs on a pretty broad matrix). |
Oh, I was mistaken. It was only for rawtext. Sorry about that. Thanks for the patch. Also regarding the empty string attribute, that's also what happens for me, but chrome inspector stripped it out so I was also mistaken there. I'm not sure I agree with converting |
@leafo is correct here, although I think it depends on the doctype. Here's how I updated my Erector fork to handle this: https://github.com/ajb/erector-rails4/blob/d2fb36cd2f15d075b1f7c371b0c0978775b52908/lib/erector/attributes.rb IMO, the behavior (for HTML5, at least) should be:
|
Hmm. So here’s my thinking on this — I kind of want to type it out as I think through it, no matter where it leads. My goals for Fortitude around issues like these are, in order:
In other words, I would rather sacrifice some Erector compatibility at times if it makes Fortitude more internally consistent or easier to learn. For the first item: Valueless attributes are allowed in both HTML4 (all variants) and HTML5 (see this article for more details, for example), but not allowed in XHTML doctypes since well-formed XML requires all attributes to have a value (even if it’s For the second item, it seems to get less clean. The HTML5 spec says that “boolean attributes” that need a false value must simply be omitted; if they need a true value, they must be present, with either no value at all ( The part I don’t like about this is that I suspect people will find it counterintuitive, particularly when using it on HTML5 But, in the end, the spec always wins. So I think you’re right; it should be: div # => '<div>'
div(:class => false) # => '<div>'
div(:class => true) # => '<div class>'
div(:class => 'true') # => '<div class="true">' Then there’s the question of So, I think I land at this (which I think agrees with both of you above): div # => '<div>'
div(:class => nil) # => '<div>'
div(:class => "") # => '<div class="">'
div(:class => false) # => '<div>'
div(:class => true) # => '<div class>'
div(:class => 'true') # => '<div class="true">' |
Oh, and for XHTML, I think we end up with: div # => '<div>'
div(:class => nil) # => '<div>'
div(:class => "") # => '<div class="">'
div(:class => false) # => '<div>'
div(:class => true) # => '<div class="class">'
div(:class => 'true') # => '<div class="true">' I’ll make these changes this evening, when I have time. |
OK, I pushed this last night, and it passed all tests. I think we can call this one done. :) |
Valid in erector:
Erector just uses
to_s
onnil
, converting it to empty string. Fortitude errors.Also noticed this difference:
In Erector:
<div></div>
In Fortitude
<div class></div>
The text was updated successfully, but these errors were encountered: