This uses the new part plugin to simplify and optimize render calls with locals. ```ruby render(:template, locals: {foo: 'bar'}) part(:template, foo: 'bar') ``` This simplifies a large number of calls in Clover, since rendering with locals is one of the most common method calls in the templates. The main advantage of this is simplicity, but the part method is also more optimized, and will be even more optimized when we upgrade to Ruby 3.4. Diff best reviewed with: ``` git diff -b --color-words --word-diff-regex='\\w+|[^[:space:]]' ```
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 %>
|