Skip to content

Commit d5b9618

Browse files
David Heinemeier Hanssonkddnewton
andauthored
Remove default reliance on Sass and CSS generators (rails#43110)
* No benefit to having actiontext css as scss * Update test * Update docs * No more css assets to be generated New world, new CSS frameworks, new needs. * SCSS is becoming optional * Remove Sass as a default-on setting But continue to make it easy to add. * Update docs * No longer used * Update tests * Update docs * Update docs * No longer used * No longer by default * Fix tests * Promote Tailwind CSS as an alternative to Sass * Fix test and copy task * Update railties/lib/rails/generators/rails/app/templates/Gemfile.tt Co-authored-by: Kevin Newton <[email protected]> Co-authored-by: Kevin Newton <[email protected]>
1 parent af7428c commit d5b9618

32 files changed

+58
-408
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ gem "capybara", ">= 3.26"
1313
gem "selenium-webdriver", ">= 4.0.0.alpha7"
1414

1515
gem "rack-cache", "~> 1.2"
16-
gem "sass-rails"
1716
gem "stimulus-rails"
1817
gem "turbo-rails"
1918
gem "webpacker", "~> 6.0.0.rc.5", require: ENV["SKIP_REQUIRE_WEBPACKER"] != "true"

Gemfile.lock

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,16 +422,6 @@ GEM
422422
rubyzip (2.3.0)
423423
rufus-scheduler (3.7.0)
424424
fugit (~> 1.1, >= 1.1.6)
425-
sass-rails (6.0.0)
426-
sassc-rails (~> 2.1, >= 2.1.1)
427-
sassc (2.4.0)
428-
ffi (~> 1.9)
429-
sassc-rails (2.1.2)
430-
railties (>= 4.0.0)
431-
sassc (>= 2.0)
432-
sprockets (> 3.0)
433-
sprockets-rails
434-
tilt
435425
sdoc (2.2.0)
436426
rdoc (>= 5.0)
437427
selenium-webdriver (4.0.0.beta4)
@@ -583,7 +573,6 @@ DEPENDENCIES
583573
rubocop-packaging
584574
rubocop-performance
585575
rubocop-rails
586-
sass-rails
587576
sdoc (>= 2.2.0)
588577
selenium-webdriver (>= 4.0.0.alpha7)
589578
sequel

actiontext/lib/generators/action_text/install/install_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def append_javascript_dependencies
6262
end
6363

6464
def create_actiontext_files
65-
template "actiontext.scss", "app/assets/stylesheets/actiontext.scss"
65+
template "actiontext.css", "app/assets/stylesheets/actiontext.css"
6666

6767
copy_file "#{GEM_ROOT}/app/views/active_storage/blobs/_blob.html.erb",
6868
"app/views/active_storage/blobs/_blob.html.erb"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and
3+
* the trix-editor content (whether displayed or under editing). Feel free to incorporate this
4+
* inclusion directly in any other asset bundle and remove this file.
5+
*
6+
<%- if defined?(Webpacker::Engine) -%>
7+
*= require trix/dist/trix
8+
<%- else -%>
9+
*= require trix
10+
<% end -%>
11+
*/
12+
13+
/*
14+
* We need to override trix.css’s image gallery styles to accommodate the
15+
* <action-text-attachment> element we wrap around attachments. Otherwise,
16+
* images in galleries will be squished by the max-width: 33%; rule.
17+
*/
18+
.trix-content .attachment-gallery > action-text-attachment,
19+
.trix-content .attachment-gallery > .attachment {
20+
flex: 1 0 33%;
21+
padding: 0 0.5em;
22+
max-width: 33%;
23+
}
24+
25+
.trix-content .attachment-gallery.attachment-gallery--2 > action-text-attachment,
26+
.trix-content .attachment-gallery.attachment-gallery--2 > .attachment, .trix-content .attachment-gallery.attachment-gallery--4 > action-text-attachment,
27+
.trix-content .attachment-gallery.attachment-gallery--4 > .attachment {
28+
flex-basis: 50%;
29+
max-width: 50%;
30+
}
31+
32+
.trix-content action-text-attachment .attachment {
33+
padding: 0 !important;
34+
max-width: 100% !important;
35+
}

actiontext/lib/generators/action_text/install/templates/actiontext.scss

Lines changed: 0 additions & 40 deletions
This file was deleted.

guides/source/action_text_overview.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,17 @@ Run `bin/rails action_text:install` to add the Yarn package and copy over the ne
4949

5050
NOTE: ActionText uses polymorphic relationships with the `action_text_rich_texts` table so that it can be shared with all models that have rich text attributes. If your models with ActionText content use UUID values for identifiers, all models that use ActionText attributes will need to use UUID values for their unique identifiers. The generated migration for ActionText will also need to be updated to specify `type: :uuid` for the `:record` `references` line.
5151

52-
After the installation is complete, a Rails app using Webpacker should have the following changes:
52+
After the installation is complete, a Rails app should have the following changes:
5353

54-
1. Both `trix` and `@rails/actiontext` should be required in your JavaScript pack.
54+
1. Both `trix` and `@rails/actiontext` should be required in your JavaScript entrypoint.
5555

5656
```js
5757
// application.js
5858
import "trix"
5959
import "@rails/actiontext"
6060
```
6161

62-
2. The `trix` stylesheet should be imported into `actiontext.scss`.
63-
64-
```scss
65-
@import "trix/dist/trix";
66-
```
67-
68-
Additionally, this `actiontext.scss` file should be imported into your stylesheet pack.
69-
70-
```scss
71-
// application.scss
72-
@import "./actiontext.scss";
73-
```
62+
2. The `trix` stylesheet will be included together with Action Text styles in your `application.css` file.
7463

7564
## Creating Rich Text content
7665

guides/source/asset_pipeline.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,11 @@ passing the `--skip-sprockets` option.
3333
$ rails new appname --skip-sprockets
3434
```
3535

36-
Rails automatically adds the [`sass-rails`](https://github.com/rails/sass-rails)
37-
gem to your `Gemfile`, which is used by Sprockets for
38-
[Sass](https://sass-lang.com) compilation:
36+
Rails can easily work with Sass by adding the [`sassc-rails`](https://github.com/sass/sassc-rails)
37+
gem to your `Gemfile`, which is used by Sprockets for [Sass](https://sass-lang.com) compilation:
3938

4039
```ruby
41-
gem 'sass-rails'
42-
```
43-
44-
Using the `--skip-sprockets` option will prevent Rails from adding
45-
this gem, so if you later want to enable the asset pipeline
46-
you will have to add it to your `Gemfile` manually. Also,
47-
creating an application with the `--skip-sprockets` option will generate
48-
a slightly different `config/application.rb` file, with a require statement
49-
for the sprockets railtie that is commented-out. You will have to remove
50-
the comment operator on that line to later enable the asset pipeline:
51-
52-
```ruby
53-
# require "sprockets/railtie"
40+
gem 'sassc-rails'
5441
```
5542

5643
To set asset compression methods, set the appropriate configuration options
@@ -62,7 +49,7 @@ config.assets.css_compressor = :yui
6249
config.assets.js_compressor = :uglifier
6350
```
6451

65-
NOTE: The `sass-rails` gem is automatically used for CSS compression if included
52+
NOTE: The `sassc-rails` gem is automatically used for CSS compression if included
6653
in the `Gemfile` and no `config.assets.css_compressor` option is set.
6754

6855
### Main Features

guides/source/command_line.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,6 @@ $ bin/rails generate controller Greetings hello
210210
invoke helper
211211
create app/helpers/greetings_helper.rb
212212
invoke test_unit
213-
invoke assets
214-
invoke scss
215-
create app/assets/stylesheets/greetings.scss
216213
```
217214
218215
What all did this generate? It made sure a bunch of directories were in our application, and created a controller file, a view file, a functional test file, a helper for the view, a JavaScript file, and a stylesheet file.
@@ -302,11 +299,6 @@ $ bin/rails generate scaffold HighScore game:string score:integer
302299
create app/views/high_scores/index.json.jbuilder
303300
create app/views/high_scores/show.json.jbuilder
304301
create app/views/high_scores/_high_score.json.jbuilder
305-
invoke assets
306-
invoke scss
307-
create app/assets/stylesheets/high_scores.scss
308-
invoke scss
309-
create app/assets/stylesheets/scaffolds.scss
310302
```
311303
312304
The generator checks that there exist the directories for models, controllers, helpers, layouts, functional and unit tests, stylesheets, creates the views, controller, model and database migration for HighScore (creating the `high_scores` table and fields), takes care of the route for the **resource**, and new tests for everything.

guides/source/configuring.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ end
211211
212212
The full set of methods that can be used in this block are as follows:
213213
214-
* `assets` allows to create assets on generating a scaffold. Defaults to `true`.
215214
* `force_plural` allows pluralized model names. Defaults to `false`.
216215
* `helper` defines whether or not to generate helpers. Defaults to `true`.
217216
* `integration_tool` defines which integration tool to use to generate integration tests. Defaults to `:test_unit`.
@@ -221,9 +220,6 @@ The full set of methods that can be used in this block are as follows:
221220
* `resource_route` defines whether a resource route definition should be generated
222221
or not. Defaults to `true`.
223222
* `scaffold_controller` different from `resource_controller`, defines which generator to use for generating a _scaffolded_ controller when using `bin/rails generate scaffold`. Defaults to `:scaffold_controller`.
224-
* `stylesheets` turns on the hook for stylesheets in generators. Used in Rails for when the `scaffold` generator is run, but this hook can be used in other generates as well. Defaults to `true`.
225-
* `stylesheet_engine` configures the stylesheet engine (for e.g. sass) to be used when generating assets. Defaults to `:css`.
226-
* `scaffold_stylesheet` creates `scaffold.css` when generating a scaffolded resource. Defaults to `true`.
227223
* `test_framework` defines which test framework to use. Defaults to `false` and will use minitest by default.
228224
* `template_engine` defines which template engine to use, such as ERB or Haml. Defaults to `:erb`.
229225

guides/source/engines.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,6 @@ create test/system/blorgh/articles_test.rb
357357
invoke helper
358358
create app/helpers/blorgh/articles_helper.rb
359359
invoke test_unit
360-
invoke assets
361-
invoke css
362-
create app/assets/stylesheets/blorgh/articles.css
363-
invoke css
364-
create app/assets/stylesheets/scaffold.css
365360
```
366361
367362
The first thing that the scaffold generator does is invoke the `active_record`
@@ -427,8 +422,6 @@ end
427422
This helps prevent conflicts with any other engine or application that may have
428423
an article resource as well.
429424

430-
Finally, the assets for this resource are generated in one file: `app/assets/stylesheets/blorgh/articles.css`. You'll see how to use these a little later.
431-
432425
You can see what the engine has so far by running `bin/rails db:migrate` at the root
433426
of our engine to run the migration generated by the scaffold generator, and then
434427
running `bin/rails server` in `test/dummy`. When you open
@@ -579,9 +572,6 @@ create test/controllers/blorgh/comments_controller_test.rb
579572
invoke helper
580573
create app/helpers/blorgh/comments_helper.rb
581574
invoke test_unit
582-
invoke assets
583-
invoke css
584-
create app/assets/stylesheets/blorgh/comments.css
585575
```
586576

587577
The form will be making a `POST` request to `/articles/:article_id/comments`, which

0 commit comments

Comments
 (0)