tailwindcss-rails 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -10
- data/app/assets/stylesheets/tailwind.css +13 -1
- data/lib/generators/tailwindcss/scaffold/scaffold_generator.rb +34 -0
- data/lib/generators/tailwindcss/scaffold/templates/_form.html.erb.tt +43 -0
- data/lib/generators/tailwindcss/scaffold/templates/edit.html.erb.tt +8 -0
- data/lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt +14 -0
- data/lib/generators/tailwindcss/scaffold/templates/new.html.erb.tt +7 -0
- data/lib/generators/tailwindcss/scaffold/templates/partial.html.erb.tt +22 -0
- data/lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt +15 -0
- data/lib/install/tailwindcss.rb +13 -3
- data/lib/tailwindcss/engine.rb +4 -0
- data/lib/tailwindcss/purger.rb +2 -2
- data/lib/tailwindcss/version.rb +1 -1
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efa9c7fbb61dc459247b3af68e46e47b8c002d925635d27e9ed48d0b6f8d6597
|
4
|
+
data.tar.gz: f4126ae45ea113f4a915308accabd4d7467fc6de364ec68fe412a8ae540d3942
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1a0c5c9d258f268f109d780a0c0b12f87779557ec859b1f50e94b602de607e0edbc99d93ce18498a3855c19dea5e0b9ea11c88dff15bc813650b0ba7f330ec1
|
7
|
+
data.tar.gz: 4c6a0bb1fdead9026be4934083af4e49ef053dcc4d1f1aead35d1db024cb4a01268784732287ac333689a936df53dc013082f6cce2b5d85ab958aefcc9e53e5c
|
data/README.md
CHANGED
@@ -2,30 +2,26 @@
|
|
2
2
|
|
3
3
|
[Tailwind CSS](https://tailwindcss.com) is a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.
|
4
4
|
|
5
|
-
This gem
|
5
|
+
This gem gives access to the standard Tailwind CSS framework configured for dark mode, forms, aspect-ratio, typography, and the Inter font via the asset pipeline using Sprockets. If you need to customize Tailwind, you will need to install it the traditional way using [Webpacker](https://github.com/rails/webpacker) instead or use webpacker port of this gem [tailwindcss-rails-webpacker](https://github.com/WizardComputer/tailwindcss-rails-webpacker).
|
6
6
|
|
7
|
-
Production-mode purging of unused css class names is provided by a Sprockets compressor built into this gem. This compressor ensures that only the css classes used by files in `app/views` and `app/helpers` are included. In development mode, the full
|
8
|
-
|
9
|
-
In both cases, Tailwind CSS is configured for dark mode, forms, aspect-ratio, typography, and the Inter font. If you need more configuration than that, you'll need to use it with Webpacker.
|
7
|
+
Production-mode purging of unused css class names is provided by a Sprockets compressor built into this gem. This compressor ensures that only the css classes used by files in `app/views` and `app/helpers` are included. In development mode, the full 7mb+ Tailwind stylesheet is loaded.
|
10
8
|
|
11
9
|
|
12
10
|
## Installation
|
13
11
|
|
14
12
|
1. Run `./bin/bundle add tailwindcss-rails`
|
15
|
-
2. Run `./bin/rails tailwindcss:install`
|
13
|
+
2. Run `./bin/rails tailwindcss:install`
|
16
14
|
|
17
15
|
The last step adds the purger compressor to `config/environments/production.rb`. This ensures that when `assets:precompile` is called during deployment that the unused class names are not included in the tailwind output css used by the app. It also adds a `stylesheet_link_tag "tailwind"` and `stylesheet_link_tag "inter-font"` to your `app/views/layouts/application.html.erb` file.
|
18
16
|
|
19
17
|
You can do these things yourself, if you've changed the default setup.
|
20
18
|
|
21
|
-
Note: You should ensure to delete `app/assets/stylesheets/scaffolds.scss` that Rails adds after running a scaffold command, if you had run this generator before installing Tailwind CSS for Rails. This stylesheet will interfere with Tailwind's reset of base styles. This gem will turn off stylesheet generation for all future scaffold runs.
|
22
|
-
|
23
19
|
|
24
20
|
## Purging in production
|
25
21
|
|
26
|
-
The Tailwind CSS framework starts out as a massive file, which gives you all the combinations of utility classes for development, but you wouldn't want to ship all those unused classes in production. So this gem
|
22
|
+
The Tailwind CSS framework starts out as a massive file, which gives you all the combinations of utility classes for development, but you wouldn't want to ship all those unused classes in production. So the Sprockets compressor included in this gem is used to purge the tailwind file from all those unused classes for production.
|
27
23
|
|
28
|
-
This compressor is currently not compatible with the default Sprockets cache system due to the fact its output depends on files outside of Sprockets (all the files observed for utility class name usage), so this cache is disabled in production. If you need to disable it in other deployed environments, add the following to that environment configuration file:
|
24
|
+
Note: This compressor is currently not compatible with the default Sprockets cache system due to the fact its output depends on files outside of Sprockets (all the files observed for utility class name usage), so this cache is disabled in production. If you need to disable it in other deployed environments, add the following to that environment configuration file:
|
29
25
|
|
30
26
|
```ruby
|
31
27
|
Rails.application.config.assets.configure do |env|
|
@@ -57,7 +53,7 @@ The Tailwind CSS main file that's being used before purging consists of these ve
|
|
57
53
|
* @tailwindcss/forms 0.3.3
|
58
54
|
* @tailwindcss/typography 0.4.1
|
59
55
|
* autoprefixer 10.3.1
|
60
|
-
* tailwindcss 2.2.
|
56
|
+
* tailwindcss 2.2.15
|
61
57
|
|
62
58
|
|
63
59
|
## License
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! tailwindcss v2.2.
|
1
|
+
/*! tailwindcss v2.2.16 | MIT License | https://tailwindcss.com */
|
2
2
|
|
3
3
|
/*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
|
4
4
|
|
@@ -475,6 +475,18 @@ button,
|
|
475
475
|
cursor: pointer;
|
476
476
|
}
|
477
477
|
|
478
|
+
/**
|
479
|
+
* Override legacy focus reset from Normalize with modern Firefox focus styles.
|
480
|
+
*
|
481
|
+
* This is actually an improvement over the new defaults in Firefox in our testing,
|
482
|
+
* as it triggers the better focus styles even for links, which still use a dotted
|
483
|
+
* outline in Firefox by default.
|
484
|
+
*/
|
485
|
+
|
486
|
+
:-moz-focusring {
|
487
|
+
outline: auto;
|
488
|
+
}
|
489
|
+
|
478
490
|
table {
|
479
491
|
border-collapse: collapse;
|
480
492
|
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rails/generators/erb/scaffold/scaffold_generator'
|
2
|
+
require "rails/generators/resource_helpers"
|
3
|
+
|
4
|
+
module Tailwindcss
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
12
|
+
|
13
|
+
def create_root_folder
|
14
|
+
empty_directory File.join("app/views", controller_file_path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def copy_view_files
|
18
|
+
available_views.each do |view|
|
19
|
+
formats.each do |format|
|
20
|
+
filename = filename_with_extensions(view, format)
|
21
|
+
template filename, File.join("app/views", controller_file_path, filename)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
template "partial.html.erb", File.join("app/views", controller_file_path, "_#{singular_table_name}.html.erb")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def available_views
|
30
|
+
%w(index edit show new _form)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<%%= form_with(model: <%= model_resource_name %>, class: "contents") do |form| %>
|
2
|
+
<%% if <%= singular_table_name %>.errors.any? %>
|
3
|
+
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
|
4
|
+
<h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<%% <%= singular_table_name %>.errors.each do |error| %>
|
8
|
+
<li><%%= error.full_message %></li>
|
9
|
+
<%% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<%% end %>
|
13
|
+
|
14
|
+
<% attributes.each do |attribute| -%>
|
15
|
+
<div class="my-5">
|
16
|
+
<% if attribute.password_digest? -%>
|
17
|
+
<%%= form.label :password %>
|
18
|
+
<%%= form.password_field :password %>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div class="my-5">
|
22
|
+
<%%= form.label :password_confirmation %>
|
23
|
+
<%%= form.password_field :password_confirmation, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
|
24
|
+
<% elsif attribute.attachments? -%>
|
25
|
+
<%%= form.label :<%= attribute.column_name %> %>
|
26
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
|
27
|
+
<% else -%>
|
28
|
+
<%%= form.label :<%= attribute.column_name %> %>
|
29
|
+
<% if attribute.field_type == :text_area -%>
|
30
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, rows: 4, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
|
31
|
+
<% elsif attribute.field_type == :check_box -%>
|
32
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "block mt-2 h-5 w-5" %>
|
33
|
+
<% else -%>
|
34
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %>
|
35
|
+
<% end -%>
|
36
|
+
<% end -%>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<% end -%>
|
40
|
+
<div class="inline">
|
41
|
+
<%%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium" %>
|
42
|
+
</div>
|
43
|
+
<%% end %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<div class="mx-auto md:w-2/3 w-full">
|
2
|
+
<h1 class="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
|
3
|
+
|
4
|
+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
5
|
+
|
6
|
+
<%%= link_to "Show this <%= human_name.downcase %>", @<%= singular_table_name %>, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
7
|
+
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
8
|
+
</div>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<div class="w-full">
|
2
|
+
<%% if notice.present? %>
|
3
|
+
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%%= notice %></p>
|
4
|
+
<%% end %>
|
5
|
+
|
6
|
+
<div class="flex justify-between items-center">
|
7
|
+
<h1 class="text-lg font-bold text-4xl"><%= human_name.pluralize %></h1>
|
8
|
+
<%%= link_to 'New <%= human_name.downcase %>', new_<%= singular_route_name %>_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div id="<%= plural_table_name %>" class="min-w-full">
|
12
|
+
<%%= render @<%= plural_table_name %> %>
|
13
|
+
</div>
|
14
|
+
</div>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<div class="mx-auto md:w-2/3 w-full">
|
2
|
+
<h1 class="text-lg font-bold text-4xl">New <%= human_name.downcase %></h1>
|
3
|
+
|
4
|
+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
5
|
+
|
6
|
+
<%%= link_to 'Back to <%= human_name.pluralize.downcase %>', <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
7
|
+
</div>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<div id="<%%= dom_id <%= singular_table_name %> %>">
|
2
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
3
|
+
<p class="my-5">
|
4
|
+
<strong class="block font-medium mb-1"><%= attribute.human_name %>:</strong>
|
5
|
+
<% if attribute.attachment? -%>
|
6
|
+
<%%= link_to <%= singular_table_name %>.<%= attribute.column_name %>.filename, <%= singular_table_name %>.<%= attribute.column_name %> if <%= singular_table_name %>.<%= attribute.column_name %>.attached? %>
|
7
|
+
<% elsif attribute.attachments? -%>
|
8
|
+
<%% <%= singular_table_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
|
9
|
+
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
|
10
|
+
<%% end %>
|
11
|
+
<% else -%>
|
12
|
+
<%%= <%= singular_table_name %>.<%= attribute.column_name %> %>
|
13
|
+
<% end -%>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<% end -%>
|
17
|
+
<%% if action_name != "show" %>
|
18
|
+
<%%= link_to "Show this <%= human_name.downcase %>", <%= singular_table_name %>, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
19
|
+
<%%= link_to 'Edit this <%= human_name.downcase %>', edit_<%= singular_table_name %>_path(<%= singular_table_name %>), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
|
20
|
+
<hr class="mt-6">
|
21
|
+
<%% end %>
|
22
|
+
</div>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div class="mx-auto md:w-2/3 w-full flex">
|
2
|
+
<div class="mx-auto">
|
3
|
+
<%% if notice.present? %>
|
4
|
+
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%%= notice %></p>
|
5
|
+
<%% end %>
|
6
|
+
|
7
|
+
<%%= render @<%= singular_table_name %> %>
|
8
|
+
|
9
|
+
<%%= link_to 'Edit this <%= singular_table_name %>', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
10
|
+
<div class="inline-block ml-2">
|
11
|
+
<%%= button_to 'Delete this <%= singular_table_name %>', <%= singular_table_name %>_path(@<%= singular_table_name %>), method: :delete, data: { confirm: "Are you sure you want to delete this <%= singular_table_name %>?" }, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
|
12
|
+
</div>
|
13
|
+
<%%= link_to 'Back to <%= plural_table_name %>', <%= index_helper %>_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
|
14
|
+
</div>
|
15
|
+
</div>
|
data/lib/install/tailwindcss.rb
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
|
2
2
|
|
3
3
|
if APPLICATION_LAYOUT_PATH.exist?
|
4
|
-
say "Add Tailwindcss include tags in application layout"
|
5
|
-
insert_into_file
|
4
|
+
say "Add Tailwindcss include tags and container element in application layout"
|
5
|
+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, <<~ERB.indent(4), before: /^\s*<%= stylesheet_link_tag/
|
6
|
+
<%= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %>
|
7
|
+
<%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %>
|
8
|
+
ERB
|
9
|
+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %( <main class="container mx-auto mt-28 px-5 flex">\n ), before: /^\s*<%= yield/
|
10
|
+
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n </main>), after: /^\s*<%= yield %>/
|
6
11
|
else
|
7
12
|
say "Default application.html.erb is missing!", :red
|
8
|
-
say %( Add <%= stylesheet_link_tag "inter-font" %> and <%= stylesheet_link_tag "tailwind" %> within the <head> tag in your custom layout.)
|
13
|
+
say %( Add <%= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %> and <%= stylesheet_link_tag "tailwind", "data-turbo-track": "reload" %> within the <head> tag in your custom layout.)
|
14
|
+
end
|
15
|
+
|
16
|
+
# No longer included by default in Rails 7, but for earlier versions of Rails
|
17
|
+
if (scaffolds_css_path = Rails.root.join("app/assets/stylesheets/scaffolds.scss")).exist?
|
18
|
+
remove_file scaffolds_css_path
|
9
19
|
end
|
10
20
|
|
11
21
|
say "Turn on purging of unused css classes in production"
|
data/lib/tailwindcss/engine.rb
CHANGED
data/lib/tailwindcss/purger.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Tailwindcss::Purger
|
4
|
-
CLASS_NAME_PATTERN = /[:A-Za-z0-9_-]+[
|
4
|
+
CLASS_NAME_PATTERN = /((?:[:A-Za-z0-9_-]+[\\\/:A-Za-z0-9_-]*[0-3][\\.]*5)|(?:[A-Za-z0-9_-]+[\\\/:A-Za-z0-9_-]*))/
|
5
5
|
|
6
6
|
CLASS_BREAK = /(?![-_a-z0-9\\])/i # `\b` for class selectors
|
7
7
|
|
@@ -29,7 +29,7 @@ class Tailwindcss::Purger
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def extract_class_names(string)
|
32
|
-
string.scan(CLASS_NAME_PATTERN).uniq.sort!
|
32
|
+
string.scan(CLASS_NAME_PATTERN).flatten.uniq.sort!
|
33
33
|
end
|
34
34
|
|
35
35
|
def extract_class_names_from(files)
|
data/lib/tailwindcss/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailwindcss-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.0.0
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email: david@loudthinking.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -51,6 +51,13 @@ files:
|
|
51
51
|
- app/assets/fonts/Inter-roman.vietnamese.var.woff2
|
52
52
|
- app/assets/stylesheets/inter-font.css.erb
|
53
53
|
- app/assets/stylesheets/tailwind.css
|
54
|
+
- lib/generators/tailwindcss/scaffold/scaffold_generator.rb
|
55
|
+
- lib/generators/tailwindcss/scaffold/templates/_form.html.erb.tt
|
56
|
+
- lib/generators/tailwindcss/scaffold/templates/edit.html.erb.tt
|
57
|
+
- lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt
|
58
|
+
- lib/generators/tailwindcss/scaffold/templates/new.html.erb.tt
|
59
|
+
- lib/generators/tailwindcss/scaffold/templates/partial.html.erb.tt
|
60
|
+
- lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt
|
54
61
|
- lib/install/tailwindcss.rb
|
55
62
|
- lib/tailwindcss-rails.rb
|
56
63
|
- lib/tailwindcss/compressor.rb
|
@@ -63,7 +70,7 @@ licenses:
|
|
63
70
|
- MIT
|
64
71
|
metadata:
|
65
72
|
homepage_uri: https://github.com/rails/tailwindcss-rails
|
66
|
-
post_install_message:
|
73
|
+
post_install_message:
|
67
74
|
rdoc_options: []
|
68
75
|
require_paths:
|
69
76
|
- lib
|
@@ -79,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
86
|
version: '0'
|
80
87
|
requirements: []
|
81
88
|
rubygems_version: 3.1.4
|
82
|
-
signing_key:
|
89
|
+
signing_key:
|
83
90
|
specification_version: 4
|
84
91
|
summary: Integrate Tailwind CSS with the asset pipeline in Rails.
|
85
92
|
test_files: []
|