Skip to content

Commit 313ca42

Browse files
Andrey AzimovDavid Heinemeier Hansson
Andrey Azimov
and
David Heinemeier Hansson
authored
Added Bootstrap option (#3)
* added bootstrap option to install.rake * fixed typos in install.rake * added bootstrap folder with install.rb * added npm watch to boostrap install.rb * changed version of bootstrap to 5.1.1 and Popperjs/core to 2.10.1 * chanaged bootstrap and popper spefic version to @latest so it will be always up to date * renamed bootstrap_js_files.js to bootstrap.js * deleted bootstrap_js_files.js * Added Bootstrap to readme * fixed typo * fixed relative path of bootstrap.scss , because it was not working for some reason. changed from '~bootstrap/scss/bootstrap' to '../../../node_modules/bootstrap/scss/bootstrap' * added say "Add build:css script" to install.rb * Match existing conventions and add the JavaScript needs to the default entry point * Use ESM package instead * We are using esm now * Stop linking stylesheets in manifest Or Sprockets will try to install sassc! * Use sass with load path * Excess CR Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
1 parent 43f89cd commit 313ca42

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CSS Bundling for Rails
22

3-
Use [Tailwind CSS](https://tailwindcss.com), [PostCSS](https://postcss.org), or [Dart Sass](https://sass-lang.com/) to bundle and process your CSS, then deliver it via the asset pipeline in Rails. This gem provides installers to get you going with the bundler of your choice in a new Rails application, and a convention to use `app/assets/builds` to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to `.gitignore` by default).
3+
Use [Tailwind CSS](https://tailwindcss.com), [PostCSS](https://postcss.org), [Dart Sass](https://sass-lang.com/), or [Bootstrap](https://getbootstrap.com/) to bundle and process your CSS, then deliver it via the asset pipeline in Rails. This gem provides installers to get you going with the bundler of your choice in a new Rails application, and a convention to use `app/assets/builds` to hold your bundled output as artifacts that are not checked into source control (the installer adds this directory to `.gitignore` by default).
44

55
You develop using this approach by running the bundler in watch mode in a terminal with `yarn build:css --watch` (and your Rails server in another, if you're not using something like [puma-dev](https://github.com/puma/puma-dev)). Whenever the bundler detects changes to any of the stylesheet files in your project, it'll bundle `app/assets/stylesheets/application.[bundler].css` into `app/assets/builds/application.css`. This build output takes over from the regular asset pipeline default file. So you continue to refer to the build output in your layout using the standard asset pipeline approach with `<%= stylesheet_link_tag "application" %>`.
66

@@ -21,9 +21,9 @@ You must already have node and yarn installed on your system. You will also need
2121

2222
1. Add `cssbundling-rails` to your Gemfile with `gem 'cssbundling-rails'`
2323
2. Run `./bin/bundle install`
24-
3. Run `./bin/rails css:install:[tailwind|postcss|sass]`
24+
3. Run `./bin/rails css:install:[tailwind|postcss|sass|bootstrap]`
2525

26-
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp --css [tailwind|postcss|sass]`.
26+
Or, in Rails 7+, you can preconfigure your new application to use a specific bundler with `rails new myapp --css [tailwind|postcss|sass|bootstrap]`.
2727

2828

2929
## License
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import 'bootstrap/scss/bootstrap';

lib/install/bootstrap/install.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
say "Install Bootstrap with Popperjs/core"
2+
copy_file "#{__dir__}/application.bootstrap.scss",
3+
"app/assets/stylesheets/application.bootstrap.scss"
4+
run "yarn add sass bootstrap @popperjs/core"
5+
6+
if Rails.root.join("app/javascript/application.js").exist?
7+
say "Appending Bootstrap JavaScript import to default entry point"
8+
append_to_file "app/javascript/application.js", %(import * as bootstrap from "bootstrap"\n)
9+
else
10+
say %(Add import * as bootstrap from "bootstrap" to your entry point JavaScript file), :red
11+
end
12+
13+
say "Add build:css script"
14+
run %(npm set-script build:css "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules")

lib/install/install.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
keep_file "app/assets/builds"
44
append_to_file "app/assets/config/manifest.js", %(//= link_tree ../builds\n)
55

6+
say "Stop linking stylesheets automatically"
7+
gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css", ""
8+
69
if Rails.root.join(".gitignore").exist?
710
append_to_file(".gitignore", %(/app/assets/builds\n!/app/assets/builds/.keep\n))
811
end

lib/tasks/cssbundling/install.rake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ namespace :css do
1919
task sass: "css:install:shared" do
2020
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/sass/install.rb", __dir__)}"
2121
end
22+
23+
desc "Install Bootstrap"
24+
task bootstrap: "css:install:shared" do
25+
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bootstrap/install.rb", __dir__)}"
26+
end
2227
end
2328
end

0 commit comments

Comments
 (0)