Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/templates/erb/scaffold/_form.html.erb.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
<%%= f.error_notification %>
<%%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<%%= render 'shared/errors', resource: @<%= singular_table_name %> if @<%= singular_table_name %>.errors.any? %>

<div class="row">
<%% @<%= singular_table_name %>.attribute_names.reject { |a| ["id", "created_at", "updated_at"].include?(a) }.each do |attr| %>
Expand All @@ -10,11 +10,13 @@
<%% end %>
</div>

<div class="form-actions mt-3">
<% if @<%= singular_table_name %>.persisted? && current_user.super_user? %>
<%%= link_to "Delete", @<%= singular_table_name %>, method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-outline-danger" %>
<% end %>
<%%= link_to "Cancel", <%= plural_table_name %>_path, class: "btn btn-outline-secondary" %>
<%%= f.button :submit, class: "btn btn-outline-primary ms-2" %>
<div class="form-actions flex justify-end gap-4 mt-3">
<%% if @<%= singular_table_name %>.persisted? && current_user.super_user? %>
<%%= link_to_button "Delete", @<%= singular_table_name %>, method: :delete, variant: :danger_outline, data: { confirm: "Are you sure?" } %>
<%% end %>
<%%= link_to_button "Cancel", <%= plural_table_name %>_path, variant: :secondary_outline %>
<%%= f.button :submit, class: 'inline-flex items-center gap-2 px-4 py-2 rounded-lg
transition-colors duration-200 font-medium shadow-sm text-sm
border border-blue-600 text-grey-600 hover:bg-blue-600 hover:text-white' %>
</div>
<%% end %>
14 changes: 10 additions & 4 deletions lib/templates/erb/scaffold/edit.html.erb.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<div class="row">
<div class="col-md-12">
<h2>Edit <%%= @<%= singular_table_name %>.class.model_name.human %></h2>
<%%= render "form", locals: { <%= singular_table_name %>: @<%= singular_table_name %> } %>
<div class="w-full">
<div class="flex items-start justify-between mb-6">
<div class="pr-6">
<h1 class="text-2xl font-semibold text-gray-900 mb-2">Edit <%%= @<%= singular_table_name %>.class.model_name.human %></h1>
<div class="border-b border-gray-300 mb-6"></div>
<div class="mt-4 pt-4">
<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %>
</div>
</div>
<%%= link_to_button 'View', <%= singular_table_name %>_path(@<%= singular_table_name %>), variant: :secondary_outline %>
</div>
</div>
81 changes: 48 additions & 33 deletions lib/templates/erb/scaffold/index.html.erb.tt
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
<div class="col-md-12">
<div class="row">
<div class="col-md-9 col-lg-8 width">
<div class="entry-content">
<h2 class="normal"><%%= <%= plural_table_name.classify %>.model_name.human.pluralize %></h2>
</div>
<div class="w-full px-4">
<!-- Header -->
<div class="flex items-center justify-between mb-6">
<div>
<h2 class="text-2xl font-semibold text-gray-900"><%%= <%= plural_table_name.classify %>.model_name.human.pluralize %></h2>
</div>
<div class="col-md-3 col-lg-4 width">
<div class="entry-content">
<%%= link_to 'New ' + <%= singular_table_name.classify %>.model_name.human, new_<%= singular_table_name %>_path, class: "btn btn-outline-primary" %>
</div>
<div>
<%%= link_to_button('New ' + <%= singular_table_name.classify %>.model_name.human.downcase,
new_<%= singular_table_name %>_path,
variant: :primary_outline) %>
</div>
</div>
</div>

<div class="col-md-12">
<table class="table table-striped table-bordered table-responsive">
<thead>
<tr>
<%% attributes = @<%= plural_table_name %>.first.attributes.keys if @<%= plural_table_name %>.any? %>
<%% attributes&.each do |attribute| %>
<th><%%= attribute.humanize %></th>
<%% end %>
<th>Edit</th>
</tr>
</thead>
<div class="border-b border-gray-300 mb-6"></div>

<tbody>
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<!-- Table -->
<div class="overflow-x-auto">
<table class="min-w-full table-auto border-collapse border border-gray-200">
<thead class="bg-gray-100">
<%% if @<%= plural_table_name %>.any? %>
<tr>
<%% attributes.each do |attribute| %>
<td><%%= <%= singular_table_name %>[attribute] %></td>
<%% attributes = @<%= plural_table_name %>.first.attributes.keys - ["id", "created_at", "updated_at"] if @<%= plural_table_name %>.any? %>
<%% attributes&.each do |attribute| %>
<th class="px-4 py-2 text-left text-sm font-semibold text-gray-700"><%%= attribute.humanize %></th>
<%% end %>
<td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td>
<th class="px-4 py-2 text-left text-sm font-semibold text-gray-700">Edit</th>
</tr>
<%% end %>
</tbody>
</table>
<%% end %>
</thead>

<tbody class="divide-y divide-gray-200">
<%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
<tr class="hover:bg-gray-50 transition-colors duration-150">
<%% attributes.each do |attribute| %>
<td class="px-4 py-2 text-sm text-gray-800">
<%%= <%= singular_table_name %>[attribute] %>
</td>
<%% end %>
<td class="px-4 py-2 flex gap-2">
<%%= link_to_button 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>),
variant: :secondary_outline %>
</td>
</tr>
<%% end %>
</tbody>
</table>
</div>

<!-- Empty state -->
<%% unless @<%= plural_table_name %>.any? %>
<p class="text-gray-500 text-center py-6">No <%%= <%= plural_table_name.classify %>.model_name.human.pluralize %> found.</p>
<%% end %>

<div class="text-center">
<%<%= will_paginate @<%= plural_table_name %>, :previous_label => '<<', :next_label => '>>', :inner_window => 2 %>
<!-- Pagination -->
<div class="flex justify-center mt-6">
<%%= will_paginate @<%= plural_table_name %>, previous_label: '<<', next_label: '>>',
class: 'flex space-x-2' %>
</div>
</div>
11 changes: 6 additions & 5 deletions lib/templates/erb/scaffold/new.html.erb.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="row">
<div class="col-md-12">
<h2>New <%%= @<%= singular_table_name %>.class.model_name.human %></h2>
<%%= render "form", locals: { <%= singular_table_name %>: @<%= singular_table_name %> } %>
<div class="max-w-7xl mx-auto px-4 py-8">
<h1 class="text-3xl font-semibold text-gray-900 mb-4">New <%%= <%= plural_table_name.classify %>.model_name.human %></h1>
<div class="border-b border-gray-300 mb-6"></div>
<div class="mt-4 pt-4">
<%%= render 'form', <%= singular_table_name %>: @<%= singular_table_name %> %>
</div>
</div>
</div>
39 changes: 20 additions & 19 deletions lib/templates/erb/scaffold/show.html.erb.tt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<div class="row mb-3">
<div class="col text-end">
<%%= link_to "Edit", edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: "btn btn-outline-primary" if current_user.super_user? %>
</div>
</div>
<div class="detail py-6 min-h-screen">
<div class="max-w-5xl mx-auto px-4">
<div class="flex justify-end mb-6">
<%%= link_to_button("Index", <%= plural_table_name %>_path, variant: :secondary_outline) %>
<%% if current_user.super_user? %>
<%%= link_to_button("Edit", edit_<%= singular_table_name %>_path, variant: :primary_outline) %>
<%% end %>
</div>
<div class="max-w-3xl mx-auto bg-white border border-gray-200 rounded-xl shadow p-6">
<h1 class="text-2xl font-bold mb-4"><%%= <%= plural_table_name.classify %>.model_name.human %> Details</h1>

<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-3">

<div class="row">
<div class="col-md-12">
<h2><%%= @<%= singular_table_name %>.class.model_name.human %> Details</h2>
<% attributes.each do |attribute| -%>
<div class="mb-3">
<p class="font-bold text-gray-700"><%= attribute.human_name %>:</p>
<p class="text-gray-900"><%%= @<%= singular_table_name %>.<%= attribute.name %> %></p>
</div>
<% end -%>

<table class="table table-striped">
<tbody>
<%% attributes = @<%= singular_table_name %>.attributes.keys if @<%= singular_table_name %> %>
<%% attributes&.each do |attribute| -%>
<tr>
<th><%%= attribute.humanize %></th>
<td><%%= @<%= singular_table_name %>.send(attribute) %></td>
</tr>
<%% end -%>
</tbody>
</table>
</div>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions lib/templates/rails/scaffold_controller/controller.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class <%= controller_class_name %>Controller < ApplicationController
before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]

layout 'tailwind'

def index
per_page = params[:number_of_items_per_page].presence || 25
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>.paginate(page: params[:page], per_page: per_page)
Expand Down