Skip to content

Commit 0b3c581

Browse files
committed
Initial port from tailwindcss-rails-webpacker
`tailwindcss-rails` dropped webpacker support, this is the port that supports only webpacker option.
0 parents  commit 0b3c581

File tree

16 files changed

+300
-0
lines changed

16 files changed

+300
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.bundle/
2+
/doc/
3+
/log/*.log
4+
/pkg/
5+
/tmp/
6+
/test/dummy/db/*.sqlite3
7+
/test/dummy/db/*.sqlite3-*
8+
/test/dummy/log/*.log
9+
/test/dummy/storage/
10+
/test/dummy/tmp/
11+
/node_modules
12+
.byebug_history
13+
*.gem
14+
.idea/

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source 'https://rubygems.org'
2+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3+
4+
gemspec
5+
6+
gem 'byebug'

Gemfile.lock

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
PATH
2+
remote: .
3+
specs:
4+
tailwindcss-rails-webpacker (0.3.3)
5+
rails (>= 6.0.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
actioncable (6.1.4.1)
11+
actionpack (= 6.1.4.1)
12+
activesupport (= 6.1.4.1)
13+
nio4r (~> 2.0)
14+
websocket-driver (>= 0.6.1)
15+
actionmailbox (6.1.4.1)
16+
actionpack (= 6.1.4.1)
17+
activejob (= 6.1.4.1)
18+
activerecord (= 6.1.4.1)
19+
activestorage (= 6.1.4.1)
20+
activesupport (= 6.1.4.1)
21+
mail (>= 2.7.1)
22+
actionmailer (6.1.4.1)
23+
actionpack (= 6.1.4.1)
24+
actionview (= 6.1.4.1)
25+
activejob (= 6.1.4.1)
26+
activesupport (= 6.1.4.1)
27+
mail (~> 2.5, >= 2.5.4)
28+
rails-dom-testing (~> 2.0)
29+
actionpack (6.1.4.1)
30+
actionview (= 6.1.4.1)
31+
activesupport (= 6.1.4.1)
32+
rack (~> 2.0, >= 2.0.9)
33+
rack-test (>= 0.6.3)
34+
rails-dom-testing (~> 2.0)
35+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
36+
actiontext (6.1.4.1)
37+
actionpack (= 6.1.4.1)
38+
activerecord (= 6.1.4.1)
39+
activestorage (= 6.1.4.1)
40+
activesupport (= 6.1.4.1)
41+
nokogiri (>= 1.8.5)
42+
actionview (6.1.4.1)
43+
activesupport (= 6.1.4.1)
44+
builder (~> 3.1)
45+
erubi (~> 1.4)
46+
rails-dom-testing (~> 2.0)
47+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
48+
activejob (6.1.4.1)
49+
activesupport (= 6.1.4.1)
50+
globalid (>= 0.3.6)
51+
activemodel (6.1.4.1)
52+
activesupport (= 6.1.4.1)
53+
activerecord (6.1.4.1)
54+
activemodel (= 6.1.4.1)
55+
activesupport (= 6.1.4.1)
56+
activestorage (6.1.4.1)
57+
actionpack (= 6.1.4.1)
58+
activejob (= 6.1.4.1)
59+
activerecord (= 6.1.4.1)
60+
activesupport (= 6.1.4.1)
61+
marcel (~> 1.0.0)
62+
mini_mime (>= 1.1.0)
63+
activesupport (6.1.4.1)
64+
concurrent-ruby (~> 1.0, >= 1.0.2)
65+
i18n (>= 1.6, < 2)
66+
minitest (>= 5.1)
67+
tzinfo (~> 2.0)
68+
zeitwerk (~> 2.3)
69+
builder (3.2.4)
70+
byebug (11.1.3)
71+
concurrent-ruby (1.1.9)
72+
crass (1.0.6)
73+
erubi (1.10.0)
74+
globalid (0.5.2)
75+
activesupport (>= 5.0)
76+
i18n (1.8.10)
77+
concurrent-ruby (~> 1.0)
78+
loofah (2.12.0)
79+
crass (~> 1.0.2)
80+
nokogiri (>= 1.5.9)
81+
mail (2.7.1)
82+
mini_mime (>= 0.1.1)
83+
marcel (1.0.1)
84+
method_source (1.0.0)
85+
mini_mime (1.1.0)
86+
mini_portile2 (2.6.1)
87+
minitest (5.14.4)
88+
nio4r (2.5.8)
89+
nokogiri (1.12.3)
90+
mini_portile2 (~> 2.6.1)
91+
racc (~> 1.4)
92+
racc (1.5.2)
93+
rack (2.2.3)
94+
rack-test (1.1.0)
95+
rack (>= 1.0, < 3)
96+
rails (6.1.4.1)
97+
actioncable (= 6.1.4.1)
98+
actionmailbox (= 6.1.4.1)
99+
actionmailer (= 6.1.4.1)
100+
actionpack (= 6.1.4.1)
101+
actiontext (= 6.1.4.1)
102+
actionview (= 6.1.4.1)
103+
activejob (= 6.1.4.1)
104+
activemodel (= 6.1.4.1)
105+
activerecord (= 6.1.4.1)
106+
activestorage (= 6.1.4.1)
107+
activesupport (= 6.1.4.1)
108+
bundler (>= 1.15.0)
109+
railties (= 6.1.4.1)
110+
sprockets-rails (>= 2.0.0)
111+
rails-dom-testing (2.0.3)
112+
activesupport (>= 4.2.0)
113+
nokogiri (>= 1.6)
114+
rails-html-sanitizer (1.4.1)
115+
loofah (~> 2.3)
116+
railties (6.1.4.1)
117+
actionpack (= 6.1.4.1)
118+
activesupport (= 6.1.4.1)
119+
method_source
120+
rake (>= 0.13)
121+
thor (~> 1.0)
122+
rake (13.0.6)
123+
sprockets (4.0.2)
124+
concurrent-ruby (~> 1.0)
125+
rack (> 1, < 3)
126+
sprockets-rails (3.2.2)
127+
actionpack (>= 4.0)
128+
activesupport (>= 4.0)
129+
sprockets (>= 3.0.0)
130+
thor (1.1.0)
131+
tzinfo (2.0.4)
132+
concurrent-ruby (~> 1.0)
133+
websocket-driver (0.7.5)
134+
websocket-extensions (>= 0.1.0)
135+
websocket-extensions (0.1.5)
136+
zeitwerk (2.4.2)
137+
138+
PLATFORMS
139+
ruby
140+
141+
DEPENDENCIES
142+
byebug
143+
tailwindcss-rails-webpacker!
144+
145+
BUNDLED WITH
146+
2.1.4

MIT-LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2021 Dino Maric
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Tailwind CSS for Rails webpacker
2+
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+
5+
This gem gives access to the standard Tailwind CSS framework configured for Rails webpacker.
6+
7+
This is extraction originally created inside the [tailwindcss-rails](https://github.com/rails/tailwindcss-rails) gem.
8+
9+
10+
## Installation
11+
12+
1. Run `./bin/bundle add tailwindcss-rails-webpacker`
13+
2. Run `./bin/rails tailwindcss:install`
14+
15+
16+
## License
17+
18+
Tailwind for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).
19+
Tailwind CSS is released under the [MIT License](https://opensource.org/licenses/MIT).

Rakefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "bundler/setup"
2+
3+
require "bundler/gem_tasks"
4+
5+
require "rake/testtask"
6+
7+
Rake::TestTask.new(:test) do |t|
8+
t.libs << 'test'
9+
t.pattern = 'test/**/*_test.rb'
10+
t.verbose = false
11+
end
12+
13+
task default: :test

bin/test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
$: << File.expand_path("../test", __dir__)
3+
4+
require "bundler/setup"
5+
require "rails/plugin/test"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@import "tailwindcss/base";
2+
@import "tailwindcss/components";
3+
@import "tailwindcss/utilities";

lib/install/tailwindcss.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
WEBPACK_STYLESHEETS_PATH = "#{Webpacker.config.source_path}/stylesheets"
2+
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
3+
4+
say "Installing Tailwind CSS"
5+
run "yarn add tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9"
6+
insert_into_file "#{Webpacker.config.source_entry_path}/application.js", "\nimport \"stylesheets/application\"\n"
7+
8+
say "Configuring Tailwind CSS"
9+
directory Pathname.new(__dir__).join("stylesheets"), Webpacker.config.source_path.join("stylesheets")
10+
Dir.chdir(WEBPACK_STYLESHEETS_PATH) { run "npx tailwindcss init" }
11+
12+
insert_into_file "postcss.config.js", "require('tailwindcss')(\"./app/javascript/stylesheets/tailwind.config.js\"),\n ",
13+
before: "require('postcss-import')"
14+
15+
16+
if APPLICATION_LAYOUT_PATH.exist?
17+
say "Add Tailwindcss include tags in application layout"
18+
insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, %(\n <%= stylesheet_pack_tag "application", "data-turbo-track": "reload" %>), before: /\s*<\/head>/
19+
else
20+
say "Default application.html.erb is missing!", :red
21+
say %( Add <%= stylesheet_pack_tag "application", "data-turbo-track": "reload" %> within the <head> tag in your custom layout.)
22+
end

lib/tailwindcss-rails-webpacker.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Tailwindcss
2+
end
3+
4+
require "tailwindcss/version"
5+
require "tailwindcss/engine"

lib/tailwindcss/engine.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Tailwindcss
2+
class Engine < ::Rails::Engine
3+
end
4+
end

lib/tailwindcss/version.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Tailwindcss
2+
VERSION = "0.3.3"
3+
end

lib/tasks/tailwindcss_tasks.rake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace :tailwindcss do
2+
desc "Install Tailwind CSS into the app"
3+
task :install do
4+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/tailwindcss.rb", __dir__)}"
5+
end
6+
end

tailwindcss-rails-webpacker.gemspec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require_relative "lib/tailwindcss/version"
2+
3+
Gem::Specification.new do |spec|
4+
spec.name = "tailwindcss-rails-webpacker"
5+
spec.version = Tailwindcss::VERSION
6+
spec.authors = [ "Dino Maric", "David Heinemeier Hansson" ]
7+
spec.email = ["dinom@hey.com"]
8+
spec.homepage = "https://github.com/rails/tailwindcss-rails"
9+
spec.summary = "Integrate Tailwind CSS with the Rails webpacker."
10+
spec.license = "MIT"
11+
12+
spec.metadata["homepage_uri"] = spec.homepage
13+
14+
spec.files = Dir["{app,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
15+
16+
spec.add_dependency "rails", ">= 6.0.0"
17+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "test_helper"
2+
3+
class TailwindcssTest < ActiveSupport::TestCase
4+
test "it has a version number" do
5+
assert Tailwindcss::VERSION
6+
end
7+
end

test/test_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Configure Rails Environment
2+
ENV["RAILS_ENV"] = "test"
3+
4+
require "rails"
5+
require "rails/test_help"
6+
require "byebug"
7+
require_relative "../lib/tailwindcss-rails-webpacker"
8+
9+
require "rails/test_unit/reporter"
10+
Rails::TestUnitReporter.executable = 'bin/test'

0 commit comments

Comments
 (0)