Skip to content

Commit 1c755e4

Browse files
authored
Add config to install ruby_ui with import maps and tailwind 4 (#232)
1 parent 8d3d813 commit 1c755e4

File tree

2 files changed

+175
-13
lines changed

2 files changed

+175
-13
lines changed

lib/generators/ruby_ui/install/install_generator.rb

+22-13
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,32 @@ def add_ruby_ui_module_to_components_base
5252
end
5353
end
5454

55-
def add_tailwind_css
56-
say "Adding RubyUI styles to application css"
57-
template "application.tailwind.css.erb", Rails.root.join("app/assets/stylesheets/application.tailwind.css")
58-
end
59-
6055
def add_tailwind_config
6156
say "Adding RubyUI config to tailwind config"
6257

63-
if File.exist?(Rails.root.join("tailwind.config.js")) # tailwindcss js package
64-
template "tailwind.config.js.js-package.erb", Rails.root.join("tailwind.config.js")
65-
elsif File.exist?(Rails.root.join("config/tailwind.config.js")) # tailwindcss-rails gem
66-
template "tailwind.config.js.tailwindcss-rails.erb", Rails.root.join("config/tailwind.config.js")
58+
if using_tailwindcss_rails_gem?
59+
template "application.css.erb", Rails.root.join("app/assets/tailwind/application.css")
6760
else
68-
say "Cannot find tailwind.config.js. You will need to install tailwind config manually", :red
61+
template "application.tailwind.css.erb", Rails.root.join("app/assets/stylesheets/application.tailwind.css")
6962
end
7063
end
7164

72-
def install_tailwind_animate
73-
say "Installing tailwindcss-animate plugin"
65+
def install_tw_animate_css
66+
say "Installing tw-animate-css plugin"
67+
68+
install_js_package("tw-animate-css")
69+
end
70+
71+
def install_tailwindcss_forms
72+
say "Installing @tailwindcss/forms plugin"
7473

75-
install_js_package("tailwindcss-animate")
74+
install_js_package("@tailwindcss/forms")
75+
end
76+
77+
def install_tailwindcss_typography
78+
say "Installing @tailwindcss/typography plugin"
79+
80+
install_js_package("@tailwindcss/typography")
7681
end
7782

7883
def add_ruby_ui_base
@@ -85,6 +90,10 @@ def add_ruby_ui_base
8590
def gem_installed?(name)
8691
Gem::Specification.find_all_by_name(name).any?
8792
end
93+
94+
def using_tailwindcss_rails_gem?
95+
File.exist?(Rails.root.join("app/assets/tailwind/application.css"))
96+
end
8897
end
8998
end
9099
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
@import "tailwindcss";
2+
@import "../../../vendor/javascript/tw-animate-css.js";
3+
4+
@plugin "@tailwindcss/forms";
5+
@plugin "@tailwindcss/typography";
6+
7+
@custom-variant dark (&:is(.dark *));
8+
9+
:root {
10+
--background: oklch(1 0 0);
11+
--foreground: oklch(0.145 0 0);
12+
--card: oklch(1 0 0);
13+
--card-foreground: oklch(0.145 0 0);
14+
--popover: oklch(1 0 0);
15+
--popover-foreground: oklch(0.145 0 0);
16+
--primary: oklch(0.205 0 0);
17+
--primary-foreground: oklch(0.985 0 0);
18+
--secondary: oklch(0.97 0 0);
19+
--secondary-foreground: oklch(0.205 0 0);
20+
--muted: oklch(0.97 0 0);
21+
--muted-foreground: oklch(0.556 0 0);
22+
--accent: oklch(0.97 0 0);
23+
--accent-foreground: oklch(0.205 0 0);
24+
--destructive: oklch(0.577 0.245 27.325);
25+
--destructive-foreground: oklch(0.577 0.245 27.325);
26+
--border: oklch(0.922 0 0);
27+
--input: oklch(0.922 0 0);
28+
--ring: oklch(0.708 0 0);
29+
--chart-1: oklch(0.646 0.222 41.116);
30+
--chart-2: oklch(0.6 0.118 184.704);
31+
--chart-3: oklch(0.398 0.07 227.392);
32+
--chart-4: oklch(0.828 0.189 84.429);
33+
--chart-5: oklch(0.769 0.188 70.08);
34+
--radius: 0.625rem;
35+
--sidebar: oklch(0.985 0 0);
36+
--sidebar-foreground: oklch(0.145 0 0);
37+
--sidebar-primary: oklch(0.205 0 0);
38+
--sidebar-primary-foreground: oklch(0.985 0 0);
39+
--sidebar-accent: oklch(0.97 0 0);
40+
--sidebar-accent-foreground: oklch(0.205 0 0);
41+
--sidebar-border: oklch(0.922 0 0);
42+
--sidebar-ring: oklch(0.708 0 0);
43+
44+
/* ruby_ui specific */
45+
--warning: hsl(38 92% 50%);
46+
--warning-foreground: hsl(0 0% 100%);
47+
--success: hsl(87 100% 37%);
48+
--success-foreground: hsl(0 0% 100%);
49+
50+
/* Container settings */
51+
--container-center: true;
52+
--container-padding: hsl(2rem);
53+
--container-max-width-2xl: hsl(1400px);
54+
}
55+
56+
.dark {
57+
--background: oklch(0.145 0 0);
58+
--foreground: oklch(0.985 0 0);
59+
--card: oklch(0.145 0 0);
60+
--card-foreground: oklch(0.985 0 0);
61+
--popover: oklch(0.145 0 0);
62+
--popover-foreground: oklch(0.985 0 0);
63+
--primary: oklch(0.985 0 0);
64+
--primary-foreground: oklch(0.205 0 0);
65+
--secondary: oklch(0.269 0 0);
66+
--secondary-foreground: oklch(0.985 0 0);
67+
--muted: oklch(0.269 0 0);
68+
--muted-foreground: oklch(0.708 0 0);
69+
--accent: oklch(0.269 0 0);
70+
--accent-foreground: oklch(0.985 0 0);
71+
--destructive: oklch(0.396 0.141 25.723);
72+
--destructive-foreground: oklch(0.637 0.237 25.331);
73+
--border: oklch(0.269 0 0);
74+
--input: oklch(0.269 0 0);
75+
--ring: oklch(0.439 0 0);
76+
--chart-1: oklch(0.488 0.243 264.376);
77+
--chart-2: oklch(0.696 0.17 162.48);
78+
--chart-3: oklch(0.769 0.188 70.08);
79+
--chart-4: oklch(0.627 0.265 303.9);
80+
--chart-5: oklch(0.645 0.246 16.439);
81+
--sidebar: oklch(0.205 0 0);
82+
--sidebar-foreground: oklch(0.985 0 0);
83+
--sidebar-primary: oklch(0.488 0.243 264.376);
84+
--sidebar-primary-foreground: oklch(0.985 0 0);
85+
--sidebar-accent: oklch(0.269 0 0);
86+
--sidebar-accent-foreground: oklch(0.985 0 0);
87+
--sidebar-border: oklch(0.269 0 0);
88+
--sidebar-ring: oklch(0.439 0 0);
89+
90+
/* ruby_ui specific */
91+
--warning: hsl(38 92% 50%);
92+
--warning-foreground: hsl(0 0% 100%);
93+
--success: hsl(84 81% 44%);
94+
--success-foreground: hsl(0 0% 100%);
95+
}
96+
97+
@theme inline {
98+
--color-background: var(--background);
99+
--color-foreground: var(--foreground);
100+
--color-card: var(--card);
101+
--color-card-foreground: var(--card-foreground);
102+
--color-popover: var(--popover);
103+
--color-popover-foreground: var(--popover-foreground);
104+
--color-primary: var(--primary);
105+
--color-primary-foreground: var(--primary-foreground);
106+
--color-secondary: var(--secondary);
107+
--color-secondary-foreground: var(--secondary-foreground);
108+
--color-muted: var(--muted);
109+
--color-muted-foreground: var(--muted-foreground);
110+
--color-accent: var(--accent);
111+
--color-accent-foreground: var(--accent-foreground);
112+
--color-destructive: var(--destructive);
113+
--color-destructive-foreground: var(--destructive-foreground);
114+
--color-border: var(--border);
115+
--color-input: var(--input);
116+
--color-ring: var(--ring);
117+
--color-chart-1: var(--chart-1);
118+
--color-chart-2: var(--chart-2);
119+
--color-chart-3: var(--chart-3);
120+
--color-chart-4: var(--chart-4);
121+
--color-chart-5: var(--chart-5);
122+
--radius-sm: calc(var(--radius) - 4px);
123+
--radius-md: calc(var(--radius) - 2px);
124+
--radius-lg: var(--radius);
125+
--radius-xl: calc(var(--radius) + 4px);
126+
--color-sidebar: var(--sidebar);
127+
--color-sidebar-foreground: var(--sidebar-foreground);
128+
--color-sidebar-primary: var(--sidebar-primary);
129+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
130+
--color-sidebar-accent: var(--sidebar-accent);
131+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
132+
--color-sidebar-border: var(--sidebar-border);
133+
--color-sidebar-ring: var(--sidebar-ring);
134+
--color-warning: var(--warning);
135+
--color-warning-foreground: var(--warning-foreground);
136+
--color-success: var(--success);
137+
--color-success-foreground: var(--success-foreground);
138+
}
139+
140+
@layer base {
141+
* {
142+
@apply border-border;
143+
}
144+
145+
body {
146+
@apply bg-background text-foreground;
147+
font-feature-settings: "rlig" 1, "calt" 1;
148+
149+
/* docs specific */
150+
/* https://css-tricks.com/snippets/css/system-font-stack/ */
151+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
152+
}
153+
}

0 commit comments

Comments
 (0)