Skip to content

Commit 783597b

Browse files
committed
Update content
1 parent 1ae036d commit 783597b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

app/content/pages/articles/custom-color-schemes-with-ruby-on-rails.html.mdrb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Pretty cool, huh? Here are the key ingredients:
3131
- [Cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies): A session cookie to store your saved color scheme selection
3232
- [Hotwire](https://hotwired.dev/): Server-rendered HTML and a single-page app experience powered by Rails, [Turbo Drive](https://turbo.hotwired.dev/handbook/introduction#turbo-drive%3A-navigate-within-a-persistent-process), and [Turbo Frames](https://turbo.hotwired.dev/handbook/introduction#turbo-frames%3A-decompose-complex-pages)
3333

34-
I started with the premise of using a monochromatic color scheme based on the 11 color scale Tailwind uses for each of [its default color sets](https://tailwindcss.com/docs/customizing-colors). The curated options are all generated from [uicolors.app](https://uicolors.app/create).
34+
I started with the premise of using a monochromatic color scheme based on the eleven-item color scale [Tailwind](https://tailwindcss.com) uses for each of [its default color sets](https://tailwindcss.com/docs/customizing-colors). The curated options are all generated from [uicolors.app](https://uicolors.app/create).
3535

3636
Each color scheme is a row in the `color_schemes` table, with a name and CSS hex code values for each of the eleven weights.
3737

@@ -51,7 +51,7 @@ end
5151

5252
CSS variables make it easy to change repeated CSS in a lot of places. You can set a CSS variable with double dashes, `--`. The CSS variable can be accessed using the `var()` expression. CSS variables can be overridden and can be defined in terms of other variables.
5353

54-
Here’s a simplified a view of how I used CSS variables to define the main background color of the `<body>` element.
54+
Here’s a simplified a view of how I used CSS variables to define the main background color of the `<body>` element. Using the pseudo-class `:root` means the CSS variable can be accessed from any scope in CSS.
5555

5656
```css:{"show_header": false}
5757
:root {
@@ -66,9 +66,11 @@ body {
6666
}
6767
```
6868

69-
Even though Joy of Rails does not use Tailwind, this approach is consistent with [the Tailwind docs for using CSS variables to customize Tailwind colors](https://tailwindcss.com/docs/customizing-colors#using-css-variables).
69+
This approach is consistent with [the Tailwind docs for using CSS variables to customize Tailwind colors](https://tailwindcss.com/docs/customizing-colors#using-css-variables) for those of you that may be using (or interested in using) Tailwind.
7070

71-
When you click the "Save" button, the application stores the `id` of the chosen color scheme in your Rails session:
71+
Most of the buttons in the color scheme demo are connected to `<form>` elements with actions that point to the [`ColorSchemesController`](https://github.com/joyofrails/joyofrails.com/blob/a08589e1cbe2accf4a20713829df56533e31755e/app/controllers/settings/color_schemes_controller.rb) in the Joy of Rails application.
72+
73+
When you click the "Save" button, [the application stores the `id` of the chosen color scheme in your Rails session](https://github.com/joyofrails/joyofrails.com/blob/a08589e1cbe2accf4a20713829df56533e31755e/app/controllers/settings/color_schemes_controller.rb#L31):
7274

7375
```ruby:{"show_header":false}
7476
session[:color_scheme_id] = @color_scheme.id
@@ -77,12 +79,10 @@ session[:color_scheme_id] = @color_scheme.id
7779
When the page is rendered, the application checks for the presence of the session data to query for the desired color scheme:
7880

7981
```ruby:{"show_header":false}
80-
if session[:color_scheme_id]
81-
@color_scheme = ColorScheme.find(session[:color_scheme_id])
82-
end
82+
session[:color_scheme_id] && ColorScheme.find(session[:color_scheme_id])
8383
```
8484

85-
The color scheme CSS variables can be written directly into a style tag
85+
The color scheme CSS variables are written directly into a style tag:
8686

8787
```erb:{"filename":"app/view/layouts/application.html.erb"}
8888
<style>

0 commit comments

Comments
 (0)