├── .gitignore ├── Gemfile ├── Gemfile.lock ├── MIT-LICENSE ├── README.md ├── Rakefile ├── bin ├── release └── test ├── lib ├── generators │ └── tailwindcss │ │ ├── controller │ │ ├── controller_generator.rb │ │ └── templates │ │ │ └── view.html.erb.tt │ │ └── scaffold │ │ ├── scaffold_generator.rb │ │ └── templates │ │ ├── _form.html.erb.tt │ │ ├── edit.html.erb.tt │ │ ├── index.html.erb.tt │ │ ├── new.html.erb.tt │ │ ├── partial.html.erb.tt │ │ └── show.html.erb.tt ├── install │ ├── stylesheets │ │ ├── application.scss │ │ └── tailwind.config.js │ └── tailwindcss.rb ├── tailwindcss-rails-webpacker.rb ├── tailwindcss │ ├── engine.rb │ └── version.rb └── tasks │ └── tailwindcss_tasks.rake ├── tailwindcss-rails-webpacker.gemspec └── test ├── lib └── generators │ └── tailwindcss │ ├── controller_generator_test.rb │ └── scaffold_generator_test.rb ├── tailwindcss └── rails │ └── webpacker_test.rb └── test_helper.rb /.gitignore: -------------------------------------------------------------------------------- 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/ 15 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 | 4 | gemspec 5 | 6 | gem 'byebug' 7 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | tailwindcss-rails-webpacker (0.2.1) 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.2) 84 | method_source (1.0.0) 85 | mini_mime (1.1.1) 86 | mini_portile2 (2.6.1) 87 | minitest (5.14.4) 88 | nio4r (2.5.8) 89 | nokogiri (1.12.5) 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.2) 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 147 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 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. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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 | Gem overrides default Rails scaffold generators in favour of Tailwind 10 | designed templates by Adam Wathan and the Tailwind team. 11 | 12 | 13 | ## Installation 14 | 15 | 1. Run `./bin/bundle add tailwindcss-rails-webpacker` 16 | 2. Run `./bin/rails tailwindcss:install` 17 | 18 | 19 | ## Purging in production 20 | 21 | 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. 22 | 23 | This gem will automatically purge those unused classes in production. 24 | 25 | ## License 26 | 27 | Tailwind for Rails Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT). 28 | Tailwind CSS is released under the [MIT License](https://opensource.org/licenses/MIT). 29 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 14 | -------------------------------------------------------------------------------- /bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | VERSION=$1 4 | 5 | printf "module Tailwindcss\n VERSION = \"$VERSION\"\nend\n" > ./lib/tailwindcss/version.rb 6 | bundle 7 | git add Gemfile.lock lib/tailwindcss/version.rb 8 | git commit -m "Bump version for $VERSION" 9 | git push 10 | git tag v$VERSION 11 | git push --tags 12 | gem build tailwindcss-rails-webpacker.gemspec 13 | gem push "tailwindcss-rails-webpacker-$VERSION.gem" -------------------------------------------------------------------------------- /bin/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | $: << File.expand_path("../test", __dir__) 3 | 4 | require "bundler/setup" 5 | require "rails/plugin/test" 6 | -------------------------------------------------------------------------------- /lib/generators/tailwindcss/controller/controller_generator.rb: -------------------------------------------------------------------------------- 1 | require "rails/generators/erb/controller/controller_generator" 2 | 3 | module Tailwindcss 4 | module Generators 5 | class ControllerGenerator < Erb::Generators::ControllerGenerator 6 | source_root File.expand_path("../templates", __FILE__) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/generators/tailwindcss/controller/templates/view.html.erb.tt: -------------------------------------------------------------------------------- 1 |
2 |

<%= class_name %>#<%= @action %>

3 |

Find me in <%= @path %>

4 |
5 | -------------------------------------------------------------------------------- /lib/generators/tailwindcss/scaffold/scaffold_generator.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /lib/generators/tailwindcss/scaffold/templates/_form.html.erb.tt: -------------------------------------------------------------------------------- 1 | <%%= form_with(model: <%= model_resource_name %>, class: "contents") do |form| %> 2 | <%% if <%= singular_table_name %>.errors.any? %> 3 |
4 |

<%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:

5 | 6 |
    7 | <%% <%= singular_table_name %>.errors.each do |error| %> 8 |
  • <%%= error.full_message %>
  • 9 | <%% end %> 10 |
11 |
12 | <%% end %> 13 | 14 | <% attributes.each do |attribute| -%> 15 |
16 | <% if attribute.password_digest? -%> 17 | <%%= form.label :password %> 18 | <%%= form.password_field :password %> 19 |
20 | 21 |
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 |
38 | 39 | <% end -%> 40 |
41 | <%%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium" %> 42 |
43 | <%% end %> -------------------------------------------------------------------------------- /lib/generators/tailwindcss/scaffold/templates/edit.html.erb.tt: -------------------------------------------------------------------------------- 1 |
2 |

Editing <%= human_name.downcase %>

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 |
-------------------------------------------------------------------------------- /lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt: -------------------------------------------------------------------------------- 1 |
2 | <%% if notice.present? %> 3 |

<%%= notice %>

4 | <%% end %> 5 | 6 |
7 |

<%= human_name.pluralize %>

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 |
10 | 11 |
12 | <%%= render @<%= plural_table_name %> %> 13 |
14 |
-------------------------------------------------------------------------------- /lib/generators/tailwindcss/scaffold/templates/new.html.erb.tt: -------------------------------------------------------------------------------- 1 |
2 |

New <%= human_name.downcase %>

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 |
-------------------------------------------------------------------------------- /lib/generators/tailwindcss/scaffold/templates/partial.html.erb.tt: -------------------------------------------------------------------------------- 1 |
2 | <% attributes.reject(&:password_digest?).each do |attribute| -%> 3 |

4 | <%= attribute.human_name %>: 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 |

<%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %>
10 | <%% end %> 11 | <% else -%> 12 | <%%= <%= singular_table_name %>.<%= attribute.column_name %> %> 13 | <% end -%> 14 |

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 |
21 | <%% end %> 22 |
-------------------------------------------------------------------------------- /lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt: -------------------------------------------------------------------------------- 1 |
2 |
3 | <%% if notice.present? %> 4 |

<%%= notice %>

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 |
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 |
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 |
15 |
-------------------------------------------------------------------------------- /lib/install/stylesheets/application.scss: -------------------------------------------------------------------------------- 1 | @import "tailwindcss/base"; 2 | @import "tailwindcss/components"; 3 | @import "tailwindcss/utilities"; -------------------------------------------------------------------------------- /lib/install/stylesheets/tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // Purge unused TailwindCSS styles 3 | purge: { 4 | enabled: ["production"].includes(process.env.NODE_ENV), 5 | content: [ 6 | './**/*.html.erb', 7 | './app/helpers/**/*.rb', 8 | './app/javascript/**/*.js', 9 | ], 10 | }, 11 | darkMode: 'media', // or 'media' or 'class' 12 | theme: { 13 | extend: {}, 14 | }, 15 | variants: { 16 | extend: {}, 17 | }, 18 | plugins: [], 19 | } -------------------------------------------------------------------------------- /lib/install/tailwindcss.rb: -------------------------------------------------------------------------------- 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 | 11 | insert_into_file "postcss.config.js", "require('tailwindcss')(\"./app/javascript/stylesheets/tailwind.config.js\"),\n ", 12 | before: "require('postcss-import')" 13 | 14 | 15 | if APPLICATION_LAYOUT_PATH.exist? 16 | say "Add Tailwindcss include tags and container element in application layout" 17 | 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>/ 18 | insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(
\n ), before: /^\s*<%= yield/ 19 | insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n
), after: /^\s*<%= yield %>/ 20 | else 21 | say "Default application.html.erb is missing!", :red 22 | say %( Add <%= stylesheet_pack_tag "application", "data-turbo-track": "reload" %> within the tag in your custom layout.) 23 | end -------------------------------------------------------------------------------- /lib/tailwindcss-rails-webpacker.rb: -------------------------------------------------------------------------------- 1 | module Tailwindcss 2 | end 3 | 4 | require "tailwindcss/version" 5 | require "tailwindcss/engine" -------------------------------------------------------------------------------- /lib/tailwindcss/engine.rb: -------------------------------------------------------------------------------- 1 | module Tailwindcss 2 | class Engine < ::Rails::Engine 3 | config.app_generators do |g| 4 | g.template_engine :tailwindcss 5 | end 6 | end 7 | end -------------------------------------------------------------------------------- /lib/tailwindcss/version.rb: -------------------------------------------------------------------------------- 1 | module Tailwindcss 2 | VERSION = "0.2.1" 3 | end 4 | -------------------------------------------------------------------------------- /lib/tasks/tailwindcss_tasks.rake: -------------------------------------------------------------------------------- 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 7 | -------------------------------------------------------------------------------- /tailwindcss-rails-webpacker.gemspec: -------------------------------------------------------------------------------- 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/WizardComputer/tailwindcss-rails-webpacker" 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 18 | -------------------------------------------------------------------------------- /test/lib/generators/tailwindcss/controller_generator_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | require "generators/tailwindcss/controller/controller_generator" 3 | 4 | class Tailwindcss::Generators::ControllerGeneratorTest < Rails::Generators::TestCase 5 | GENERATION_PATH = File.expand_path("../controller_tmp", File.dirname(__FILE__)) 6 | 7 | tests Tailwindcss::Generators::ControllerGenerator 8 | destination GENERATION_PATH 9 | 10 | arguments %w(Messages index show) 11 | 12 | Minitest.after_run do 13 | FileUtils.rm_rf GENERATION_PATH 14 | end 15 | 16 | test "generates correct view templates" do 17 | run_generator 18 | assert_file "app/views/messages/index.html.erb" 19 | assert_file "app/views/messages/show.html.erb" 20 | end 21 | 22 | test "should revoke the template engine" do 23 | run_generator 24 | run_generator ["messages"], behavior: :revoke 25 | 26 | assert_no_file "app/views/messages" 27 | assert_no_file "app/views/messages/index.html.erb" 28 | assert_no_file "app/views/messages/show.html.erb" 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /test/lib/generators/tailwindcss/scaffold_generator_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | require "generators/tailwindcss/scaffold/scaffold_generator" 3 | 4 | class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase 5 | GENERATION_PATH = File.expand_path("../tmp", File.dirname(__FILE__)) 6 | 7 | tests Tailwindcss::Generators::ScaffoldGenerator 8 | destination GENERATION_PATH 9 | 10 | arguments %w(message title:string content:text) 11 | 12 | Minitest.after_run do 13 | FileUtils.rm_rf GENERATION_PATH 14 | end 15 | 16 | test "generates correct view templates" do 17 | run_generator 18 | 19 | %w(index edit new show _form _message).each { |view| assert_file "app/views/messages/#{view}.html.erb" } 20 | end 21 | end -------------------------------------------------------------------------------- /test/tailwindcss/rails/webpacker_test.rb: -------------------------------------------------------------------------------- 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 8 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 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' 11 | --------------------------------------------------------------------------------