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

Should we provide shorthand methods or be more DSL-like with more magic? #10

Closed
andrewculver opened this issue Feb 11, 2021 · 0 comments · Fixed by #57
Closed

Should we provide shorthand methods or be more DSL-like with more magic? #10

andrewculver opened this issue Feb 11, 2021 · 0 comments · Fixed by #57
Assignees

Comments

@andrewculver
Copy link
Contributor

andrewculver commented Feb 11, 2021

For example, this is my current new.html.erb:

<%= render 'account/shared/page' do |p| %>
  <% p.content_for :title, t('.section') %>
  <% p.content_for :body do %>
    <%= render 'account/shared/box', divider: true do |p| %>
      <% p.content_for :title, t('.header') %>
      <% p.content_for :description, t('.description') %>
      <% p.content_for :body do %>
        <%= render 'form', tangible_thing: @tangible_thing %>
      <% end %>
    <% end %>
  <% end %>
<% end %>

This is great because it plays on the natural language of Rails partials, but...

Potential Suggestion 1

Is there a place for a shorthand like this when invoking a nice partial?

<%= render 'account/shared/page' do |p| %>
  <% p.cf :title, t('.section') %>
  <% p.cf :body do %>
    <%= render 'account/shared/box', divider: true do |p| %>
      <% p.cf :title, t('.header') %>
      <% p.cf :description, t('.description') %>
      <% p.cf :body do %>
        <%= render 'form', tangible_thing: @tangible_thing %>
      <% end %>
    <% end %>
  <% end %>
<% end %>

This isn't un-Railsy, given how often content_for is invoked. I mean, we have t as an example of this sort of shorthand in Rails.

Potential Suggestion 2

Is it ugly/confusing/undesirable to go full magic like this? Reminds me a little bit of FactoryBot's syntax/DSL.

<%= render 'account/shared/page' do |p| %>
  <% p.title t('.section') %>
  <% p.body do %>
    <%= render 'account/shared/box', divider: true do |p| %>
      <% p.title t('.header') %>
      <% p.description t('.description') %>
      <% p.body do %>
        <%= render 'form', tangible_thing: @tangible_thing %>
      <% end %>
    <% end %>
  <% end %>
<% end %>
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.

1 participant