From 6c79cede061eee0f257be5a118d0a1237d05089a Mon Sep 17 00:00:00 2001 From: nakamura Date: Wed, 26 Mar 2025 08:59:01 +0000 Subject: [PATCH] split show template --- .../application/_resource_group.html.erb | 9 ++++++ .../_resource_group_layout.html.erb | 16 +++++++++++ .../application/_resource_item.html.erb | 1 + .../_resource_item_layout.html.erb | 10 +++++++ .../administrate/application/show.html.erb | 28 +++++-------------- 5 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 app/views/administrate/application/_resource_group.html.erb create mode 100644 app/views/administrate/application/_resource_group_layout.html.erb create mode 100644 app/views/administrate/application/_resource_item.html.erb create mode 100644 app/views/administrate/application/_resource_item_layout.html.erb diff --git a/app/views/administrate/application/_resource_group.html.erb b/app/views/administrate/application/_resource_group.html.erb new file mode 100644 index 0000000000..70c36ad2f7 --- /dev/null +++ b/app/views/administrate/application/_resource_group.html.erb @@ -0,0 +1,9 @@ +<% attributes = resource_group.second %> + +<%= render( + partial: 'resource_item', + layout: 'resource_item_layout', + collection: attributes, + as: :attribute, + locals: local_assigns +) %> diff --git a/app/views/administrate/application/_resource_group_layout.html.erb b/app/views/administrate/application/_resource_group_layout.html.erb new file mode 100644 index 0000000000..68fa82189e --- /dev/null +++ b/app/views/administrate/application/_resource_group_layout.html.erb @@ -0,0 +1,16 @@ +<% group_title = resource_group.first %> + +<% if group_title.present? %> + <%# grouped attributes: { title => attributes } %> +
+ <%= t "helpers.label.#{page.resource_name}.#{group_title}", default: group_title %> +
+ <%= yield %> +
+
+<% else %> + <%# non-grouped attributes: { "" => attributes } %> +
+ <%= yield %> +
+<% end %> diff --git a/app/views/administrate/application/_resource_item.html.erb b/app/views/administrate/application/_resource_item.html.erb new file mode 100644 index 0000000000..8d8451733a --- /dev/null +++ b/app/views/administrate/application/_resource_item.html.erb @@ -0,0 +1 @@ +<%= render_field attribute, page: page %> diff --git a/app/views/administrate/application/_resource_item_layout.html.erb b/app/views/administrate/application/_resource_item_layout.html.erb new file mode 100644 index 0000000000..42897fd417 --- /dev/null +++ b/app/views/administrate/application/_resource_item_layout.html.erb @@ -0,0 +1,10 @@ +
+ <%= t( + "helpers.label.#{resource_name}.#{attribute.name}", + default: page.resource.class.human_attribute_name(attribute.name), + ) %> +
+ +
+ <%= yield %> +
diff --git a/app/views/administrate/application/show.html.erb b/app/views/administrate/application/show.html.erb index e12fe87f7b..4d1ae66163 100644 --- a/app/views/administrate/application/show.html.erb +++ b/app/views/administrate/application/show.html.erb @@ -50,27 +50,13 @@ as well as a link to its edit page. <%= content_for(:main) %> <% else %>
-
- <% page.attributes.each do |title, attributes| %> -
"> - <% if title.present? %> - <%= t "helpers.label.#{page.resource_name}.#{title}", default: title %> - <% end %> - - <% attributes.each do |attribute| %> -
- <%= t( - "helpers.label.#{resource_name}.#{attribute.name}", - default: page.resource.class.human_attribute_name(attribute.name), - ) %> -
- -
<%= render_field attribute, page: page %>
- <% end %> -
- <% end %> -
+ <%= render( + partial: 'resource_group', + layout: 'resource_group_layout', + collection: page.attributes.to_a, + as: :resource_group, + locals: local_assigns + ) %>
<% end %>