Home >Web Front-end >CSS Tutorial >Ruby on Rails Front-end Rápido com Frameworks CSS Classless ou Class-Light - Sem CDN
This article is intentionally very similar to the previous one that deals with the same subject, but used CDN for the CSS frameworks, however, in this article we will use CSS files locally, copied to the project folder.
If you are starting out in web development and your focus is not to specialize in the front-end, one of the barriers that can be most painful is being able to easily style your ugly HTML.
For those who have first contact, it is something enigmatic, mystical, supernatural trying to understand HTML that has a sequence of letters and numbers with predefined utility classes to apply styles to HTML, for example:
<summary class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700" >
CSS frameworks that use utility classes are excellent, versatile, responsive, elegant and have many other qualities, but Tailwind CSS is not the only solution. If you need something quick and simpler, using a classless or class-light CSS framework will be a better solution.
Classless CSS Frameworks style HTML elements directly, without classes. Class-light frameworks combine automatic styles with some optional utility classes for customization, which adds greater versatility to their use.
Using a classless or class-light approach you can quickly solve HTML styling with one, two or three lines.
$ rails -v Rails 8.0.0 $ time rails new classless-css-local ... real 0m47.500s user 0m33.052s sys 0m4.249s
Rails 8, within its No Build philosophy, will use Propshaft as an asset pipeline library by default and Importmap as a JavaScript library. Importmap does not perform any type of JavaScript processing.
$ cd classless-css-local && code .
Show more…
<summary
class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700"
>
Show more…
$ rails -v
Rails 8.0.0
$ time rails new classless-css-local
...
real 0m47.500s
user 0m33.052s
sys 0m4.249s
Open the config/routes.rb file in VSCode
$ cd classless-css-local && code .
Using the terminal you can display the routes by specifying a controller (with -c), for example from controller pages Or you can display all routes withShow more…
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Classless Css" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= yield :head %>
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
<summary
class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700"
>
Ruby on Rails uses the MVC (Model-View-Controller) architecture by default to start organizing your project. Much of your code is organized in the following folders:
Show more…
$ rails -v
Rails 8.0.0
$ time rails new classless-css-local
...
real 0m47.500s
user 0m33.052s
sys 0m4.249s
Show more…
$ cd classless-css-local && code .
Let's create a classless subfolder inside app/assets/stylesheets to copy the css files downloaded from the links below: Bamboo CSS: https://github.com/rilwis/bamboo/blob/master/dist/bamboo.min.css Bamboo CSS only has the minified file. You can format them to make them easier to understand using services like CSS Beautifier & Minifie. Paste the code on the left and get the formatted file on the right. Rename the file to bamboo.css. Converting Vanilla SCSS to Vanilla CSS:Show more…
Consulting the Rails documentation on CSS files, we can see that we need to follow a few steps to style our web application by copying the CSS files:
<summary
class="flex cursor-pointer items-center justify-between rounded-lg px-4 py-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700"
>
FORShow more…
$ rails -v
Rails 8.0.0
$ time rails new classless-css-local
...
real 0m47.500s
user 0m33.052s
sys 0m4.249s
$ cd classless-css-local && code .
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Classless Css" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= yield :head %>
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
$ rails g controller pages html_test_1 html_test_2 html_test_3 html_test_4
create app/controllers/pages_controller.rb
route get "pages/html_test_1"
get "pages/html_test_2"
get "pages/html_test_3"
get "pages/html_test_4"
invoke erb
create app/views/pages
create app/views/pages/html_test_1.html.erb
create app/views/pages/html_test_2.html.erb
create app/views/pages/html_test_3.html.erb
create app/views/pages/html_test_4.html.erb
invoke helper
create app/helpers/pages_helper.rb
After saving the stylesheets above and starting the Rails server you will see your HTML styled with the chosen css frameworks.
Some styles have the option for dark mode. To confirm, change your computer's theme in the color customization options. Search Windows for Turn on dark mode for apps and toggle between dark or light mode. The HTML page should automatically change after changing the operating system, indicating that it supports light and dark mode.
[x] Arrange the styles according to your preference;
[x] Use styling from project CSS files, without using CDN;
[-] Dynamically update changes made to the project in the browser using Rails Live Reload;
[-] If you want to spend a little more time on the frontend, check out the customization options for your favorite style;
[-] Replicate the capability of a classless CSS framework using Tailwind;
The above is the detailed content of Ruby on Rails Front-end Rápido com Frameworks CSS Classless ou Class-Light - Sem CDN. For more information, please follow other related articles on the PHP Chinese website!