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

Support HTML (Ruby - ERB) #80

Closed
borisdamato opened this issue Sep 8, 2014 · 9 comments
Closed

Support HTML (Ruby - ERB) #80

borisdamato opened this issue Sep 8, 2014 · 9 comments
Assignees
Labels

Comments

@borisdamato
Copy link

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?

@Glavin001 Glavin001 added the bug label Sep 8, 2014
@Glavin001
Copy link
Owner

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.

@Glavin001 Glavin001 self-assigned this Sep 8, 2014
@Glavin001
Copy link
Owner

@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.

@Glavin001
Copy link
Owner

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 Glavin001 added feature and removed bug labels Sep 8, 2014
@Glavin001 Glavin001 changed the title Support html.erb Support HTML (Ruby - ERB) Sep 8, 2014
@borisdamato
Copy link
Author

@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

@Glavin001
Copy link
Owner

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 👍.

@borisdamato
Copy link
Author

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

@Glavin001
Copy link
Owner

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!

@Glavin001
Copy link
Owner

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

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

    <html xmlns="https://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"
    "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <html xmlns="https://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 👍.

@Glavin001
Copy link
Owner

Published to v0.8.0

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

No branches or pull requests

2 participants