twitter-bootstrap-rails 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +64 -0
- data/README.md +115 -4
- data/lib/generators/bootstrap/agent/agent_generator.rb +17 -0
- data/lib/generators/bootstrap/agent/templates/guide.md.erb +34 -2
- data/lib/generators/bootstrap/bootstrap5_markup.rb +22 -0
- data/lib/generators/bootstrap/cdn/cdn_generator.rb +32 -2
- data/lib/generators/bootstrap/cdn_tags.rb +11 -0
- data/lib/generators/bootstrap/doctor/doctor_generator.rb +12 -2
- data/lib/generators/bootstrap/install/install_generator.rb +77 -21
- data/lib/generators/bootstrap/layout/layout_generator.rb +15 -0
- data/lib/generators/bootstrap/layout/templates/layout.html.erb +4 -1
- data/lib/generators/bootstrap/layout/templates/layout.html.haml +4 -1
- data/lib/generators/bootstrap/layout/templates/layout.html.slim +4 -1
- data/lib/generators/bootstrap/nes/nes_generator.rb +101 -0
- data/lib/generators/bootstrap/snippets/snippet_base.rb +4 -0
- data/lib/generators/bootstrap/stimulus/stimulus_generator.rb +49 -0
- data/lib/generators/bootstrap/stimulus/templates/bootstrap_controller.js.tt +67 -0
- data/lib/generators/bootstrap/themed/themed_generator.rb +4 -0
- data/lib/twitter/bootstrap/rails/config.rb +17 -4
- data/lib/twitter/bootstrap/rails/doctor.rb +161 -11
- data/lib/twitter/bootstrap/rails/v6_migration.rb +156 -0
- data/lib/twitter/bootstrap/rails/version.rb +33 -1
- data/spec/lib/generators/agent_generator_spec.rb +9 -0
- data/spec/lib/generators/cdn_generator_spec.rb +31 -0
- data/spec/lib/generators/doctor_generator_spec.rb +108 -0
- data/spec/lib/generators/install_generator_spec.rb +51 -1
- data/spec/lib/generators/layout_generator_spec.rb +24 -0
- data/spec/lib/generators/nes_generator_spec.rb +164 -0
- data/spec/lib/generators/no_hardcoded_versions_spec.rb +3 -1
- data/spec/lib/generators/stimulus_generator_spec.rb +65 -0
- data/spec/lib/twitter_bootstrap_rails/v6_migration_spec.rb +98 -0
- data/spec/support/generator_spec_helper.rb +2 -0
- data/vendor/assets/javascripts/twitter/bootstrap/bootstrap.esm.min.js +7 -0
- data/vendor/assets/javascripts/twitter/bootstrap/popper.esm.js +15 -0
- metadata +31 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34e03d74439b02f3ce1da3ea93b4a9298978a32af11e82b1a3dd48526c1d0c1f
|
|
4
|
+
data.tar.gz: ddd677d336c9b7ae98479f85f95949c8530d69cf12a1d7865427de880f850abe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5939e73a695d58c36e2717857949625f67ae53d0632954d075a2d5d0c5b6465a2e43eae1b14285dc1cf03ac792ca3907737f8b4ed9f74c5a38a89690ae324381
|
|
7
|
+
data.tar.gz: 6c841f7baf8afc2bc4b83210d370c27ef0cd519c48b782f018e1c37b524e114fc7e1929cfdb429c73eae5c7fb023462d4074bd15e3cfa7a2745e1d753e319f3f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
## 5.6.0
|
|
2
|
+
|
|
3
|
+
### Added
|
|
4
|
+
|
|
5
|
+
- **`rails g bootstrap:install importmap`.** Vendors the stylesheet and Bootstrap's ES
|
|
6
|
+
module build, pins `bootstrap` and `@popperjs/core` in `config/importmap.rb`, and
|
|
7
|
+
imports Bootstrap from `app/javascript/application.js`. Popper's official UMD build
|
|
8
|
+
is wrapped with ES module exports, because Popper ships no single-file ES module.
|
|
9
|
+
- **`rails g bootstrap:stimulus`** writes a Stimulus controller that sets up tooltips
|
|
10
|
+
and popovers on each Turbo render, disposes of them afterwards, and closes modals,
|
|
11
|
+
offcanvases and dropdowns before Turbo caches a page.
|
|
12
|
+
- **`rails g bootstrap:nes`** sets up HeroDevs Bootstrap NES 4.6.5 (paid,
|
|
13
|
+
security-patched Bootstrap 4.6) through npm. It adds the aliased package and an
|
|
14
|
+
override to `package.json`, and the registry to `.npmrc` with the token read from
|
|
15
|
+
`${HERODEVS_NES_TOKEN}`. The doctor gets `nes_package` and `nes_registry` checks
|
|
16
|
+
and skips the legacy-markup scan. The agent guide tells agents to write Bootstrap 4
|
|
17
|
+
markup, and the Bootstrap 5 generators warn.
|
|
18
|
+
- **`rails g bootstrap:cdn --bootstrap=6`** prints the Bootstrap 6.0.0-alpha.1 tags,
|
|
19
|
+
with the bundle as an ES module. The doctor names a Bootstrap 6 prerelease and
|
|
20
|
+
points at `--v6`.
|
|
21
|
+
- The doctor has an `importmap_tags` check.
|
|
22
|
+
- The upstream `bootstrap-v4-v6-migration` skill is installed in this repository
|
|
23
|
+
next to `bootstrap-v5-v6-migration`.
|
|
24
|
+
- Gemspec metadata (changelog, source, bug tracker, documentation, funding), and
|
|
25
|
+
`rubygems_mfa_required`.
|
|
26
|
+
- A feature-request issue template and Dependabot for Bundler.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- **Requires Rails 7.1 or later** (was 5.0). Older lines get no security fixes and
|
|
31
|
+
weren't tested.
|
|
32
|
+
- `bootstrap:layout` keeps `javascript_importmap_tags` on apps with
|
|
33
|
+
`config/importmap.rb`. Regenerating the application layout used to drop it, which
|
|
34
|
+
turned off Turbo and Stimulus.
|
|
35
|
+
- `CONTRIBUTERS.md` is now `CONTRIBUTORS.md`.
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
|
|
39
|
+
- `WARP.md` and `.travis.yml`, which described the pre-5.4 toolchain.
|
|
40
|
+
- The unused `minitest`, `mocha`, `turn` and `coveralls` development gems.
|
|
41
|
+
|
|
42
|
+
## 5.5.1
|
|
43
|
+
|
|
44
|
+
### Added
|
|
45
|
+
|
|
46
|
+
- **Bootstrap 6 migration support.** `rails g bootstrap:doctor --v6` adds a
|
|
47
|
+
`v6_migration` check and list: Bootstrap 5 classes, data attributes, Sass
|
|
48
|
+
`@import`s and JavaScript calls that change in Bootstrap 6, with file, line and
|
|
49
|
+
replacement. It follows the upstream `bootstrap-v5-v6-migration` skill from
|
|
50
|
+
`twbs/bootstrap`, scans views, helpers, components, `app/javascript` and
|
|
51
|
+
stylesheets, skips the Bootstrap files this gem vendored, and only warns.
|
|
52
|
+
- The `bootstrap:agent` guide has a Bootstrap 6 section. It tells agents not to write
|
|
53
|
+
Bootstrap 6 markup on the Bootstrap 5 this gem ships, and gives the steps to migrate:
|
|
54
|
+
install the upstream skill with
|
|
55
|
+
`npx skills add twbs/bootstrap --skill bootstrap-v5-v6-migration`, run
|
|
56
|
+
`bootstrap:doctor --v6 --json`, and switch assets before markup.
|
|
57
|
+
- The upstream migration skill is installed in this repository
|
|
58
|
+
(`.claude/skills/bootstrap-v5-v6-migration`, pinned in `skills-lock.json`) for work
|
|
59
|
+
on the gem itself. It is not packaged into the gem.
|
|
60
|
+
|
|
61
|
+
### Changed
|
|
62
|
+
|
|
63
|
+
- `bootstrap:doctor` prints a heading above each list of findings.
|
|
64
|
+
|
|
1
65
|
## 5.5.0
|
|
2
66
|
|
|
3
67
|
### Added
|
data/README.md
CHANGED
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
[](https://github.com/seyhunak/twitter-bootstrap-rails/issues)
|
|
7
7
|
[](https://claude.com/claude-code)
|
|
8
8
|
|
|
9
|
-
Integrates Bootstrap 5.3.8 into Rails
|
|
10
|
-
Tested against Rails 8.1.4.1 and 8.0.5.2.
|
|
9
|
+
Integrates Bootstrap 5.3.8 into Rails on Propshaft, Sprockets, importmap or the CDN.
|
|
10
|
+
Supports Rails 8 and 7.1+. Tested against Rails 8.1.4.1 and 8.0.5.2.
|
|
11
|
+
Apps still on Bootstrap 4 can use [HeroDevs Bootstrap NES 4.6](#bootstrap-nes-46-herodevs).
|
|
11
12
|
|
|
12
13
|
> **Upgrade Rails.** [Rails 8.1.4.1 and 8.0.5.2](https://rubyonrails.org/2026/11/4/Rails-8.0.5.2-and-8.1.4.1-have-been-released)
|
|
13
14
|
> fix 21 security issues, and the Rails team strongly recommends upgrading as soon
|
|
14
|
-
> as possible. This gem
|
|
15
|
-
> installing it won't upgrade Rails for you. Run
|
|
15
|
+
> as possible. This gem requires Rails 7.1 or later but allows unpatched releases
|
|
16
|
+
> within that range, so installing it won't upgrade Rails for you. Run
|
|
17
|
+
> `bundle update rails` in your app.
|
|
16
18
|
> Security support for Rails 8.0 ends on 7 November 2026, and older series are
|
|
17
19
|
> already unsupported.
|
|
18
20
|
|
|
@@ -40,6 +42,7 @@ is reproducible from a command:
|
|
|
40
42
|
| CDN CSS `<link>` | `rails g bootstrap:cdn --css` |
|
|
41
43
|
| CDN JS bundle `<script>` | `rails g bootstrap:cdn --js` |
|
|
42
44
|
| Popper + `bootstrap.js` separately | `rails g bootstrap:cdn --separate-popper` |
|
|
45
|
+
| Bootstrap 6 prerelease tags | `rails g bootstrap:cdn --bootstrap=6` |
|
|
43
46
|
| Important globals (doctype, `lang`, viewport) | baked into every generated layout and the starter template |
|
|
44
47
|
|
|
45
48
|
```bash
|
|
@@ -49,6 +52,9 @@ rails g bootstrap:install static
|
|
|
49
52
|
# ...or load Bootstrap from the jsDelivr CDN instead
|
|
50
53
|
rails g bootstrap:install cdn
|
|
51
54
|
|
|
55
|
+
# ...or pin Bootstrap as an ES module in config/importmap.rb
|
|
56
|
+
rails g bootstrap:install importmap
|
|
57
|
+
|
|
52
58
|
# Generate a Bootstrap layout
|
|
53
59
|
rails g bootstrap:layout application
|
|
54
60
|
|
|
@@ -69,6 +75,9 @@ rails g bootstrap:cdn
|
|
|
69
75
|
rails g scaffold Task title:string done:boolean
|
|
70
76
|
rails db:migrate
|
|
71
77
|
rails g bootstrap:themed Tasks
|
|
78
|
+
|
|
79
|
+
# Keep tooltips, popovers and modals working with Turbo (needs Stimulus)
|
|
80
|
+
rails g bootstrap:stimulus
|
|
72
81
|
```
|
|
73
82
|
|
|
74
83
|
`bootstrap:install cdn` records the choice in `config/initializers/bootstrap.rb`,
|
|
@@ -83,6 +92,64 @@ run `rails g bootstrap:layout` after `bootstrap:install static` either way.
|
|
|
83
92
|
The Bootstrap version and its CDN URLs and integrity hashes live in one place,
|
|
84
93
|
`Twitter::Bootstrap::Rails::BOOTSTRAP_CDN`. No template hardcodes them.
|
|
85
94
|
|
|
95
|
+
### Importmap
|
|
96
|
+
|
|
97
|
+
`rails g bootstrap:install importmap` is for apps on importmap-rails (the Rails 7 and
|
|
98
|
+
8 default). It vendors the stylesheet, copies Bootstrap's ES module build and Popper
|
|
99
|
+
into `vendor/javascript/twitter/bootstrap/`, pins both in `config/importmap.rb`, and
|
|
100
|
+
adds `import "bootstrap"` to `app/javascript/application.js`. Your own modules can
|
|
101
|
+
then `import { Tooltip } from "bootstrap"`. Nothing is fetched from a CDN at runtime.
|
|
102
|
+
|
|
103
|
+
Popper ships no single-file ES module build, so the gem wraps Popper's official
|
|
104
|
+
UMD build with ES module exports.
|
|
105
|
+
|
|
106
|
+
`bootstrap:layout` now keeps `<%= javascript_importmap_tags %>` in the layout on any
|
|
107
|
+
app with `config/importmap.rb`. Earlier versions dropped it, so regenerating
|
|
108
|
+
`application` silently turned off Turbo and Stimulus. The doctor warns
|
|
109
|
+
(`importmap_tags`) if no layout loads the importmap.
|
|
110
|
+
|
|
111
|
+
### Turbo and Stimulus
|
|
112
|
+
|
|
113
|
+
Bootstrap's data attributes (`data-bs-toggle="modal"`, `"dropdown"`, `"collapse"`)
|
|
114
|
+
work with Turbo on their own. Tooltips and popovers are opt-in JavaScript, and an
|
|
115
|
+
open modal can be cached by Turbo and come back with its backdrop stuck. Run
|
|
116
|
+
`rails g bootstrap:stimulus` and add `data-controller="bootstrap"` to `<body>`. The
|
|
117
|
+
controller sets up tooltips and popovers on every render, disposes of them
|
|
118
|
+
afterwards, and closes modals, offcanvases and dropdowns before Turbo caches a page.
|
|
119
|
+
On importmap apps it imports Bootstrap, and elsewhere it uses the bundle's global.
|
|
120
|
+
|
|
121
|
+
### Bootstrap NES 4.6 (HeroDevs)
|
|
122
|
+
|
|
123
|
+
Apps that can't leave Bootstrap 4 yet can run
|
|
124
|
+
[HeroDevs Bootstrap NES 4.6](https://docs.herodevs.com/bootstrap/bootstrap-4-6), a
|
|
125
|
+
security-patched Bootstrap 4.6 (currently 4.6.5). It is a **paid** product served
|
|
126
|
+
from HeroDevs' private npm registry, so the gem can't vendor it. It sets your app
|
|
127
|
+
up to install it:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
rails g bootstrap:nes # package.json + .npmrc + initializer
|
|
131
|
+
export HERODEVS_NES_TOKEN=... # your HeroDevs access token
|
|
132
|
+
npm install
|
|
133
|
+
rails g bootstrap:doctor # checks the NES setup
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- It needs npm, so use jsbundling-rails or cssbundling-rails. importmap can't
|
|
137
|
+
install from an authenticated registry.
|
|
138
|
+
- `package.json` gets
|
|
139
|
+
`"bootstrap": "npm:@neverendingsupport/bootstrap@4.6.2-bootstrap-4.6.5"` plus a
|
|
140
|
+
matching `overrides` entry, so packages that depend on Bootstrap get NES too.
|
|
141
|
+
- `.npmrc` gets the registry and
|
|
142
|
+
`_authToken=${HERODEVS_NES_TOKEN}`, so the token stays in the environment and out
|
|
143
|
+
of git. Use `--token-env=NAME` for another variable name.
|
|
144
|
+
- Bootstrap 4's JavaScript needs jQuery.
|
|
145
|
+
- The doctor checks the package, the override, the registry and the token line. It
|
|
146
|
+
warns if a token is written into `.npmrc` or the NES release is older than the one
|
|
147
|
+
the gem knows, and it doesn't flag Bootstrap 4 markup as legacy.
|
|
148
|
+
- The gem's layout, themed and snippet generators and its view helpers write
|
|
149
|
+
Bootstrap 5 markup, so they warn on an NES app. `bootstrap:agent` tells coding
|
|
150
|
+
agents to write Bootstrap 4 markup and points them at the upstream
|
|
151
|
+
`bootstrap-v4-v6-migration` skill.
|
|
152
|
+
|
|
86
153
|
## Snippets
|
|
87
154
|
|
|
88
155
|
Every snippet published at
|
|
@@ -156,6 +223,7 @@ knows instead. The gem doesn't call any AI service and needs no API key.
|
|
|
156
223
|
rails g bootstrap:agent # write a guide tailored to this app
|
|
157
224
|
rails g bootstrap:doctor # check how Bootstrap is set up
|
|
158
225
|
rails g bootstrap:doctor --json # the same report, for agents and CI
|
|
226
|
+
rails g bootstrap:doctor --v6 # also list what changes in Bootstrap 6
|
|
159
227
|
rails g bootstrap:header --json # list a snippet's variants as JSON
|
|
160
228
|
```
|
|
161
229
|
|
|
@@ -179,6 +247,38 @@ In an existing app, `legacy_markup` works as a migration to-do list. Plain names
|
|
|
179
247
|
If Bootstrap comes from `package.json` or your importmap, the doctor warns that it
|
|
180
248
|
can't verify it rather than reporting an error.
|
|
181
249
|
|
|
250
|
+
### Preparing for Bootstrap 6
|
|
251
|
+
|
|
252
|
+
This gem ships Bootstrap 5.3.8. Bootstrap 6 is in alpha (`6.0.0-alpha.1` on npm),
|
|
253
|
+
and the Bootstrap team publishes an agent skill for the move from 5 to 6. Install it
|
|
254
|
+
into your app alongside the gem's own guide:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
npx skills add twbs/bootstrap --skill bootstrap-v5-v6-migration
|
|
258
|
+
rails g bootstrap:agent # the guide tells agents to stay on Bootstrap 5 markup until you migrate
|
|
259
|
+
rails g bootstrap:cdn --bootstrap=6 # prerelease CDN tags, to try Bootstrap 6 out
|
|
260
|
+
rails g bootstrap:doctor --v6 # the migration worklist
|
|
261
|
+
rails g bootstrap:doctor --v6 --json
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`--v6` adds a `v6_migration` check and list: every Bootstrap 5 class, data attribute,
|
|
265
|
+
Sass `@import` and JavaScript call that changes in Bootstrap 6, with file, line and
|
|
266
|
+
replacement. For example `modal-body` becomes `dialog-body`, `col-md-6` becomes
|
|
267
|
+
`md:col-6`, `btn-primary` becomes `btn-solid theme-primary`, and
|
|
268
|
+
`data-bs-toggle="dropdown"` becomes `data-bs-toggle="menu"`. It scans `app/views`,
|
|
269
|
+
`app/helpers`, `app/components`, `app/javascript` and your stylesheets, and skips the
|
|
270
|
+
Bootstrap files this gem vendored. It reports a warning, never an error, and is off
|
|
271
|
+
unless you ask for it.
|
|
272
|
+
|
|
273
|
+
Things the scan can't do for you:
|
|
274
|
+
|
|
275
|
+
- The vendored assets, `bootstrap:install` and every generator are still Bootstrap 5.
|
|
276
|
+
Switch the assets to Bootstrap 6 before changing markup, and don't re-run the
|
|
277
|
+
generators afterwards.
|
|
278
|
+
- The view helpers (`nav_bar`, `modal_dialog`, `badge` and the rest) render Bootstrap 5
|
|
279
|
+
markup at runtime, so their output isn't scanned.
|
|
280
|
+
- Bootstrap 6 changes the spacing scale, so check `p-*`/`m-*` utilities by eye.
|
|
281
|
+
|
|
182
282
|
## Quick Start
|
|
183
283
|
|
|
184
284
|
```bash
|
|
@@ -197,6 +297,17 @@ rails server
|
|
|
197
297
|
Run `bootstrap:layout` even if you already have a layout — that step is what puts
|
|
198
298
|
Bootstrap's CSS and JS on the page.
|
|
199
299
|
|
|
300
|
+
## Upgrading to 5.6.0
|
|
301
|
+
|
|
302
|
+
5.6.0 requires **Rails 7.1 or later**. Apps on older Rails should pin
|
|
303
|
+
`gem "twitter-bootstrap-rails", "~> 5.5.1"`.
|
|
304
|
+
|
|
305
|
+
If your app uses importmap and you generated its layout with an earlier version,
|
|
306
|
+
re-run `rails g bootstrap:layout` or add `<%= javascript_importmap_tags %>` to its
|
|
307
|
+
`<head>`: earlier layouts left it out. `rails g bootstrap:doctor` reports this as
|
|
308
|
+
`importmap_tags`. To load Bootstrap's JavaScript through the importmap instead of the
|
|
309
|
+
bundle, run `rails g bootstrap:install importmap`.
|
|
310
|
+
|
|
200
311
|
## Upgrading to 5.5.0
|
|
201
312
|
|
|
202
313
|
5.5.0 changes the HTML that the view helpers produce. They were still
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'erb'
|
|
2
2
|
require 'rails/generators'
|
|
3
3
|
require 'twitter/bootstrap/rails/doctor'
|
|
4
|
+
require 'twitter/bootstrap/rails/v6_migration'
|
|
4
5
|
require 'generators/bootstrap/snippets/snippet_catalog'
|
|
5
6
|
|
|
6
7
|
module Bootstrap
|
|
@@ -66,6 +67,22 @@ module Bootstrap
|
|
|
66
67
|
Twitter::Bootstrap::Rails::LegacyMarkup
|
|
67
68
|
end
|
|
68
69
|
|
|
70
|
+
def v6
|
|
71
|
+
Twitter::Bootstrap::Rails::V6Migration
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def nes?
|
|
75
|
+
facts[:asset_mode] == "nes"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def nes
|
|
79
|
+
Twitter::Bootstrap::Rails::BOOTSTRAP_NES
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def v4_skill_command
|
|
83
|
+
"npx skills add twbs/bootstrap --skill bootstrap-v4-v6-migration"
|
|
84
|
+
end
|
|
85
|
+
|
|
69
86
|
def pipeline_note
|
|
70
87
|
case facts[:asset_pipeline]
|
|
71
88
|
when "propshaft"
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Bootstrap in this app
|
|
2
2
|
|
|
3
|
+
<% if nes? -%>
|
|
4
|
+
This app uses Bootstrap <%= facts[:bootstrap_version] %> from <%= nes[:name] %>: security-patched Bootstrap 4.6, installed with npm from HeroDevs' private registry and set up by the twitter-bootstrap-rails gem (<%= facts[:gem_version] %>).
|
|
5
|
+
|
|
6
|
+
**Write Bootstrap 4 markup.** Bootstrap 4 uses <%= legacy::DATA_ATTRIBUTES.first(3).map { |name| "`data-#{name}`" }.join(", ") %> and so on, not `data-bs-*`, and Bootstrap 4 classes. The gem's layout, themed and snippet generators and its view helpers write Bootstrap 5 markup, which doesn't work here, so don't use them in this app.
|
|
7
|
+
<% else -%>
|
|
3
8
|
This app uses Bootstrap <%= facts[:bootstrap_version] %> through the twitter-bootstrap-rails gem (<%= facts[:gem_version] %>). Prefer the gem's generators and helpers over writing Bootstrap markup from memory, which is often out of date.
|
|
9
|
+
<% end -%>
|
|
4
10
|
|
|
5
11
|
This guide is generated. Run `rails g bootstrap:agent` again after upgrading the gem or changing the asset setup.
|
|
6
12
|
|
|
@@ -9,6 +15,18 @@ This guide is generated. Run `rails g bootstrap:agent` again after upgrading the
|
|
|
9
15
|
- Asset pipeline: <%= pipeline_note %>
|
|
10
16
|
- Bootstrap assets: <%= facts[:asset_mode] %>
|
|
11
17
|
- Template engine: <%= facts[:template_engine] %>
|
|
18
|
+
<% if nes? -%>
|
|
19
|
+
|
|
20
|
+
## Workflow
|
|
21
|
+
|
|
22
|
+
1. Run `rails g bootstrap:doctor --json` to check the NES setup: the package in `package.json`, and the registry and token in `.npmrc`. It writes nothing, and it exits 1 if a check reports an error.
|
|
23
|
+
2. npm reads the access token from the `<%= nes[:token_env] %>` environment variable (or the name in `.npmrc`). Never write the token into a file.
|
|
24
|
+
3. Bootstrap 4's JavaScript needs jQuery, imported before Bootstrap.
|
|
25
|
+
|
|
26
|
+
## Moving off Bootstrap 4
|
|
27
|
+
|
|
28
|
+
NES keeps Bootstrap 4.6 patched, but the gem's tooling targets Bootstrap 5. To migrate, install the upstream skill with `<%= v4_skill_command %>` and follow it. To stop at Bootstrap 5, switch `package.json` back to the public `bootstrap` package, run `rails g bootstrap:install`, then use `rails g bootstrap:doctor` to find the Bootstrap 4 markup that needs changing.
|
|
29
|
+
<% else -%>
|
|
12
30
|
|
|
13
31
|
## Workflow
|
|
14
32
|
|
|
@@ -33,9 +51,10 @@ Snippets are always written as ERB partials. They render from any template engin
|
|
|
33
51
|
|
|
34
52
|
## Other generators
|
|
35
53
|
|
|
36
|
-
- `bootstrap:install static` or `bootstrap:install
|
|
37
|
-
- `bootstrap:layout [NAME]`: writes a layout that loads Bootstrap. Don't overwrite an existing layout without checking its contents first.
|
|
54
|
+
- `bootstrap:install static`, `bootstrap:install cdn` or `bootstrap:install importmap`: sets up Bootstrap's assets. `importmap` pins Bootstrap as an ES module, so `import { Tooltip } from "bootstrap"` works.
|
|
55
|
+
- `bootstrap:layout [NAME]`: writes a layout that loads Bootstrap, and keeps `javascript_importmap_tags` on importmap apps. Don't overwrite an existing layout without checking its contents first.
|
|
38
56
|
- `bootstrap:themed RESOURCE`: writes Bootstrap views for a scaffold.
|
|
57
|
+
- `bootstrap:stimulus`: writes a Stimulus controller that sets up tooltips and popovers on each Turbo render and closes modals before Turbo caches a page. Attach it with `data-controller="bootstrap"` on `<body>`.
|
|
39
58
|
- `bootstrap:cdn`: prints the CDN tags and writes nothing.
|
|
40
59
|
|
|
41
60
|
## View helpers
|
|
@@ -45,6 +64,18 @@ Snippets are always written as ERB partials. They render from any template engin
|
|
|
45
64
|
- Modals: `modal_dialog`, `modal_toggle`, `modal_cancel_button`
|
|
46
65
|
- Other: `badge`, `tag_label`, `render_breadcrumbs`, `add_breadcrumb`, and `error_span` on form builders
|
|
47
66
|
|
|
67
|
+
## Bootstrap 6
|
|
68
|
+
|
|
69
|
+
This app runs Bootstrap <%= facts[:bootstrap_version] %>. Don't write Bootstrap 6 markup (`dialog`, `drawer`, `menu`, `md:col-6`, `btn-solid theme-primary`) unless the app is being moved to Bootstrap 6: none of it works on <%= facts[:bootstrap_version] %>. The gem's generators and helpers produce Bootstrap 5 markup.
|
|
70
|
+
|
|
71
|
+
To move the app to Bootstrap 6:
|
|
72
|
+
|
|
73
|
+
1. Install the upstream migration skill: `<%= v6::SKILL_COMMAND %>`. Follow it alongside this guide.
|
|
74
|
+
2. Run `rails g bootstrap:doctor --v6 --json`. It lists every Bootstrap 5 class, data attribute, Sass import and JavaScript call that changes, with file, line and replacement, under `v6_migration`.
|
|
75
|
+
3. Switch the Bootstrap assets before changing markup, because the vendored files and `bootstrap:install` are Bootstrap 5. `rails g bootstrap:cdn --bootstrap=6` prints the prerelease CDN tags. Re-running `bootstrap:layout`, `bootstrap:themed` or a snippet generator writes Bootstrap 5 markup again.
|
|
76
|
+
4. The helpers in "View helpers" render Bootstrap 5 markup at runtime, so the scan can't see their output. Replace them with Bootstrap 6 markup in the views that use them.
|
|
77
|
+
5. v6 changes the spacing scale (`p-3` is smaller), so check spacing utilities by eye; the scan doesn't flag them.
|
|
78
|
+
|
|
48
79
|
## Markup to avoid
|
|
49
80
|
|
|
50
81
|
These come from older Bootstrap versions and do nothing on this one. `bootstrap:doctor` reports them, with file and line, under `legacy_markup`. Plain names like `close` or `well` may be the app's own CSS classes, so check those before changing them.
|
|
@@ -59,3 +90,4 @@ Data attributes: <%= legacy::DATA_ATTRIBUTES.map { |name| "`data-#{name}`" }.joi
|
|
|
59
90
|
<% legacy::CLASS_PATTERNS.each do |_pattern, _replacement, example| -%>
|
|
60
91
|
| <%= example.split(" become").first %> | <%= example.split(/ becomes? /).last %> |
|
|
61
92
|
<% end -%>
|
|
93
|
+
<% end -%>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'twitter/bootstrap/rails/config'
|
|
2
|
+
require 'twitter/bootstrap/rails/version'
|
|
3
|
+
|
|
4
|
+
module Bootstrap
|
|
5
|
+
module Generators
|
|
6
|
+
# For generators that write Bootstrap 5 markup. On an app running HeroDevs
|
|
7
|
+
# Bootstrap NES 4.6 that markup doesn't work, so say so before writing it.
|
|
8
|
+
module Bootstrap5Markup
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def warn_if_nes
|
|
12
|
+
return unless Twitter::Bootstrap::Rails.nes?
|
|
13
|
+
|
|
14
|
+
say_status :warn,
|
|
15
|
+
"This app runs Bootstrap #{Twitter::Bootstrap::Rails::BOOTSTRAP_NES[:bootstrap_version]} (NES), but this " \
|
|
16
|
+
"generator writes Bootstrap 5 markup, which needs data-bs-* attributes and Bootstrap 5 classes. " \
|
|
17
|
+
"Convert it to Bootstrap 4 markup, or migrate the app first.",
|
|
18
|
+
:yellow
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -17,21 +17,51 @@ module Bootstrap
|
|
|
17
17
|
:desc => 'Print only the JavaScript bundle script'
|
|
18
18
|
class_option :'separate-popper', :type => :boolean, :default => false,
|
|
19
19
|
:desc => 'Print Popper and bootstrap.js as separate tags instead of the bundle'
|
|
20
|
+
class_option :bootstrap, :type => :string, :default => "5",
|
|
21
|
+
:desc => "Bootstrap major version: 5 (#{Twitter::Bootstrap::Rails::BOOTSTRAP_VERSION}) or 6 " \
|
|
22
|
+
"(the #{Twitter::Bootstrap::Rails::BOOTSTRAP_NEXT_VERSION} prerelease)"
|
|
23
|
+
|
|
24
|
+
def validate_version
|
|
25
|
+
unless %w[5 6].include?(options[:bootstrap])
|
|
26
|
+
raise ::Rails::Generators::Error,
|
|
27
|
+
"--bootstrap must be 5 or 6. For HeroDevs Bootstrap NES 4.6, run `rails g bootstrap:nes`."
|
|
28
|
+
end
|
|
29
|
+
return unless next_version? && options[:'separate-popper']
|
|
30
|
+
|
|
31
|
+
raise ::Rails::Generators::Error,
|
|
32
|
+
"--separate-popper does not apply to Bootstrap 6, whose bundle includes Floating UI."
|
|
33
|
+
end
|
|
20
34
|
|
|
21
35
|
def print_tags
|
|
22
36
|
say tags.join("\n")
|
|
23
37
|
end
|
|
24
38
|
|
|
39
|
+
def warn_about_prerelease
|
|
40
|
+
return unless next_version?
|
|
41
|
+
|
|
42
|
+
say_status :warn,
|
|
43
|
+
"Bootstrap #{Twitter::Bootstrap::Rails::BOOTSTRAP_NEXT_VERSION} is a prerelease. This gem's generators and helpers " \
|
|
44
|
+
"write Bootstrap 5 markup, which needs migrating: run `rails g bootstrap:doctor --v6` for the list.",
|
|
45
|
+
:yellow
|
|
46
|
+
end
|
|
47
|
+
|
|
25
48
|
private
|
|
26
49
|
|
|
50
|
+
def next_version?
|
|
51
|
+
options[:bootstrap] == "6"
|
|
52
|
+
end
|
|
53
|
+
|
|
27
54
|
def tags
|
|
28
|
-
|
|
55
|
+
css = next_version? ? next_css_tag : css_tag
|
|
56
|
+
return [css] if options[:css] && !options[:js]
|
|
29
57
|
return [javascript_tags] if options[:js] && !options[:css]
|
|
30
58
|
|
|
31
|
-
[
|
|
59
|
+
[css, javascript_tags]
|
|
32
60
|
end
|
|
33
61
|
|
|
34
62
|
def javascript_tags
|
|
63
|
+
return next_bundle_tag if next_version?
|
|
64
|
+
|
|
35
65
|
options[:'separate-popper'] ? separate_popper_tags : bundle_tag
|
|
36
66
|
end
|
|
37
67
|
end
|
|
@@ -23,6 +23,17 @@ module Bootstrap
|
|
|
23
23
|
script_tag(:popper)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
# Bootstrap 6 ships only ES modules, so its bundle needs type="module".
|
|
27
|
+
def next_css_tag
|
|
28
|
+
entry = Twitter::Bootstrap::Rails::BOOTSTRAP_NEXT_CDN.fetch(:css)
|
|
29
|
+
%{<link href="#{entry[:url]}" rel="stylesheet" integrity="#{entry[:integrity]}" crossorigin="anonymous">}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def next_bundle_tag
|
|
33
|
+
entry = Twitter::Bootstrap::Rails::BOOTSTRAP_NEXT_CDN.fetch(:bundle)
|
|
34
|
+
%{<script type="module" src="#{entry[:url]}" integrity="#{entry[:integrity]}" crossorigin="anonymous"></script>}
|
|
35
|
+
end
|
|
36
|
+
|
|
26
37
|
# Popper and bootstrap.js as the separate pair, in the docs' order.
|
|
27
38
|
def separate_popper_tags
|
|
28
39
|
[popper_tag, js_tag].join("\n")
|
|
@@ -11,9 +11,11 @@ module Bootstrap
|
|
|
11
11
|
|
|
12
12
|
class_option :json, :type => :boolean, :default => false,
|
|
13
13
|
:desc => 'Print the report as JSON'
|
|
14
|
+
class_option :v6, :type => :boolean, :default => false,
|
|
15
|
+
:desc => 'Also list Bootstrap 5 code that changes in Bootstrap 6'
|
|
14
16
|
|
|
15
17
|
def diagnose
|
|
16
|
-
report = Twitter::Bootstrap::Rails::Doctor.new(destination_root).report
|
|
18
|
+
report = Twitter::Bootstrap::Rails::Doctor.new(destination_root).report(:v6 => options[:v6])
|
|
17
19
|
|
|
18
20
|
options[:json] ? say(JSON.pretty_generate(report)) : print_report(report)
|
|
19
21
|
exit(1) if report[:status] == "error"
|
|
@@ -30,7 +32,15 @@ module Bootstrap
|
|
|
30
32
|
say " #{' ' * 20} Fix: #{check[:fix]}" if check[:fix]
|
|
31
33
|
end
|
|
32
34
|
|
|
33
|
-
report[:legacy_markup]
|
|
35
|
+
print_findings("Older Bootstrap markup", report[:legacy_markup])
|
|
36
|
+
print_findings("Changes in Bootstrap 6", report[:v6_migration])
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def print_findings(title, findings)
|
|
40
|
+
return if findings.nil? || findings.empty?
|
|
41
|
+
|
|
42
|
+
say "\n#{title}:"
|
|
43
|
+
findings.each do |finding|
|
|
34
44
|
say " #{finding[:file]}:#{finding[:line]} #{finding[:found]} -> #{finding[:replacement]}"
|
|
35
45
|
end
|
|
36
46
|
end
|
|
@@ -12,22 +12,43 @@ module Bootstrap
|
|
|
12
12
|
|
|
13
13
|
source_root File.expand_path("../templates", __FILE__)
|
|
14
14
|
desc "This generator installs Bootstrap #{Twitter::Bootstrap::Rails::BOOTSTRAP_VERSION} to the Asset Pipeline"
|
|
15
|
+
MODES = %w[static cdn importmap].freeze
|
|
16
|
+
|
|
15
17
|
argument :asset_mode, :type => :string, :default => 'static',
|
|
16
|
-
:banner => '
|
|
17
|
-
:desc => 'static vendors Bootstrap into the
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
:banner => MODES.join(' | '),
|
|
19
|
+
:desc => 'static vendors Bootstrap into the asset pipeline; cdn links to jsDelivr; ' \
|
|
20
|
+
'importmap vendors the stylesheet and pins Bootstrap as an ES module'
|
|
21
|
+
|
|
22
|
+
STYLESHEET = ['vendor/assets/stylesheets/twitter/bootstrap/bootstrap.min.css',
|
|
23
|
+
'app/assets/stylesheets/twitter/bootstrap/bootstrap.min.css'].freeze
|
|
24
|
+
BUNDLE = ['vendor/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js',
|
|
25
|
+
'app/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js'].freeze
|
|
26
|
+
# importmap-rails serves vendor/javascript, and these paths are what the pins name.
|
|
27
|
+
ES_MODULES = [
|
|
28
|
+
['vendor/assets/javascripts/twitter/bootstrap/bootstrap.esm.min.js',
|
|
29
|
+
'vendor/javascript/twitter/bootstrap/bootstrap.esm.min.js'],
|
|
30
|
+
['vendor/assets/javascripts/twitter/bootstrap/popper.esm.js',
|
|
31
|
+
'vendor/javascript/twitter/bootstrap/popper.esm.js']
|
|
24
32
|
].freeze
|
|
33
|
+
PINS = {
|
|
34
|
+
"bootstrap" => ["twitter/bootstrap/bootstrap.esm.min.js", "Bootstrap #{Twitter::Bootstrap::Rails::BOOTSTRAP_VERSION}"],
|
|
35
|
+
"@popperjs/core" => ["twitter/bootstrap/popper.esm.js", "Popper #{Twitter::Bootstrap::Rails::POPPER_VERSION}"]
|
|
36
|
+
}.freeze
|
|
37
|
+
IMPORTMAP = "config/importmap.rb".freeze
|
|
38
|
+
APPLICATION_JS = "app/javascript/application.js".freeze
|
|
25
39
|
|
|
26
40
|
def validate_asset_mode
|
|
27
|
-
|
|
41
|
+
unless MODES.include?(asset_mode)
|
|
42
|
+
raise ::Rails::Generators::Error,
|
|
43
|
+
"Unknown asset mode #{asset_mode.inspect}. Expected one of #{MODES.join(', ')}. " \
|
|
44
|
+
"For HeroDevs Bootstrap NES 4.6, run `rails g bootstrap:nes`."
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
return unless importmap? && !exists_in_app?(IMPORTMAP)
|
|
28
48
|
|
|
29
49
|
raise ::Rails::Generators::Error,
|
|
30
|
-
"
|
|
50
|
+
"importmap mode needs importmap-rails, but #{IMPORTMAP} does not exist. " \
|
|
51
|
+
"Run `bin/rails importmap:install` first, or use `bootstrap:install static`."
|
|
31
52
|
end
|
|
32
53
|
|
|
33
54
|
def add_assets
|
|
@@ -38,7 +59,9 @@ module Bootstrap
|
|
|
38
59
|
|
|
39
60
|
js_manifest = 'app/assets/javascripts/application.js'
|
|
40
61
|
|
|
41
|
-
if
|
|
62
|
+
if importmap?
|
|
63
|
+
# Bootstrap's JavaScript comes from the importmap, not the manifest.
|
|
64
|
+
elsif exists_in_app?(js_manifest)
|
|
42
65
|
add_require(js_manifest,
|
|
43
66
|
"//= require twitter/bootstrap/bootstrap.bundle.min\n",
|
|
44
67
|
"application\n",
|
|
@@ -62,7 +85,8 @@ module Bootstrap
|
|
|
62
85
|
def copy_bootstrap_assets
|
|
63
86
|
return if cdn?
|
|
64
87
|
|
|
65
|
-
|
|
88
|
+
vendored = [STYLESHEET] + (importmap? ? ES_MODULES : [BUNDLE])
|
|
89
|
+
vendored.each do |relative_source, destination|
|
|
66
90
|
source = File.join(gem_root, relative_source)
|
|
67
91
|
|
|
68
92
|
unless File.file?(source)
|
|
@@ -75,22 +99,46 @@ module Bootstrap
|
|
|
75
99
|
end
|
|
76
100
|
end
|
|
77
101
|
|
|
102
|
+
def pin_modules
|
|
103
|
+
return unless importmap?
|
|
104
|
+
|
|
105
|
+
existing = read_from_app(IMPORTMAP)
|
|
106
|
+
pins = PINS.reject { |name, _| existing.match?(/^\s*pin\s+["']#{Regexp.escape(name)}["']/) }
|
|
107
|
+
.map { |name, (path, label)| %{pin "#{name}", to: "#{path}" # #{label} via twitter-bootstrap-rails\n} }
|
|
108
|
+
append_to_file IMPORTMAP, "\n" + pins.join unless pins.empty?
|
|
109
|
+
|
|
110
|
+
if exists_in_app?(APPLICATION_JS)
|
|
111
|
+
unless read_from_app(APPLICATION_JS).match?(/^\s*import\s+(?:\*\s+as\s+\w+\s+from\s+)?["']bootstrap["']/)
|
|
112
|
+
append_to_file APPLICATION_JS, %{import "bootstrap"\n}
|
|
113
|
+
end
|
|
114
|
+
else
|
|
115
|
+
say_status :warn, "#{APPLICATION_JS} not found. Add `import \"bootstrap\"` to your JavaScript entry point.", :yellow
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
78
119
|
def add_bootstrap
|
|
79
120
|
return if cdn?
|
|
80
121
|
return if propshaft?
|
|
81
122
|
|
|
82
|
-
copy_file "bootstrap.js", "app/assets/javascripts/bootstrap.js"
|
|
123
|
+
copy_file "bootstrap.js", "app/assets/javascripts/bootstrap.js" unless importmap?
|
|
83
124
|
copy_file "bootstrap_and_overrides.css", "app/assets/stylesheets/bootstrap_and_overrides.css"
|
|
84
125
|
end
|
|
85
126
|
|
|
86
|
-
def
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
def add_mode_initializer
|
|
128
|
+
if cdn?
|
|
129
|
+
create_file "config/initializers/bootstrap.rb", <<~RUBY
|
|
130
|
+
# Bootstrap's CSS and JS are loaded from jsDelivr rather than vendored into
|
|
131
|
+
# this app. `rails g bootstrap:layout` reads this to emit CDN tags by default.
|
|
132
|
+
Twitter::Bootstrap::Rails.asset_mode = :cdn
|
|
133
|
+
RUBY
|
|
134
|
+
elsif importmap?
|
|
135
|
+
create_file "config/initializers/bootstrap.rb", <<~RUBY
|
|
136
|
+
# Bootstrap's stylesheet is vendored into the asset pipeline and its JavaScript
|
|
137
|
+
# is pinned in config/importmap.rb. `rails g bootstrap:layout` reads this to
|
|
138
|
+
# leave Bootstrap's JavaScript to the importmap.
|
|
139
|
+
Twitter::Bootstrap::Rails.asset_mode = :importmap
|
|
140
|
+
RUBY
|
|
141
|
+
end
|
|
94
142
|
end
|
|
95
143
|
|
|
96
144
|
def add_locale
|
|
@@ -111,6 +159,10 @@ module Bootstrap
|
|
|
111
159
|
if cdn?
|
|
112
160
|
say "Bootstrap #{version} will be loaded from jsDelivr. " \
|
|
113
161
|
"Run `rails g bootstrap:layout` to generate a layout with the CDN tags."
|
|
162
|
+
elsif importmap?
|
|
163
|
+
say "Bootstrap #{version} pinned in #{IMPORTMAP} and imported from #{APPLICATION_JS}. " \
|
|
164
|
+
"Use `import { Tooltip } from \"bootstrap\"` in your own modules. " \
|
|
165
|
+
"Run `rails g bootstrap:layout` if your layout doesn't link the stylesheet yet."
|
|
114
166
|
elsif propshaft?
|
|
115
167
|
say "Bootstrap #{version} vendored for Propshaft. " \
|
|
116
168
|
"Run `rails g bootstrap:layout` to generate a layout that links it."
|
|
@@ -125,6 +177,10 @@ module Bootstrap
|
|
|
125
177
|
asset_mode == 'cdn'
|
|
126
178
|
end
|
|
127
179
|
|
|
180
|
+
def importmap?
|
|
181
|
+
asset_mode == 'importmap'
|
|
182
|
+
end
|
|
183
|
+
|
|
128
184
|
def propshaft?
|
|
129
185
|
Twitter::Bootstrap::Rails.propshaft?
|
|
130
186
|
end
|