From 2ea6a88e954e400d923e6d5fe765c977c61f7064 Mon Sep 17 00:00:00 2001 From: Bryan Date: Fri, 6 Feb 2026 15:09:03 +0400 Subject: [PATCH] =?UTF-8?q?tailwind=20css,=20d=C3=A9but1=20turbo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/input.css | 8 ++++++- app/controllers/concerns/turbo_controller.js | 9 +++++++ app/controllers/livres_controller.rb | 9 +++++-- app/views/layouts/application.html.erb | 8 ++++--- app/views/livres/form.html.erb | 2 +- app/views/livres/index.html.erb | 25 ++++++++++---------- app/views/livres/new.html.erb | 18 ++++++++------ 7 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 app/controllers/concerns/turbo_controller.js diff --git a/app/assets/stylesheets/input.css b/app/assets/stylesheets/input.css index a461c50..9234003 100644 --- a/app/assets/stylesheets/input.css +++ b/app/assets/stylesheets/input.css @@ -1 +1,7 @@ -@import "tailwindcss"; \ No newline at end of file +@import "tailwindcss"; + +@layer base { + .font-Inter { + font-family: 'Inter', sans-serif; + } +} \ No newline at end of file diff --git a/app/controllers/concerns/turbo_controller.js b/app/controllers/concerns/turbo_controller.js new file mode 100644 index 0000000..0c9200a --- /dev/null +++ b/app/controllers/concerns/turbo_controller.js @@ -0,0 +1,9 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + visit(event) { + event.preventDefault() + Turbo.visit(event.target.dataset.url) + this.element.innerHTML = "" + } +} diff --git a/app/controllers/livres_controller.rb b/app/controllers/livres_controller.rb index 7972d92..c7fa673 100644 --- a/app/controllers/livres_controller.rb +++ b/app/controllers/livres_controller.rb @@ -7,9 +7,14 @@ class LivresController < ApplicationController end end - def new - @livre = Livre.new +def new + @livre = Livre.new + respond_to do |format| + format.html + format.turbo_stream end +end + def create @livre = Livre.new(livre_params) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3ce3d48..d35e0c6 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,8 +2,7 @@ <%= content_for(:title) || "Bibliotheque" %> - - + ... @@ -21,13 +20,16 @@ + + + <%# Includes all stylesheet files in app/assets/stylesheets %> <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> <%= javascript_importmap_tags %> - + <%= yield %> diff --git a/app/views/livres/form.html.erb b/app/views/livres/form.html.erb index c45d27a..5d0e6fc 100644 --- a/app/views/livres/form.html.erb +++ b/app/views/livres/form.html.erb @@ -4,7 +4,7 @@
<%= form.text_field :titre %>
<%= form.text_field :auteur %>
<%= form.date_field :date_de_sortie %>
-
<%= form.submit "Enregistrer", class: "btn" %>
+
<%= form.submit "Enregistrer", class: "shadow-[1px_1px_1px_rgba(0,0,0,0.2)] bg-[#B7E1FF] text-[#0F0F0F] px-3 py-1 rounded-md text-sm hover:bg-[#F6FAFE] transition text-center" %>
<% end %> diff --git a/app/views/livres/index.html.erb b/app/views/livres/index.html.erb index 0eec791..a70a4e9 100644 --- a/app/views/livres/index.html.erb +++ b/app/views/livres/index.html.erb @@ -1,6 +1,6 @@ -

-catalogue de la bibliothèque +

+Catalogue de la bibliothèque

@@ -25,7 +25,7 @@ catalogue de la bibliothèque Nombre total de livres : <%= @livres.count %>

-
+
Titre
Auteur
@@ -36,20 +36,20 @@ catalogue de la bibliothèque <% @livres.each do |livre| %>
-
<%= livre.titre %>
+
<%= livre.titre %>
<%= livre.auteur %>
-
<%= livre.date_de_sortie %>
+
<%= livre.date_de_sortie %>
-
+
<%= link_to "Modifier", edit_livre_path(livre), data: { turbo_frame: "livre_#{livre.id}" }, - class: "shadow-[1px_1px_1px_rgba(0,0,0,0.2)] bg-[#B7E1FF] text-[#0F0F0F] px-3 py-1 rounded-md text-sm hover:bg-[#F6FAFE] transition w-[90px] text-center" %> + class: "shadow-[1px_1px_1px_rgba(0,0,0,0.2)] bg-[#B7E1FF] text-[#0F0F0F] px-0 py-0.5 rounded-md text-sm hover:bg-[#F6FAFE] transition text-center" %> <%= button_to "Supprimer", livre_path(livre), method: :delete, - data: { confirm: "Supprimer ce livre ?" }, - class: "shadow-[1px_1px_1px_rgba(0,0,0,0.2)] bg-[#B7E1FF] text-[#0F0F0F] px-3 py-1 rounded-md text-sm hover:bg-[#F6FAFE] transition w-[90px] text-center" %> + data: { turbo_method: :delete, turbo_confirm: "Supprimer ce livre ?", turbo_frame: "_top" }, + class: "shadow-[1px_1px_1px_rgba(0,0,0,0.2)] bg-[#B7E1FF] text-[#0F0F0F] px-0 py-0.5 rounded-md text-sm hover:bg-[#F6FAFE] transition w-[90px] text-center" %>
@@ -57,7 +57,6 @@ catalogue de la bibliothèque
-

- <%= link_to "Ajouter un nouveau livre", new_livre_path, - class: "text-black underline text-sm hover:text-blue-800 transition" %> -

+ + <%= link_to "Ajouter un nouveau livre", new_livre_path, data: { turbo_frame: "nouveau_livre" } %> + diff --git a/app/views/livres/new.html.erb b/app/views/livres/new.html.erb index 10f602d..072be5f 100644 --- a/app/views/livres/new.html.erb +++ b/app/views/livres/new.html.erb @@ -1,23 +1,27 @@ -

Ajouter un nouveau livre

+ +

AJOUTER UN NOUVEAU

<%= form_with model: @livre, local: true do |form| %> -

- <%= form.label :titre %>
+

+ <%= form.label :titre,class:" font-bold text-gray-800 mb-6 " %>
<%= form.text_field :titre %>

- <%= form.label :auteur %>
+ <%= form.label :auteur,class:" font-bold text-gray-800 mb-6 " %>
<%= form.text_field :auteur %>

- <%= form.label :date_de_sortie, "Date de sortie" %>
+ <%= form.label :date_de_sortie,class:" font-bold text-gray-800 mb-6 " %>
<%= form.date_field :date_de_sortie %>

- +
<%= form.submit "Créer le livre" %> +
+ <% end %> -

<%= link_to "← Retour au catalogue", livres_path %>

+

<%= link_to "← Fermer l'éditeur", livres_path %>

+