Skip to content
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

Incorrect conversion of tag-inline ERB #40

Open
aprescott opened this issue Jan 7, 2014 · 6 comments
Open

Incorrect conversion of tag-inline ERB #40

aprescott opened this issue Jan 7, 2014 · 6 comments

Comments

@aprescott
Copy link

Reproduced this on master:

$ cat /tmp/blah.erb 
<%
  attrs = 'data-a="1" data-b="2"'
  class = "some-class"
%>

<div class="panel <%= class -%>" <%= raw attrs -%>>
</div>
$ html2haml /tmp/blah.erb /tmp/blah.haml
$ cat /tmp/blah.haml
- attrs = 'data-a="1" data-b="2"'
- class = "some-class"
.panel
= class
" #{raw attrs}&gt;

This should instead be

- attrs = 'data-a="1" data-b="2"'
- class = "some-class"
<div class="panel #{class}" #{raw attrs}>

html2haml 1.0.1 generates the expected HAML, but the latest version doesn't.

@snatchev
Copy link
Member

snatchev commented Jan 7, 2014

@aprescott I am not sure if html2haml could ever produce the expected output in the case. The issue is that it will not create an html <div> tag like that. The second issue is that there is no haml representation of raw attrs as your have shown in the expected output. They need to be a key-value pair of some kind.

@aprescott
Copy link
Author

@snatchev html2haml 1.0.1 handles this case correctly, though.

@snatchev
Copy link
Member

snatchev commented Jan 7, 2014

@aprescott Good point. I will look into how it handled it. Thanks for reporting.

@bvogel
Copy link

bvogel commented Jan 7, 2014

<div class="panel #{class}" #{raw attrs}> does not look like haml, I'd expect something like
.panel{class: class}, however I'm unsure how the raw attrs should be handled correctly. I'd expect something like .panel{class: class, data: attrs} with attrs = {a: "1", b: "2"}

@aprescott
Copy link
Author

Oh, that's a good point. Sorry @snatchev, getting my HTML and HAML confused. So yes, 1.0.1 "handles" this case for some value of "handle", but I guess any ERB that inserts attributes directly as with #{raw ...} here — which could just as well be #{anything} — should ideally be handled. Not sure if that's possible though with HAML?

@snatchev
Copy link
Member

@aprescott this test case is really difficult. For one, using a variable called class is not valid ruby, so html2haml will not treat it like a code block. Secondly, as mentioned above, there is no HAML equivalent to #{raw attrs} so the only possible solution would be for html2haml to not convert the line and keep it as HTML. This would still be valid Haml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants