Glavin001/atom-beautify

Support HTML (Ruby - ERB)

borisdamato opened this issue · 9 comments

When I try to beautify an html.erb file, atom returns the "Unsupported language for grammar 'HTML (Ruby - ERB)'." error. Since html.erb is just a simple html file with embed ruby, could it be possibile to support it?

Absolutely! Thanks for letting me know.

Here is the afflicting line of code: https://github.com/Glavin001/atom-beautify/blob/master/lib/language-options.coffee#L148

Change

when "HTML (Liquid)", "HTML", "XML"

to

when "HTML (Liquid)", "HTML", "XML", "HTML (Ruby - ERB)"

And it will also handle that grammar for .erb files.

I will try and publish a patch after work tonight.

@Aselox could post a sample html.erb file contents? I am going to quickly patch it now, test, and publish.

Also it may be worth while to switch from js-beautify to https://github.com/threedaymonk/htmlbeautifier for HTML beautification support.

beautifier/js-beautify#398 would suggest that ERB support is not available with js-beautify.

It may be best to add ERB support and use https://github.com/threedaymonk/htmlbeautifier just for it.

@Glavin001 I renamed the file I'm working on removing the .erb part and I noticed the same bug described in that report. It seems to break ruby code by adding spaces between @ or models.
Eg: @user.username -> @ user.username (or) User.find_by_id -> U ser.find_by_id

Could you try htmlbeautifier and let me know if it works for you? If it works as expected in all of your usages then I can add support for it later today 👍.

Ok @Glavin001, I tried htmlbeautifier multiple times and it seems to work really well without breaking the embed ruby code.

Excellent! Then I should be able to add support for ERB HTML later. I'll see if I can tonight, if not soon after. Thanks for testing!

I took the example from: http://www.stuartellis.eu/articles/erb/

<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
            <title>Shopping List for <%= @date.strftime('%A, %d %B %Y') %></title>
        </head>
        <body>
                 <h1>Shopping List for <%= @date.strftime('%A, %d %B %Y') %></h1>
                <p>You need to buy:</p>
                <ul>
                  <% for @item in @items %>
                    <li><%= h(@item) %></li>
                  <% end %>
                </ul>
        </body>
        </html>
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <title>Shopping List for
        <%= @date.strftime('%A, %d %B %Y') %></title>
    </head>
    <body>
      <h1>Shopping List for
        <%= @date.strftime('%A, %d %B %Y') %></h1>
      <p>You need to buy:</p>
      <ul>
        <% for @item in @items %>
        <li><%= h(@item) %></li>
      <% end %>
    </ul>
  </body>
</html>

Will be publishing soon now that I have it working and tested 👍.

Published to v0.8.0