-
Notifications
You must be signed in to change notification settings - Fork 25
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
Parsing issues with yield
?
#51
Comments
The same issue happens with this template also: <div id="flash">
<% flash.each do |type, message| %>
<% next unless message.is_a?(String) %>
<% case type %>
<% when "alert" %>
<%= render("shared/alert_flash", message: message) %>
<% when "notice" %>
<%= render("shared/notice_flash", message: message) %>
<% end %>
<% end %>
</div> The error is:
|
For this template: <section>
<div class="flex flex-col pb-4 mx-auto">
<div class="w-full bg-white rounded-lg shadow sm:max-w-lg md:mt-0 xl:p-0 dark:bg-gray-800 dark:border dark:border-gray-700">
<div class="p-6 space-y-4 sm:p-8 md:space-y-6">
<%= yield %>
</div>
</div>
</div>
</section> Adding |
I'm facing the same issue |
I dug a bit into the code and I found this case statement: erb-formatter/lib/erb/formatter.rb Lines 308 to 326 in 8c1c7b2
So the issue here is that the yield tag should be handled in else I believe, but it's being handled in when RUBY_OPEN_BLOCK I tried replicating the code in else into a when right at the start, where this one checks if the tag starts with yield :
when /\Ayield\b/
ruby_code = format_ruby(ruby_code, autoclose: false)
full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag) So final code looked like this: case ruby_code
when /\Ayield\b/
ruby_code = format_ruby(ruby_code, autoclose: false)
full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
html << (erb_pre_match.match?(/\s+\z/) ? indented(full_erb_tag) : full_erb_tag)
when RUBY_CLOSE_BLOCK
full_erb_tag = "#{erb_open}#{ruby_code} #{erb_close}"
... The formatter seemed to start working correctly |
I'm facing a similar issue when there's a ruby code with <% flash.each do |type, message| %>
<% next unless message.is_a?(String) %>
<div ... >
...
</div>
<% end %> For some reason, erb-formatter thinks that the |
what solution for this problem? |
I have the same issue with |
@IbraheemTuffaha could you please send a PR with your solution? I can't fix it right now, and I'm happy to accept it, even if it's not "optimal" and only improves the situation. 🙏 |
I've tried your branch @IbraheemTuffaha and I confirm that it fixes my issue. 🙏 |
Just wanted to add that I'm also having the same issue with
causes this error:
|
@anthmatic erb-formatter/lib/erb/formatter.rb Line 313 in a7ce8b4
Which is defined here: erb-formatter/lib/erb/formatter.rb Line 65 in a7ce8b4
Are you sure you closed the whole case statement properly?
<% case var %>
<% when "bar" %>
...
<% when "foo" %>
...
<% end %> |
I also had issues with case/when, and this was the only syntax that worked: <% case var
when "bar" %>
...
<% when "foo" %>
...
<% end %> But it now seems to work with @IbraheemTuffaha 's PR. @elia do you think you can merge it? |
Should be closed now after #53 is merged? |
Fixed by #53 |
I have the following ERB template:
When I save it,
erb-formatter
VSCode extension shows the following:But in other templates like the following one:
No issues happens and the formatter works, but the formatting is not correct, I'm pasting the formatted template.
I think
erb-formatter
has some issues withyield
with used with HTML tags.The text was updated successfully, but these errors were encountered: