nebulab/erb-formatter

Ignore Front Matter

cseelus opened this issue · 8 comments

Static site generators like Bridgetown or Middleman, usually utilize some kinds of Front Matter, like

---
layout: post
title: Blogging Like a Hacker
---

Unfortunately erb-format will convert it to this, which doesn't work anymore:

--- layout: post title: Blogging Like a Hacker ---

Using a hash based syntax almost works …

---<%
{
  layout: :post,
  title: 'Blogging Like a Hacker'
}
%>---

but will also get destroyed upon formating:

---<% {
  layout: :post,
  title: 'Blogging Like a Hacker'
} %>
---

Is there any known workaround for this problem, like the # rubocop:disable all comment, which can be added to enclose lines that should be ignored? Would be happy to add this info to the README, if requested.

elia commented

@cseelus added #12, can you please try it out and check if there are any issues?

It looks like all lines of the front matter still get merged into one, so for example this test file …

---
layout: default
---

<h1 class="text-4xl mb-12"><%= resource.data.title %></h1>

  <div class="mx-auto lg:mx-48 xl:mx-72 2xl:mx-96">
    <%= yield %>
          </div>

… will be formatted correctly, except for the front matter:

Screenshot 2023-01-17 at 14 17 57

elia commented

Maybe you tried with the installed version or one from master? Seems to be working here:

⤑ pbpaste | erb-format --stdin
---
layout: default
---

<h1 class="text-4xl mb-12"><%= resource.data.title %></h1>

<div class="mx-auto lg:mx-48 xl:mx-72 2xl:mx-96">
  <%= yield %>
</div>

Weird, I cloned this repo (since I created a PR for a --version cmd line flag) and used this one.

Seems to not have picked up your commit/force push from ~10 minutes ago (which look like they should do the trick), will give it another try this afternoon:

Screenshot 2023-01-17 at 14 32 26

Screenshot 2023-01-17 at 14 32 48

Your new changes from elia/front-matter seem to work great now, tested a bunch of files.

A improvement would be, to keep a blank line between the front matter and the actual eruby stuff, like in this or that example.

Before:

---
layout: page
title: About
---

<p>This is the basic Bridgetown (BT) site template. You can find out more info about customizing your Bridgetown site, as well as basic Bridgetown usage documentation at [bridgetownrb.com](https://bridgetownrb.com/)</p>

After:

$ erb-format src/about.erb --no-write
---
layout: page
title: About
---
<p>This is the basic Bridgetown (BT) site template. You can find out more info
  about customizing your Bridgetown site, as well as basic Bridgetown usage
  documentation at [bridgetownrb.com](https://bridgetownrb.com/)</p>

One other thing, since I couldn't find anything in the docs: The max line length can only be set indirectly via RuboCop::Cop::Layout::LineLength#max?

elia commented

One other thing, since I couldn't find anything in the docs: The max line length can only be set indirectly via RuboCop::Cop::Layout::LineLength#max?

Does #13 solve?

elia commented

Pushed an update that will add an extra newline, good call 👍

Newline-update works as expected 👌

Would be cool if one could disable forced line breaks altogether via #13.

I'm on the road now with a smaller screen and those newlines can mess things up:

Before running erb-format:
Screenshot 2023-01-17 at 16 36 24

After:
Screenshot 2023-01-17 at 16 36 40