heartcombo / simple_form

Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
http://blog.plataformatec.com.br/tag/simple_form
MIT License
8.21k stars 1.31k forks source link

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

Closed r7kamura closed 1 year ago

r7kamura commented 1 year ago

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 commented 1 year ago

@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

r7kamura commented 1 year ago

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