Skip to content

Commit e48dc28

Browse files
BakiVernesdixpac
andcommitted
Add Tailwind styled scaffold templates
Co-authored-by: Dino Marić <dino.onex@gmail.com>
1 parent 5e3008b commit e48dc28

File tree

7 files changed

+117
-1
lines changed

7 files changed

+117
-1
lines changed

lib/install/tailwindcss.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
22

33
if APPLICATION_LAYOUT_PATH.exist?
4-
say "Add Tailwindcss include tags in application layout"
4+
say "Add Tailwindcss include tags and container element in application layout"
55
insert_into_file APPLICATION_LAYOUT_PATH.to_s, <<~ERB.indent(4), before: /^\s*<%= stylesheet_link_tag/
66
<%= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %>
77
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
88
ERB
9+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %( <main class="container mx-auto mt-28 px-5 flex">\n ), before: /^\s*<%= yield/
10+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n </main>), after: /^\s*<%= yield %>/
911
else
1012
say "Default application.html.erb is missing!", :red
1113
say %( Add <%= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %> and <%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %> within the <head> tag in your custom layout.)

lib/tailwindcss/engine.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ class Engine < ::Rails::Engine
1919
env.cache = ActiveSupport::Cache.lookup_store(:null_store)
2020
end if Rails.env.production?
2121
end
22+
23+
config.app_generators do |g|
24+
g.templates.unshift File::expand_path('../../templates', __FILE__)
25+
end
2226
end
2327
end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<%%= form_with(model: <%= model_resource_name %>, class: "contents") do |form| %>
2+
<%% if <%= singular_table_name %>.errors.any? %>
3+
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
4+
<h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5+
6+
<ul>
7+
<%% <%= singular_table_name %>.errors.each do |error| %>
8+
<li><%%= error.full_message %></li>
9+
<%% end %>
10+
</ul>
11+
</div>
12+
<%% end %>
13+
14+
<% attributes.each do |attribute| -%>
15+
<div class="field my-5">
16+
<% if attribute.password_digest? -%>
17+
<%%= form.label :password %>
18+
<%%= form.password_field :password %>
19+
</div>
20+
21+
<div class="field my-5">
22+
<%%= form.label :password_confirmation %>
23+
<%%= form.password_field :password_confirmation, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
24+
<% elsif attribute.attachments? -%>
25+
<%%= form.label :<%= attribute.column_name %> %>
26+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
27+
<% else -%>
28+
<%%= form.label :<%= attribute.column_name %> %>
29+
<% if attribute.field_type == :text_area -%>
30+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, rows: 4, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
31+
<% elsif attribute.field_type == :check_box -%>
32+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "block mt-2 h-5 w-5" %>
33+
<% else -%>
34+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
35+
<% end -%>
36+
<% end -%>
37+
</div>
38+
39+
<% end -%>
40+
<div class="actions inline">
41+
<%%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium" %>
42+
</div>
43+
<%% end %>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="mx-auto md:w-2/3 w-full">
2+
<h1 class="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
3+
4+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
5+
6+
<%%= link_to "Show this <%= human_name.downcase %>", @<%= singular_table_name %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
7+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
8+
</div>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<div class="w-full">
2+
<%% if notice.present? %>
3+
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%%= notice %></p>
4+
<%% end %>
5+
6+
<div class="flex justify-between items-center">
7+
<h1 class="text-lg font-bold text-4xl"><%= human_name %></h1>
8+
<%%= link_to 'New <%= human_name.downcase %>', new_<%= singular_route_name %>_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
9+
</div>
10+
11+
<table class="min-w-full">
12+
<thead class="border-b-2 border-gray-200">
13+
<tr class="text-gray-500 uppercase text-left">
14+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
15+
<th class="pt-6 pb-2 font-normal"><%= attribute.human_name %></th>
16+
<% end -%>
17+
</tr>
18+
</thead>
19+
20+
<tbody>
21+
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
22+
<tr class="align-top border-b border-gray-200">
23+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
24+
<td class="py-6 pr-3"><%%= <%= singular_table_name %>.<%= attribute.column_name %> %></td>
25+
<% end -%>
26+
<td class="py-6 pr-3"><%%= link_to 'Show', <%= model_resource_name %>, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %></td>
27+
<td class="py-6 pr-3"><%%= link_to 'Edit', edit_<%= singular_route_name %>_path(<%= singular_table_name %>), class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %></td>
28+
</tr>
29+
<%% end %>
30+
</tbody>
31+
</table>
32+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="mx-auto md:w-2/3 w-full">
2+
<h1 class="text-lg font-bold text-4xl">New <%= human_name.downcase %></h1>
3+
4+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
5+
6+
<%%= link_to 'Back to <%= human_name.pluralize.downcase %>', <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
7+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<div class="mx-auto md:w-2/3 w-full flex">
2+
<div class="mx-auto">
3+
<%% if notice.present? %>
4+
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%%= notice %></p>
5+
<%% end %>
6+
7+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
8+
<p class="my-5">
9+
<strong class="block font-medium mb-1"><%= attribute.human_name %>:</strong>
10+
<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>
11+
</p>
12+
<% end -%>
13+
14+
<%%= link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
15+
<div class="inline-block ml-2">
16+
<%%= button_to 'Delete', <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
17+
</div>
18+
<%%= link_to 'Back', <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
19+
</div>
20+
</div>

0 commit comments

Comments
 (0)