Skip to content

Commit

Permalink
Merge pull request #4113 from rubygems/segiddins/tailwind
Browse files Browse the repository at this point in the history
POC adding tailwind
  • Loading branch information
indirect authored Oct 19, 2023
2 parents 885f10e + cd310b6 commit a75f418
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ coverage
REVISION
/.env*
/doc/erd.*

/app/assets/builds/*
!/app/assets/builds/.keep
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ gem "groupdate", "~> 6.2"
gem "amazing_print", "~> 1.4"
gem "rails_semantic_logger", "~> 4.11"

group :assets, :development do
gem "tailwindcss-rails", "~> 2.0"
end

group :assets do
gem "dartsass-sprockets", "~> 3.0"
gem "terser", "~> 1.1"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ GEM
activesupport (>= 3)
attr_required (>= 0.0.5)
httpclient (>= 2.4)
tailwindcss-rails (2.0.30)
railties (>= 6.0.0)
terser (1.1.18)
execjs (>= 0.3.0, < 3)
thor (1.3.0)
Expand Down Expand Up @@ -779,6 +781,7 @@ DEPENDENCIES
sprockets-rails (~> 3.4)
statsd-instrument (~> 3.5)
strong_migrations (~> 1.6)
tailwindcss-rails (~> 2.0)
terser (~> 1.1)
toxiproxy (~> 2.0)
unpwn (~> 1.0)
Expand Down
Empty file added app/assets/builds/.keep
Empty file.
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//= link application.css
//= link application.js
//= link_tree ../../../vendor/assets/images
//= link_tree ../builds
3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.tailwind.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @tailwind base; */ /* base disabled because the resets break the current site */
@tailwind components;
@tailwind utilities;
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

<%= stylesheet_link_tag("application") %>
<%= stylesheet_link_tag("tailwind", "data-turbo-track": "reload") %>
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
<link href='https://fonts.googleapis.com/css?family=Roboto:100&amp;subset=greek,latin,cyrillic,latin-ext' rel='stylesheet' type='text/css'>
<%= render "layouts/feeds" %>
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/zeitwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

Rails.autoloaders.main.ignore(Rails.root.join("lib/cops"))

Rails.autoloaders.main.ignore(Rails.root.join("lib/puma/plugin"))

Rails.autoloaders.once.inflector.inflect(
"http" => "HTTP",
"oidc" => "OIDC"
Expand Down
3 changes: 3 additions & 0 deletions config/puma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart

require_relative "../lib/puma/plugin/tailwind"
plugin :tailwind
end

# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
Expand Down
41 changes: 41 additions & 0 deletions config/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const defaultTheme = require("tailwindcss/defaultTheme");

/** @type {import('tailwindcss').Config} */
module.exports = {
mode: "jit",
prefix: "tw-", // While we still have non-tailwind classes
content: [
"./app/views/**/*.rb",
"./app/components/**/*rb",
"./public/*.html",
"./app/helpers/**/*.rb",
"./app/javascript/**/*.js",
"./app/views/**/*.{erb,haml,html,slim,rb}",
],
theme: {
extend: {
fontFamily: {
sans: [
"Helvetica Neue",
"Helvetica",
"Arial",
...defaultTheme.fontFamily.sans,
],
},
colors: {
"rubygems-red": "#e74c3c",
blackish: "#141c22",
grayish: "#c1c4ca",
},
},
},
plugins: [
require("@tailwindcss/forms"),
require("@tailwindcss/aspect-ratio"),
require("@tailwindcss/typography"),
require("@tailwindcss/container-queries"),
],
corePlugins: {
preflight: false,
},
};
17 changes: 17 additions & 0 deletions lib/puma/plugin/tailwind.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "puma/plugin"

Puma::Plugin.create do
def start(launcher)
in_background do
warn "Starting TailwindCSS watcher..."
system(
File.expand_path("../../../bin/rails", __dir__), "--trace", "tailwindcss:watch", "RAILS_GROUPS=assets",
%i[out err] => File.expand_path("../../../log/tailwind.log", __dir__),
exception: true
)
rescue StandardError => e
warn e.full_message(highlight: true)
launcher.restart
end
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "simplecov"
SimpleCov.start "rails" do
add_filter "lib/tasks"
add_filter "lib/puma/plugin"
add_filter "lib/rails_development_log_formatter.rb"

# Will be deleted after all the delayed jobs have run
Expand Down

0 comments on commit a75f418

Please sign in to comment.