I was investigating changing how we formatted some code, and found that `erb-formatter` also formatted embedded code in disagreement with how `rubocop-erb` does. Such differences in formatting interpretation can cause failure in CI, where committing code produced by `erb-formatter` can fail rubocop. To have investigated this so closely is a lot of effort to achieve nearly nothing. Originally, I intended to change the `Layout/DotPosition` rubocop rule to `trailing`, but where the `syntax_tree` gem used by `erb-formatter` would produce code that *always* format code that would fail Rubocop. I changed my mind late in the process: it was based on a misunderstanding of how `pry` handled multi-line pastes of code with leading `.`, which runs what come after in `sh`. In a multi-line paste, it correctly interprets it as method chaining instead. By then I had made those enhancements to `erb-formatter` and decided to keep them: there's no reason to redundantly format code or expose ourselves to the `syntax_tree` dependency. There is one very small additional change where `erb-formatter` eliminates an extra space now.
33 lines
1.4 KiB
Plaintext
33 lines
1.4 KiB
Plaintext
<%# locals: (text:, type: "primary", link: nil, icon: nil, attributes: {}, extra_class: nil, right_icon: nil) %>
|
|
<% color = BUTTON_COLOR[type] %>
|
|
|
|
<% if link %>
|
|
<a
|
|
href="<%= link %>"
|
|
class="inline-flex items-center justify-center rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 <%= color %> disabled:pointer-events-none disabled:opacity-50 <%= extra_class %>"
|
|
<% attributes.each do |atr_key, atr_value| %>
|
|
<%= atr_key %>="<%= atr_value %>"
|
|
<% end%>
|
|
>
|
|
<% if icon %>
|
|
<%== part("components/icon", name: icon, classes: "h-5 w-5") %>
|
|
<% end %>
|
|
<%= text %>
|
|
</a>
|
|
<% else %>
|
|
<button
|
|
class="inline-flex items-center justify-center rounded-md px-3 py-2 text-sm font-semibold text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 <%= color %> disabled:pointer-events-none disabled:opacity-50 <%= extra_class %>"
|
|
<% attributes.compact.each do |atr_key, atr_value| %>
|
|
<%= atr_key %>="<%= atr_value %>"
|
|
<% end%>
|
|
>
|
|
<% if icon %>
|
|
<%== part("components/icon", name: icon, classes: "h-5 w-5 #{(text && !text.empty?) ? "ml-0.5 mr-1.5" : "mx-0"}") %>
|
|
<% end %>
|
|
<%= text %>
|
|
<% if right_icon %>
|
|
<%== part("components/icon", name: right_icon, classes: "ml-1.5 -mr-1 h-5 w-5") %>
|
|
<% end %>
|
|
</button>
|
|
<% end %>
|