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:]]' ```
38 lines
1.4 KiB
Plaintext
38 lines
1.4 KiB
Plaintext
<%# locals: (name: nil, label: nil, type: "text", value: nil, attributes: {}, extra_class: nil, button_title: nil) %>
|
|
<% value = flash.dig("old", name) || value
|
|
error = rodauth.field_error(name) || flash.dig("errors", name) %>
|
|
|
|
<div class="space-y-2 text-gray-900">
|
|
<% if label %>
|
|
<label for="<%= name %>" class="block text-sm font-medium leading-6"><%= label %></label>
|
|
<% end %>
|
|
<div class="flex gap-x-2">
|
|
<input
|
|
id="<%= name %>"
|
|
type="<%= type %>"
|
|
name="<%= name %>"
|
|
<% if value %>
|
|
value="<%= value %>"
|
|
<% end %>
|
|
class="block w-full rounded-md border-0 py-1.5 pl-3 pr-10 shadow-sm ring-1 ring-inset focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6 <%= error ? "text-red-900 ring-red-300 placeholder:text-red-300 focus:ring-red-500" : "text-gray-900 ring-gray-300 placeholder:text-gray-400 focus:ring-orange-600"%> <%= extra_class %>"
|
|
<% attributes.each do |atr_key, atr_value| %>
|
|
<%= atr_key %>="<%= atr_value %>"
|
|
<% end%>
|
|
>
|
|
<% if button_title %>
|
|
<%== part("components/form/submit_button", text: button_title) %>
|
|
<% end %>
|
|
</div>
|
|
<% if error %>
|
|
<% if error.is_a?(Array) %>
|
|
<p class="text-sm text-red-600 leading-6" id="<%= name %>-error">
|
|
<% error.each do |e| %>
|
|
<%= e %><br/>
|
|
<% end %>
|
|
</p>
|
|
<% else %>
|
|
<p class="text-sm text-red-600 leading-6" id="<%= name %>-error"><%= error %></p>
|
|
<% end %>
|
|
<% end %>
|
|
</div>
|