Skip to content

Commit d043caf

Browse files
committed
Upgrade to tailwind 4
TailwindCSS 4 and its rails integration include some breaking changes. This adjusts the installation generator to work with that. Also includes a custom form builder, because tailwind's form plugin is no longer bundled.
1 parent c3c0359 commit d043caf

File tree

9 files changed

+41
-21
lines changed

9 files changed

+41
-21
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ ask if it should also install the `fasp_data_sharing` engine. This is
4141
only needed for discovery FASP that want to implement the `data_sharing`
4242
capability.
4343

44+
It will try to overwrite `app/views/layout/application.html.erb` and
45+
`app/assets/tailwind/application.css`. Confirm both unless you want to
46+
start from scratch with you own markup and possibly CSS.
47+
4448
Once all the generators have finished this should leave you with a
4549
working rails application. Just run `bin/dev` and have a look at
4650
`http://localhost:3000`.

fasp_base/app/controllers/fasp_base/application_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ class ApplicationController < ActionController::Base
55
helper Rails.application.helpers
66

77
layout "layouts/application"
8+
9+
default_form_builder FaspBase::FormBuilder
810
end
911
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module FaspBase
2+
class FormBuilder < ActionView::Helpers::FormBuilder
3+
INPUT_CLASSES = %w(px-2 py-1 border border-blue-400 text-base)
4+
5+
def text_field(method, options = {})
6+
options[:class] = [options[:class], INPUT_CLASSES].compact.join(" ")
7+
super
8+
end
9+
10+
def email_field(method, options = {})
11+
options[:class] = [options[:class], INPUT_CLASSES].compact.join(" ")
12+
super
13+
end
14+
15+
def password_field(method, options = {})
16+
options[:class] = [options[:class], INPUT_CLASSES].compact.join(" ")
17+
super
18+
end
19+
20+
def url_field(method, options = {})
21+
options[:class] = [options[:class], INPUT_CLASSES].compact.join(" ")
22+
super
23+
end
24+
end
25+
end

fasp_base/app/helpers/fasp_base/application_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module FaspBase
22
module ApplicationHelper
3-
ALERT_CLASSES = "mt-1 mb-2 rounded px-4 py-2 text-gray-600 font-medium"
3+
ALERT_CLASSES = "mt-1 mb-2 rounded-sm px-4 py-2 text-gray-600 font-medium"
44
ALERT_COLORS = {
55
notice: "border-blue-400 bg-blue-50",
66
alert: "border-red-400 bg-red-50"
77
}.freeze
8-
BUTTON_CLASSES = "font-bold rounded px-4 py-2"
8+
BUTTON_CLASSES = "font-bold rounded-sm px-4 py-2"
99

1010
def notification(message, type: :notice)
1111
tag.div(message, class: "#{ALERT_CLASSES} #{ALERT_COLORS[type]}")
@@ -29,7 +29,7 @@ def button_link_to(*args, **kwargs, &block)
2929
end
3030

3131
def nav_link_to(*args, **kwargs)
32-
link_to(*args, **(kwargs.merge(class: "text-gray-600 font-medium px-2 py-1 rounded hover:bg-blue-200 hover:text-gray-700")))
32+
link_to(*args, **(kwargs.merge(class: "text-gray-600 font-medium px-2 py-1 rounded-sm hover:bg-blue-200 hover:text-gray-700")))
3333
end
3434

3535
def button(type: :button, &block)

fasp_base/app/views/fasp_base/servers/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<p class="my-2 font-bold"><%=t ".key_fingerprint" %></p>
88

9-
<code class="block my-2 rounded p-2 font-mono bg-gray-200">
9+
<code class="block my-2 rounded-sm p-2 font-mono bg-gray-200">
1010
<%= @server.fasp_public_key_fingerprint %>
1111
</code>
1212

fasp_base/lib/generators/fasp_base/install/install_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def install
1111
copy_file "initializers/fasp_base.rb", "config/initializers/fasp_base.rb"
1212
copy_file "config/tailwind.config.js", "config/tailwind.config.js"
1313
copy_file "layouts/application.html.erb", "app/views/layouts/application.html.erb"
14+
copy_file "tailwind/application.css", "app/assets/tailwind/application.css"
1415

1516
inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do
1617
" include FaspBase::Authentication\n\n"
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const defaultTheme = require('tailwindcss/defaultTheme')
21
const execSync = require('child_process').execSync
32

43
let content = [
@@ -12,25 +11,12 @@ const gems = ['fasp_base']
1211

1312
gems.forEach((gem) => {
1413
const gemPath = execSync(`bundle show ${gem}`, { encoding: 'utf-8' }).trim()
14+
content.push(`${gemPath}/app/form_builder/**/*.rb`)
1515
content.push(`${gemPath}/app/helpers/**/*.rb`)
1616
content.push(`${gemPath}/app/javascript/**/*.js`)
1717
content.push(`${gemPath}/app/views/**/*.{erb,haml,html,slim}`)
1818
})
1919

20-
console.log(content)
21-
2220
module.exports = {
23-
content: content,
24-
theme: {
25-
extend: {
26-
fontFamily: {
27-
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
28-
},
29-
},
30-
},
31-
plugins: [
32-
require('@tailwindcss/forms'),
33-
require('@tailwindcss/typography'),
34-
require('@tailwindcss/container-queries'),
35-
]
21+
content: content
3622
}

fasp_base/lib/generators/fasp_base/install/templates/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<link rel="icon" href="/icon.png" type="image/png">
1414
<link rel="icon" href="/icon.svg" type="image/svg+xml">
1515
<link rel="apple-touch-icon" href="/icon.png">
16-
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
16+
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
1717
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
1818
<%= javascript_importmap_tags %>
1919
</head>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@import "tailwindcss";
2+
@config "../../../config/tailwind.config.js";

0 commit comments

Comments
 (0)