From 91e870533e89c887050e2ed6785e81d84964d7c5 Mon Sep 17 00:00:00 2001 From: Patricio Mac Adden Date: Fri, 17 Jan 2025 11:00:54 -0300 Subject: [PATCH 1/2] make the index a table again --- .../scaffold/templates/index.html.erb.tt | 38 +++++++++++++------ test/integration/user_journey_test.sh | 2 +- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt index 3d337f95..7c44d03d 100644 --- a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt +++ b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt @@ -2,24 +2,40 @@
<%% if notice.present? %> -

<%%= notice %>

+

<%%= notice %>

<%% end %> -
-

<%= human_name.pluralize %>

+
+

<%= human_name.pluralize %>

<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %>
-
+
<%% if @<%= plural_table_name %>.any? %> - <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %> - <%%= render <%= singular_table_name %> %> -

- <%%= link_to "Show this <%= human_name.downcase %>", <%= model_resource_name(singular_table_name) %>, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %> -

- <%% end %> + + + +<% attributes.reject(&:password_digest?).each do |attribute| -%> + +<% end -%> + + + + + <%% @users.each do |user| %> + +<% attributes.reject(&:password_digest?).each do |attribute| -%> + +<% end -%> + + + <%% end %> + +
<%= attribute.human_name %>Actions
<%%= <%= singular_name %>.<%= attribute.column_name %> %> + <%%= link_to "Show", <%= model_resource_name(singular_table_name) %>, class: "text-blue-600 hover:text-blue-900" %> +
<%% else %> -

No <%= human_name.downcase.pluralize %> found.

+

No <%= human_name.downcase.pluralize %> found.

<%% end %>
diff --git a/test/integration/user_journey_test.sh b/test/integration/user_journey_test.sh index 14f4597a..4f11de93 100755 --- a/test/integration/user_journey_test.sh +++ b/test/integration/user_journey_test.sh @@ -68,7 +68,7 @@ fi # TEST: presence of the generated file bin/rails generate scaffold post title:string body:text published:boolean -grep -q "Show this post" app/views/posts/index.html.erb +grep -q "Show" app/views/posts/index.html.erb # TEST: contents of the css file bin/rails tailwindcss:build[verbose] From f71a89dee7db1f1d57fd1da739894ef0693bddf3 Mon Sep 17 00:00:00 2001 From: Patricio Mac Adden Date: Sun, 19 Jan 2025 23:44:03 -0300 Subject: [PATCH 2/2] revert class reordering, add attachments links to table rows, fix hardcoded vars, add edit and destroy actions to table rows --- .../scaffold/templates/index.html.erb.tt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt index 7c44d03d..7ea54857 100644 --- a/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt +++ b/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt @@ -2,11 +2,11 @@
<%% if notice.present? %> -

<%%= notice %>

+

<%%= notice %>

<%% end %> -
-

<%= human_name.pluralize %>

+
+

<%= human_name.pluralize %>

<%%= link_to "New <%= human_name.downcase %>", new_<%= singular_route_name %>_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %>
@@ -22,20 +22,34 @@ - <%% @users.each do |user| %> + <%% @<%= plural_table_name %>.each do |<%= singular_name %>| %> <% attributes.reject(&:password_digest?).each do |attribute| -%> +<% if attribute.attachment? -%> + <%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %> +<% elsif attribute.attachments? -%> + + <%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %> +
<%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %>
+ <%% end %> + +<% else -%> <%%= <%= singular_name %>.<%= attribute.column_name %> %> +<% end -%> <% end -%> <%%= link_to "Show", <%= model_resource_name(singular_table_name) %>, class: "text-blue-600 hover:text-blue-900" %> + <%%= link_to "Edit", edit_<%= singular_route_name %>_path(<%= singular_table_name %>), class: "text-blue-600 hover:text-blue-900" %> +
+ <%%= button_to "Destroy", <%= model_resource_name %>, method: :delete, class: "text-red-600 hover:text-red-900" %> +
<%% end %> <%% else %> -

No <%= human_name.downcase.pluralize %> found.

+

No <%= human_name.downcase.pluralize %> found.

<%% end %>