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

Is there any particular reason for the use of %% instead of % in the ERB template? #1811

Closed
r7kamura opened this issue Feb 25, 2023 · 2 comments

Comments

@r7kamura
Copy link

I'm having a little trouble on applying an ERB linter for ERB templates generated by simple_form gem, as the ERB parser provided by better_html doesn't seem to support the <%% ... %%> format.

require 'better_html'
require 'better_html/parser'
require 'parser'

::BetterHtml::Parser.new(
  ::Parser::Source::Buffer.new(
    'example.erb',
    source: '<%% foo %%>'
  ),
  template_language: :html
).ast
# => 
# s(:document,
#   s(:text,
#     s(:erb,
#       s(:indicator, "%"), nil,
#       s(:code, " foo %"), nil)))

Unlike the general ERB format, lib/generators/simple_form/templates/_form.html.erb is using <%% ... %%> instead of <% ... %> format. Is there any particular reason why this format is used here?

@nashby
Copy link
Collaborator

nashby commented Feb 25, 2023

@r7kamura hey, that's not a template itself. It's a template that generates another template that is gonna be used when you do e.g rails g scaffold Post name:string. So looks like someone just copy pasted it directly into their app instead of using generator.

P.S See examples here https://stackoverflow.com/a/40487753/336626

@nashby nashby closed this as completed Feb 25, 2023
@r7kamura
Copy link
Author

I see. Thanks for letting me know, very helpful 👍

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

No branches or pull requests

2 participants