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

Ignore Front Matter #6

Closed
cseelus opened this issue Sep 17, 2022 · 8 comments · Fixed by #12
Closed

Ignore Front Matter #6

cseelus opened this issue Sep 17, 2022 · 8 comments · Fixed by #12

Comments

@cseelus
Copy link
Contributor

cseelus commented Sep 17, 2022

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
Copy link
Member

elia commented Jan 17, 2023

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

@cseelus
Copy link
Contributor Author

cseelus commented Jan 17, 2023

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
Copy link
Member

elia commented Jan 17, 2023

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>

@cseelus
Copy link
Contributor Author

cseelus commented Jan 17, 2023

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

@cseelus
Copy link
Contributor Author

cseelus commented Jan 17, 2023

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
Copy link
Member

elia commented Jan 17, 2023

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
Copy link
Member

elia commented Jan 17, 2023

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

@cseelus
Copy link
Contributor Author

cseelus commented Jan 17, 2023

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

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

Successfully merging a pull request may close this issue.

2 participants