twitter-bootstrap-rails 5.4.0 → 5.5.1

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +68 -0
  3. data/README.md +104 -1
  4. data/app/helpers/badge_label_helper.rb +5 -6
  5. data/app/helpers/bootstrap_flash_helper.rb +10 -5
  6. data/app/helpers/flash_block_helper.rb +6 -4
  7. data/app/helpers/form_errors_helper.rb +3 -2
  8. data/app/helpers/modal_helper.rb +13 -13
  9. data/app/helpers/navbar_helper.rb +54 -47
  10. data/app/helpers/twitter_breadcrumbs_helper.rb +2 -2
  11. data/app/views/twitter-bootstrap/_breadcrumbs.html.erb +11 -11
  12. data/lib/generators/bootstrap/agent/agent_generator.rb +86 -0
  13. data/lib/generators/bootstrap/agent/templates/guide.md.erb +73 -0
  14. data/lib/generators/bootstrap/doctor/doctor_generator.rb +49 -0
  15. data/lib/generators/bootstrap/partial/templates/_login.html.erb +11 -15
  16. data/lib/generators/bootstrap/snippets/snippet_base.rb +23 -4
  17. data/lib/generators/bootstrap/themed/templates/_form.html.haml +7 -9
  18. data/lib/generators/bootstrap/themed/templates/_form.html.slim +8 -10
  19. data/lib/generators/bootstrap/themed/templates/edit.html.erb +1 -1
  20. data/lib/generators/bootstrap/themed/templates/edit.html.haml +1 -1
  21. data/lib/generators/bootstrap/themed/templates/edit.html.slim +1 -1
  22. data/lib/generators/bootstrap/themed/templates/index.html.haml +4 -4
  23. data/lib/generators/bootstrap/themed/templates/index.html.slim +4 -4
  24. data/lib/generators/bootstrap/themed/templates/new.html.erb +1 -1
  25. data/lib/generators/bootstrap/themed/templates/new.html.haml +1 -1
  26. data/lib/generators/bootstrap/themed/templates/new.html.slim +1 -1
  27. data/lib/generators/bootstrap/themed/templates/show.html.erb +1 -1
  28. data/lib/generators/bootstrap/themed/templates/show.html.haml +3 -3
  29. data/lib/generators/bootstrap/themed/templates/show.html.slim +3 -3
  30. data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.erb +1 -1
  31. data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.haml +2 -2
  32. data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.slim +2 -2
  33. data/lib/twitter/bootstrap/rails/doctor.rb +238 -0
  34. data/lib/twitter/bootstrap/rails/legacy_markup.rb +119 -0
  35. data/lib/twitter/bootstrap/rails/v6_migration.rb +156 -0
  36. data/lib/twitter/bootstrap/rails/version.rb +1 -1
  37. data/spec/lib/breadcrumbs_spec.rb +8 -2
  38. data/spec/lib/generators/agent_generator_spec.rb +120 -0
  39. data/spec/lib/generators/doctor_generator_spec.rb +272 -0
  40. data/spec/lib/generators/snippet_generators_spec.rb +23 -0
  41. data/spec/lib/twitter_bootstrap_rails/badge_label_helper_spec.rb +7 -3
  42. data/spec/lib/twitter_bootstrap_rails/bootstrap_flash_helper_spec.rb +23 -45
  43. data/spec/lib/twitter_bootstrap_rails/breadcrumbs_view_spec.rb +35 -0
  44. data/spec/lib/twitter_bootstrap_rails/flash_block_helper_spec.rb +26 -0
  45. data/spec/lib/twitter_bootstrap_rails/form_errors_helper_spec.rb +2 -2
  46. data/spec/lib/twitter_bootstrap_rails/legacy_markup_spec.rb +74 -0
  47. data/spec/lib/twitter_bootstrap_rails/modal_helper_spec.rb +21 -8
  48. data/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb +94 -92
  49. data/spec/lib/twitter_bootstrap_rails/v6_migration_spec.rb +98 -0
  50. data/spec/spec_helper.rb +0 -1
  51. data/spec/support/generator_spec_helper.rb +2 -0
  52. metadata +24 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c179497e697969f22082029863a8961ef3bc5c662c7b62a108238dd14b72a9ac
4
- data.tar.gz: 2500bd3b9f13b5a44d3a7403e9ab48b0d995ac9ede9605a21ffcf7257cd67dc2
3
+ metadata.gz: 875edfcbadfdb5b579da81a68c3a5dc44d7b14d208bcf7de6dc89a8dabe969d3
4
+ data.tar.gz: bc3f64fe1f6c45217d043887a9fbcab629e7161738b2c47c3ea46a0a830b1cb1
5
5
  SHA512:
6
- metadata.gz: b394fbf43caa16b0288e3357ec3c47745e1dc10c19149f18040a463165c0ca9a2e2843108db50c821941b01f800eb97f449e918056127ae90473cd39f466c8e7
7
- data.tar.gz: 1c51ce6849e58c49b9017ac95d7b58bff2c44bb6b23eff6137120f43450cf645a9328d9218ec83c842c99885ae51b5f8453a2c96aa33cd90ab2f6bfba942b578
6
+ metadata.gz: 18bd87131c776f3da869462fb6af504614dd708a91434881a9e46955a3e7817cdbcd8071e3d490a5bd18841b3601016e632e73163071786c026b5a2fb52cfc74
7
+ data.tar.gz: 75630ca82664a7956d088fbc90b48d2eb1f11e89087488dcb7a5b209221aff58ccabc2296546a4be9fc83595109b6b31fc41db9be8e931a23818ac8f6dea8841
data/CHANGELOG.md CHANGED
@@ -1,3 +1,71 @@
1
+ ## 5.5.1
2
+
3
+ ### Added
4
+
5
+ - **Bootstrap 6 migration support.** `rails g bootstrap:doctor --v6` adds a
6
+ `v6_migration` check and list: Bootstrap 5 classes, data attributes, Sass
7
+ `@import`s and JavaScript calls that change in Bootstrap 6, with file, line and
8
+ replacement. It follows the upstream `bootstrap-v5-v6-migration` skill from
9
+ `twbs/bootstrap`, scans views, helpers, components, `app/javascript` and
10
+ stylesheets, skips the Bootstrap files this gem vendored, and only warns.
11
+ - The `bootstrap:agent` guide has a Bootstrap 6 section. It tells agents not to write
12
+ Bootstrap 6 markup on the Bootstrap 5 this gem ships, and gives the steps to migrate:
13
+ install the upstream skill with
14
+ `npx skills add twbs/bootstrap --skill bootstrap-v5-v6-migration`, run
15
+ `bootstrap:doctor --v6 --json`, and switch assets before markup.
16
+ - The upstream migration skill is installed in this repository
17
+ (`.claude/skills/bootstrap-v5-v6-migration`, pinned in `skills-lock.json`) for work
18
+ on the gem itself. It is not packaged into the gem.
19
+
20
+ ### Changed
21
+
22
+ - `bootstrap:doctor` prints a heading above each list of findings.
23
+
24
+ ## 5.5.0
25
+
26
+ ### Added
27
+
28
+ - **`rails g bootstrap:doctor`** checks how Bootstrap is set up in an app: whether
29
+ layouts load its CSS and JS, stale versions, an unrendered icon sprite, leftover
30
+ placeholder images, and markup from older Bootstrap versions with file and line.
31
+ `--json` prints a machine-readable report. It writes nothing and exits 1 if a
32
+ check reports an error.
33
+ - **`rails g bootstrap:agent`** writes a guide for coding agents, tailored to the
34
+ app: a Claude skill and a section in `AGENTS.md`. It keeps the rest of `AGENTS.md`
35
+ and replaces its own section when run again.
36
+ - **`--json`** on every snippet generator lists the variants as JSON.
37
+
38
+ ### Changed
39
+
40
+ - **View helpers now produce Bootstrap 5 markup.** They were still producing
41
+ Bootstrap 3 markup, so toggles, dropdowns and close buttons did nothing on the
42
+ Bootstrap 5 this gem ships. This changes their HTML, so custom CSS or tests that
43
+ rely on the old output need updating:
44
+ - `nav_bar` and the menu helpers use `navbar-expand`, `nav-item` and `nav-link`.
45
+ `:inverse` uses `data-bs-theme="dark"`, and `:static` no longer adds a class.
46
+ - `menu_item` puts `active` on the link rather than the `li`.
47
+ - `drop_down_submenu` renders a labelled group, because Bootstrap 5 has no nested
48
+ dropdowns.
49
+ - `menu_text` renders a `span`.
50
+ - `badge` and `tag_label` render `badge text-bg-*`, defaulting to `secondary`.
51
+ - `modal_toggle` and `modal_cancel_button` use `btn-secondary`, and the modal title
52
+ is an `h5`.
53
+ - `error_span` defaults to `invalid-feedback d-block` inside `has-validation`.
54
+ - `render_breadcrumbs` renders `nav > ol.breadcrumb`. The divider is set through
55
+ `--bs-breadcrumb-divider`, so `:divider_class` no longer applies.
56
+ - The Haml and Slim themed templates, the simple_form templates and the Devise login
57
+ partial now use Bootstrap 5 markup too.
58
+
59
+ ### Fixed
60
+
61
+ - `modal_cancel_button` raised `NoMethodError` on Rails 8.1.
62
+ - `modal_dialog` ignored `:size`.
63
+ - `close_button` didn't escape its dismiss target.
64
+ - `bootstrap_flash` dropped the `:class` option after the first message.
65
+ - `flash_block` used `alert-notice` and `alert-alert`, which don't exist.
66
+ - `render_breadcrumbs` ignored its default options, so the last crumb wasn't styled
67
+ as active.
68
+
1
69
  ## 5.4.0
2
70
 
3
71
  Bootstrap **5.3.8**. The gem version no longer tracks the Bootstrap version;
data/README.md CHANGED
@@ -4,8 +4,17 @@
4
4
  [![GitHub stars](https://img.shields.io/github/stars/seyhunak/twitter-bootstrap-rails.svg)](https://github.com/seyhunak/twitter-bootstrap-rails/stargazers)
5
5
  [![GitHub forks](https://img.shields.io/github/forks/seyhunak/twitter-bootstrap-rails.svg)](https://github.com/seyhunak/twitter-bootstrap-rails/network)
6
6
  [![GitHub issues](https://img.shields.io/github/issues/seyhunak/twitter-bootstrap-rails.svg)](https://github.com/seyhunak/twitter-bootstrap-rails/issues)
7
+ [![Built with Claude Code](https://img.shields.io/badge/Built%20with-Claude%20Code-D97757?logo=claude&logoColor=white)](https://claude.com/claude-code)
7
8
 
8
9
  Integrates Bootstrap 5.3.8 into Rails Asset Pipeline. Supports Rails 8, 7, 6, 5.
10
+ Tested against Rails 8.1.4.1 and 8.0.5.2.
11
+
12
+ > **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
+ > fix 21 security issues, and the Rails team strongly recommends upgrading as soon
14
+ > as possible. This gem's dependency range still allows older Rails versions, so
15
+ > installing it won't upgrade Rails for you. Run `bundle update rails` in your app.
16
+ > Security support for Rails 8.0 ends on 7 November 2026, and older series are
17
+ > already unsupported.
9
18
 
10
19
  ## Install
11
20
 
@@ -110,6 +119,7 @@ Options, on every snippet command:
110
119
  | Option | Effect |
111
120
  |---|---|
112
121
  | `--list` | Print the variants with descriptions and exit, writing nothing |
122
+ | `--json` | Print the variants as JSON and exit, writing nothing |
113
123
  | `--as=NAME` | Partial name to write (default: the generator name) |
114
124
  | `--path=DIR` | Where to write it (default: `app/views/shared`) |
115
125
  | `--no-icons` | Skip installing the shared icon sprite |
@@ -136,6 +146,71 @@ near the top of `<body>` in your layout, or those icons come out as empty boxes:
136
146
  <%= render "shared/bootstrap_icons" %>
137
147
  ```
138
148
 
149
+ ## Coding agents
150
+
151
+ Agents like Claude Code, Cursor and Codex often write outdated Bootstrap from memory
152
+ or guess at an app's asset setup. These commands let them use what this gem already
153
+ knows instead. The gem doesn't call any AI service and needs no API key.
154
+
155
+ ```bash
156
+ rails g bootstrap:agent # write a guide tailored to this app
157
+ rails g bootstrap:doctor # check how Bootstrap is set up
158
+ rails g bootstrap:doctor --json # the same report, for agents and CI
159
+ rails g bootstrap:doctor --v6 # also list what changes in Bootstrap 6
160
+ rails g bootstrap:header --json # list a snippet's variants as JSON
161
+ ```
162
+
163
+ `bootstrap:agent` writes `.claude/skills/bootstrap-rails/SKILL.md` and a section in
164
+ `AGENTS.md`, keeping anything else in that file. Run it again after upgrading the gem
165
+ or changing your asset setup. Use `--no-claude` or `--no-agents` to skip either one.
166
+
167
+ `bootstrap:doctor` writes nothing and exits 1 if a check reports an error, so it also
168
+ works as a CI step. It checks:
169
+
170
+ | Check | Looks for |
171
+ |---|---|
172
+ | `bootstrap_css`, `bootstrap_js` | Whether your layouts actually load Bootstrap, on Propshaft, Sprockets or the CDN |
173
+ | `bootstrap_version` | CDN tags or vendored files on a different version from the one this gem ships |
174
+ | `icon_sprite` | The sprite being installed but never rendered, or rendered more than once |
175
+ | `placeholder_images` | Docs-site images left in your views |
176
+ | `legacy_markup` | Markup from older Bootstrap versions in `app/views`, `app/helpers` and `app/components`, with file, line and replacement |
177
+
178
+ In an existing app, `legacy_markup` works as a migration to-do list. Plain names like
179
+ `close` or `well` may be your own CSS classes, so check those before changing them.
180
+ If Bootstrap comes from `package.json` or your importmap, the doctor warns that it
181
+ can't verify it rather than reporting an error.
182
+
183
+ ### Preparing for Bootstrap 6
184
+
185
+ This gem ships Bootstrap 5.3.8. Bootstrap 6 is in alpha (`6.0.0-alpha.1` on npm),
186
+ and the Bootstrap team publishes an agent skill for the move from 5 to 6. Install it
187
+ into your app alongside the gem's own guide:
188
+
189
+ ```bash
190
+ npx skills add twbs/bootstrap --skill bootstrap-v5-v6-migration
191
+ rails g bootstrap:agent # the guide tells agents to stay on Bootstrap 5 markup until you migrate
192
+ rails g bootstrap:doctor --v6 # the migration worklist
193
+ rails g bootstrap:doctor --v6 --json
194
+ ```
195
+
196
+ `--v6` adds a `v6_migration` check and list: every Bootstrap 5 class, data attribute,
197
+ Sass `@import` and JavaScript call that changes in Bootstrap 6, with file, line and
198
+ replacement. For example `modal-body` becomes `dialog-body`, `col-md-6` becomes
199
+ `md:col-6`, `btn-primary` becomes `btn-solid theme-primary`, and
200
+ `data-bs-toggle="dropdown"` becomes `data-bs-toggle="menu"`. It scans `app/views`,
201
+ `app/helpers`, `app/components`, `app/javascript` and your stylesheets, and skips the
202
+ Bootstrap files this gem vendored. It reports a warning, never an error, and is off
203
+ unless you ask for it.
204
+
205
+ Things the scan can't do for you:
206
+
207
+ - The vendored assets, `bootstrap:install` and every generator are still Bootstrap 5.
208
+ Switch the assets to Bootstrap 6 before changing markup, and don't re-run the
209
+ generators afterwards.
210
+ - The view helpers (`nav_bar`, `modal_dialog`, `badge` and the rest) render Bootstrap 5
211
+ markup at runtime, so their output isn't scanned.
212
+ - Bootstrap 6 changes the spacing scale, so check `p-*`/`m-*` utilities by eye.
213
+
139
214
  ## Quick Start
140
215
 
141
216
  ```bash
@@ -154,6 +229,24 @@ rails server
154
229
  Run `bootstrap:layout` even if you already have a layout — that step is what puts
155
230
  Bootstrap's CSS and JS on the page.
156
231
 
232
+ ## Upgrading to 5.5.0
233
+
234
+ 5.5.0 changes the HTML that the view helpers produce. They were still
235
+ writing Bootstrap 3 markup, so toggles, dropdowns and close buttons did nothing on
236
+ Bootstrap 5. If you have custom CSS or tests built on the old output, you'll need to
237
+ update them:
238
+
239
+ - `nav_bar` and the menu helpers use `navbar-expand`, `nav-item` and `nav-link`, and
240
+ `menu_item` puts `active` on the link rather than the `li`.
241
+ - `drop_down_submenu` renders a labelled group, because Bootstrap 5 has no nested
242
+ dropdowns.
243
+ - `badge` and `tag_label` render `badge text-bg-*`.
244
+ - `render_breadcrumbs` renders `nav > ol.breadcrumb`, and `:divider_class` no longer
245
+ applies.
246
+
247
+ See the [CHANGELOG](CHANGELOG.md) for the full list. `rails g bootstrap:doctor` finds
248
+ older Bootstrap markup in your own views and helpers.
249
+
157
250
  ## Upgrading to 5.4.0
158
251
 
159
252
  5.4.0 is a breaking release:
@@ -171,9 +264,19 @@ If you are on Rails 8, note that `bootstrap:install static` previously left
171
264
  Propshaft apps with no Bootstrap at all — that is fixed here. See the
172
265
  [CHANGELOG](CHANGELOG.md) for the full list.
173
266
 
267
+ ## Sponsor
268
+
269
+ [![Open Collective](https://img.shields.io/badge/Open%20Collective-back%20this%20project-1F87FF?style=for-the-badge&logo=opencollective&logoColor=white)](https://opencollective.com/twitter-bootstrap-rails)
270
+ [![Patreon](https://img.shields.io/badge/Patreon-become%20a%20patron-FF424D?style=for-the-badge&logo=patreon&logoColor=white)](https://www.patreon.com/cw/seyhunak)
271
+
272
+ - [Open Collective](https://opencollective.com/twitter-bootstrap-rails) — back the project with a one-off or monthly contribution
273
+ - [Patreon](https://www.patreon.com/cw/seyhunak) — become a patron
274
+ - [Bootstrap 5 for Rails](https://www.patreon.com/seyhunak/posts/twitter-rails-5-165533952) — release write-up on Patreon
275
+
174
276
  ## Buy me a Coffee
175
277
  ## ☕ Support the Project
176
278
 
279
+ [![Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S1B528UND3)
177
280
  [![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-FFDD00?style=for-the-badge&logo=buymeacoffee&logoColor=000000)](https://www.buymeacoffee.com/seyhunak)
178
281
 
179
282
  ## Contributors
@@ -197,4 +300,4 @@ Thanks to all contributors who are helping to make better.
197
300
 
198
301
  ## License
199
302
 
200
- MIT
303
+ MIT. Copyright (c) 2025 (since 2011) by Seyhun Akyürek
@@ -1,16 +1,15 @@
1
1
  module BadgeLabelHelper
2
2
  def badge(*args)
3
- badge_label(:badge, *args)
3
+ badge_label(*args)
4
4
  end
5
5
 
6
+ # Bootstrap 4 merged labels into badges, so this renders a badge too.
6
7
  def tag_label(*args)
7
- badge_label(:label, *args)
8
+ badge_label(*args)
8
9
  end
9
10
 
10
11
  private
11
- def badge_label(what, value, type = nil)
12
- klass = [what]
13
- klass << "#{what}-#{type}" if type.present?
14
- content_tag :span, value, :class => "#{klass.join(' ')}"
12
+ def badge_label(value, type = nil)
13
+ content_tag :span, value, :class => "badge text-bg-#{type.presence || 'secondary'}"
15
14
  end
16
15
  end
@@ -3,6 +3,9 @@ module BootstrapFlashHelper
3
3
 
4
4
  def bootstrap_flash(options = {})
5
5
  flash_messages = []
6
+ tag_class = options[:class]
7
+ tag_attributes = options.except(:class)
8
+
6
9
  flash.each do |type, message|
7
10
  # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
8
11
  next if message.blank?
@@ -13,15 +16,17 @@ module BootstrapFlashHelper
13
16
  type = :danger if type == :error
14
17
  next unless ALERT_TYPES.include?(type)
15
18
 
16
- tag_class = options.extract!(:class)[:class]
17
19
  tag_options = {
18
- class: "alert fade in alert-#{type} #{tag_class}"
19
- }.merge(options)
20
+ class: ["alert", "alert-#{type}", "alert-dismissible", "fade", "show", tag_class].compact.join(" "),
21
+ role: "alert"
22
+ }.merge(tag_attributes)
20
23
 
21
- close_button = content_tag(:button, raw("&times;"), type: "button", class: "close", "data-dismiss" => "alert")
24
+ close_button = content_tag(:button, "", type: "button", class: "btn-close", "data-bs-dismiss" => "alert", "aria-label" => "Close")
22
25
 
23
26
  Array(message).each do |msg|
24
- text = content_tag(:div, close_button + msg, tag_options)
27
+ # safe_join, not +: the message comes first now, and String + SafeBuffer
28
+ # would skip escaping it.
29
+ text = content_tag(:div, safe_join([msg, close_button]), tag_options)
25
30
  flash_messages << text if msg
26
31
  end
27
32
  end
@@ -1,4 +1,6 @@
1
1
  module FlashBlockHelper
2
+ ALERT_CONTEXTS = { :notice => :success, :alert => :danger, :error => :danger }.freeze unless const_defined?(:ALERT_CONTEXTS)
3
+
2
4
  def flash_block
3
5
  output = ''
4
6
  flash.each do |type, message|
@@ -9,9 +11,9 @@ module FlashBlockHelper
9
11
  end
10
12
 
11
13
  def flash_container(type, message)
12
- raw(content_tag(:div, :class => "alert alert-#{type}") do
13
- content_tag(:a, raw("&times;"),:class => 'close', :data => {:dismiss => 'alert'}) +
14
- message
15
- end)
14
+ context = ALERT_CONTEXTS.fetch(type.to_sym, type)
15
+ close = content_tag(:button, "", :type => "button", :class => "btn-close", "data-bs-dismiss" => "alert", "aria-label" => "Close")
16
+
17
+ content_tag(:div, safe_join([message, close]), :class => "alert alert-#{context} alert-dismissible fade show", :role => "alert")
16
18
  end
17
19
  end
@@ -2,8 +2,9 @@ module FormErrorsHelper
2
2
  include ActionView::Helpers::FormTagHelper
3
3
 
4
4
  def error_span(attribute, options = {})
5
- options[:span_class] ||= 'help-block'
6
- options[:error_class] ||= 'has-error'
5
+ # d-block: .invalid-feedback is hidden unless it follows an .is-invalid input.
6
+ options[:span_class] ||= 'invalid-feedback d-block'
7
+ options[:error_class] ||= 'has-validation'
7
8
 
8
9
  if errors_on?(attribute)
9
10
  @template.content_tag( :div, :class => options[:error_class] ) do
@@ -3,8 +3,8 @@ module ModalHelper
3
3
  #modals have a header, a body, a footer for options.
4
4
  def modal_dialog(options = {}, &block)
5
5
  options = {:id => 'modal', :size => '', :show_close => true, :dismiss => true}.merge options
6
- content_tag :div, :class => "bootstrap-modal modal fade", :id => options[:id] do
7
- content_tag :div, :class => "modal-dialog #{options['size']}" do
6
+ content_tag :div, :class => "bootstrap-modal modal fade", :id => options[:id], :tabindex => "-1", "aria-hidden" => "true" do
7
+ content_tag :div, :class => ["modal-dialog", options[:size].presence].compact.join(" ") do
8
8
  content_tag :div, :class => "modal-content" do
9
9
  modal_header(options[:header], &block) +
10
10
  modal_body(options[:body], &block) +
@@ -17,10 +17,10 @@ module ModalHelper
17
17
  def modal_header(options, &block)
18
18
  content_tag :div, :class => 'modal-header' do
19
19
  if options[:show_close]
20
- close_button(options[:dismiss]) +
21
- content_tag(:h4, options[:title], :class => 'modal-title', &block)
20
+ content_tag(:h5, options[:title], :class => 'modal-title', &block) +
21
+ close_button(options[:dismiss])
22
22
  else
23
- content_tag(:h4, options[:title], :class => 'modal-title', &block)
23
+ content_tag(:h5, options[:title], :class => 'modal-title', &block)
24
24
  end
25
25
  end
26
26
  end
@@ -33,27 +33,27 @@ module ModalHelper
33
33
  content_tag :div, options[:content], :class => 'modal-footer', &block
34
34
  end
35
35
 
36
- def close_button(dismiss)
37
- #It doesn't seem to like content_tag, so we do this instead.
38
- raw("<button class=\"close\" data-dismiss=\"#{dismiss}\" aria-hidden=\"true\">&times;</button>")
36
+ def close_button(dismiss = "modal")
37
+ dismiss = "modal" if dismiss.blank? || dismiss == true
38
+ content_tag :button, "", :type => "button", :class => "btn-close", "data-bs-dismiss" => dismiss, "aria-label" => "Close"
39
39
  end
40
40
 
41
41
  def modal_toggle(content_or_options = nil, options, &block)
42
42
  if block_given?
43
43
  options = content_or_options if content_or_options.is_a?(Hash)
44
- default_options = { :class => 'btn btn-default', "data-toggle" => "modal", "href" => options[:dialog] }.merge(options)
44
+ default_options = { :class => 'btn btn-secondary', "data-bs-toggle" => "modal", "href" => options[:dialog] }.merge(options)
45
45
 
46
46
  content_tag :a, nil, default_options, true, &block
47
47
  else
48
- default_options = { :class => 'btn btn-default', "data-toggle" => "modal", "href" => options[:dialog] }.merge(options)
48
+ default_options = { :class => 'btn btn-secondary', "data-bs-toggle" => "modal", "href" => options[:dialog] }.merge(options)
49
49
  content_tag :a, content_or_options, default_options, true
50
50
  end
51
51
  end
52
52
 
53
- def modal_cancel_button(content, options)
54
- default_opts = { :class => "btn bootstrap-modal-cancel-button" }
53
+ def modal_cancel_button(content, options = {})
54
+ default_opts = { :class => "btn btn-secondary bootstrap-modal-cancel-button", "data-bs-dismiss" => "modal" }
55
55
 
56
- content_tag_string "a", content, default_opts.merge(options)
56
+ content_tag :a, content, default_opts.merge(options)
57
57
  end
58
58
 
59
59
  end
@@ -9,62 +9,68 @@ module NavbarHelper
9
9
  end
10
10
 
11
11
  def menu_group(options={}, &block)
12
- pull_class = "navbar-#{options[:pull].to_s}" if options[:pull].present?
13
- content_tag(:ul, :class => "nav navbar-nav #{pull_class}", &block)
12
+ pull_class = { :left => "me-auto", :right => "ms-auto" }[options[:pull].to_s.to_sym]
13
+ content_tag(:ul, :class => ["navbar-nav", pull_class].compact.join(" "), &block)
14
14
  end
15
15
 
16
16
  def menu_item(name=nil, path="#", *args, &block)
17
17
  path = name || path if block_given?
18
18
  options = args.extract_options!
19
- content_tag :li, :class => is_active?(path, options) do
19
+ active = is_active?(path, options)
20
+ link_options = options.merge(:class => menu_link_class(active, options[:class]))
21
+ link_options["aria-current"] = "page" if active
22
+
23
+ content_tag :li, :class => (@_inside_drop_down ? nil : "nav-item") do
20
24
  if block_given?
21
- link_to path, options, &block
25
+ link_to path, link_options, &block
22
26
  else
23
- link_to name, path, options, &block
24
- end
27
+ link_to name, path, link_options
28
+ end
25
29
  end
26
30
  end
27
31
 
28
32
  def drop_down(name)
29
- content_tag :li, :class => "dropdown" do
33
+ content_tag :li, :class => "nav-item dropdown" do
30
34
  drop_down_link(name) + drop_down_list { yield }
31
35
  end
32
36
  end
33
37
 
34
38
  def drop_down_with_submenu(name, &block)
35
- content_tag :li, :class => "dropdown" do
39
+ content_tag :li, :class => "nav-item dropdown" do
36
40
  drop_down_link(name) + drop_down_sublist(&block)
37
41
  end
38
42
  end
39
43
 
40
44
  def drop_down_sublist(&block)
41
- content_tag :ul, :class => "dropdown-menu", &block
45
+ drop_down_list(&block)
42
46
  end
43
47
 
48
+ # Bootstrap 5 has no nested dropdowns, so a submenu renders as a labelled
49
+ # group of items inside its parent menu.
44
50
  def drop_down_submenu(name, &block)
45
- content_tag :li, :class => "dropdown-submenu" do
46
- link_to(name, "") + drop_down_list(&block)
47
- end
51
+ safe_join([drop_down_header(name), inside_drop_down { capture(&block) }])
48
52
  end
49
53
 
50
54
  def drop_down_divider
51
- content_tag :li, "", :class => "divider"
55
+ content_tag(:li) { tag.hr(:class => "dropdown-divider") }
52
56
  end
53
57
 
54
58
  def drop_down_header(text)
55
- content_tag :li, text, :class => "nav-header"
59
+ content_tag(:li) { content_tag(:h6, text, :class => "dropdown-header") }
56
60
  end
57
61
 
58
62
  def menu_divider
59
- content_tag :li, "", :class => "divider-vertical"
63
+ content_tag :li, :class => "nav-item py-1" do
64
+ content_tag :div, "", :class => "vr d-none d-lg-flex h-100 mx-lg-2"
65
+ end
60
66
  end
61
67
 
62
68
  def menu_text(text=nil, options={}, &block)
63
69
  pull = options.delete(:pull)
64
- pull_class = pull.present? ? "pull-#{pull.to_s}" : nil
70
+ pull_class = { :left => "me-auto", :right => "ms-auto" }[pull.to_s.to_sym]
65
71
  options.append_merge!(:class, pull_class)
66
72
  options.append_merge!(:class, "navbar-text")
67
- content_tag :p, options do
73
+ content_tag :span, options do
68
74
  text || yield
69
75
  end
70
76
  end
@@ -104,12 +110,14 @@ module NavbarHelper
104
110
  private
105
111
 
106
112
  def nav_bar_nav(options, &block)
107
-
108
- position = "static-#{options[:static].to_s}" if options[:static]
109
113
  position = "fixed-#{options[:fixed].to_s}" if options[:fixed]
110
- inverse = (options[:inverse].present? && options[:inverse] == true) ? true : false
114
+ inverse = options[:inverse] == true
115
+ # :static needs no class: Bootstrap 5 navbars are static unless told otherwise.
111
116
 
112
- content_tag :nav, :class => nav_bar_css_class(position, inverse), :role => "navigation" do
117
+ content_tag :nav,
118
+ :class => nav_bar_css_class(position, inverse, options[:responsive] == true),
119
+ "data-bs-theme" => (inverse ? "dark" : nil),
120
+ :role => "navigation" do
113
121
  yield
114
122
  end
115
123
  end
@@ -125,29 +133,20 @@ module NavbarHelper
125
133
 
126
134
  def container_div_with_block(brand, brand_link, responsive, no_turbolink, &block)
127
135
  output = []
136
+ output << brand_link(brand, brand_link, no_turbolink)
128
137
  if responsive == true
129
- output << responsive_nav_header(brand, brand_link, no_turbolink)
138
+ output << responsive_button
130
139
  output << responsive_div { capture(&block) }
131
140
  else
132
- output << brand_link(brand, brand_link, no_turbolink)
133
141
  output << capture(&block)
134
142
  end
135
143
  output.join("\n").html_safe
136
144
  end
137
145
 
138
- def responsive_nav_header(brand, brand_link, no_turbolink)
139
- content_tag(:div, :class => "navbar-header") do
140
- output = []
141
- output << responsive_button
142
- output << brand_link(brand, brand_link, no_turbolink)
143
- output.join("\n").html_safe
144
- end
145
- end
146
-
147
- def nav_bar_css_class(position, inverse = false)
148
- css_class = ["navbar", "navbar-default"]
149
- css_class << "navbar-#{position}" if position.present?
150
- css_class << "navbar-inverse" if inverse
146
+ def nav_bar_css_class(position, inverse = false, responsive = false)
147
+ css_class = ["navbar", responsive ? "navbar-expand-lg" : "navbar-expand"]
148
+ css_class << (inverse ? "bg-dark" : "bg-body-tertiary")
149
+ css_class << position if position.present?
151
150
  css_class.join(" ")
152
151
  end
153
152
 
@@ -163,16 +162,13 @@ module NavbarHelper
163
162
  end
164
163
 
165
164
  def responsive_button
166
- %{<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
167
- <span class="sr-only">Toggle navigation</span>
168
- <span class="icon-bar"></span>
169
- <span class="icon-bar"></span>
170
- <span class="icon-bar"></span>
171
- </button>}
165
+ %{<button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-label="Toggle navigation">
166
+ <span class="navbar-toggler-icon"></span>
167
+ </button>}
172
168
  end
173
169
 
174
170
  def responsive_div(&block)
175
- content_tag(:div, :class => "navbar-collapse collapse", &block)
171
+ content_tag(:div, :class => "collapse navbar-collapse", &block)
176
172
  end
177
173
 
178
174
  def is_active?(path, options={})
@@ -180,16 +176,27 @@ module NavbarHelper
180
176
  "active" if state.in?([:active, :chosen]) || state === true
181
177
  end
182
178
 
183
- def name_and_caret(name)
184
- "#{name} #{content_tag(:b, :class => "caret") {}}".html_safe
179
+ def menu_link_class(active, extra)
180
+ [@_inside_drop_down ? "dropdown-item" : "nav-link", active, extra].compact.join(" ")
185
181
  end
186
182
 
187
183
  def drop_down_link(name)
188
- link_to(name_and_caret(name), "#", :class => "dropdown-toggle", "data-toggle" => "dropdown")
184
+ link_to(name, "#", :class => "nav-link dropdown-toggle", :role => "button",
185
+ "data-bs-toggle" => "dropdown", "aria-expanded" => "false")
189
186
  end
190
187
 
191
188
  def drop_down_list(&block)
192
- content_tag :ul, :class => "dropdown-menu", &block
189
+ content_tag(:ul, :class => "dropdown-menu") { inside_drop_down(&block) }
190
+ end
191
+
192
+ # Bootstrap 5 styles a link differently inside a dropdown, so menu_item has to
193
+ # know where it is being rendered.
194
+ def inside_drop_down
195
+ previous = @_inside_drop_down
196
+ @_inside_drop_down = true
197
+ yield
198
+ ensure
199
+ @_inside_drop_down = previous
193
200
  end
194
201
  end
195
202
 
@@ -1,7 +1,7 @@
1
1
  module TwitterBreadcrumbsHelper
2
2
  def render_bootstrap_breadcrumbs(divider = '/', options={}, &block)
3
- default_options = { :class => '', :item_class => '', :divider_class => '', :active_class => 'active' }.merge(options)
4
- content = render :partial => 'twitter-bootstrap/breadcrumbs', :layout => false, :locals => { :divider => divider, options: options }
3
+ default_options = { :class => '', :item_class => '', :active_class => 'active' }.merge(options)
4
+ content = render :partial => 'twitter-bootstrap/breadcrumbs', :layout => false, :locals => { :divider => divider, options: default_options }
5
5
  if block_given?
6
6
  capture(content, &block)
7
7
  else
@@ -1,14 +1,14 @@
1
1
  <% if @__bs_breadcrumbs.present? %>
2
- <ul class="breadcrumb <%= options[:class] %>">
3
- <% separator = divider.html_safe if divider %>
4
- <% @__bs_breadcrumbs[0..-2].each do |crumb| %>
5
- <li class="<%= options[:item_class] %>">
6
- <%= link_to crumb[:name], crumb[:url], crumb[:options] %>
7
- <span class="divider <%= options[:divider_class] %>"><%= separator if separator %></span>
2
+ <nav aria-label="breadcrumb"<% if divider %> style="--bs-breadcrumb-divider: '<%= divider %>';"<% end %>>
3
+ <ol class="breadcrumb <%= options[:class] %>">
4
+ <% @__bs_breadcrumbs[0..-2].each do |crumb| %>
5
+ <li class="breadcrumb-item <%= options[:item_class] %>">
6
+ <%= link_to crumb[:name], crumb[:url], crumb[:options] %>
7
+ </li>
8
+ <% end %>
9
+ <li class="breadcrumb-item <%= options[:active_class] %>" aria-current="page">
10
+ <%= @__bs_breadcrumbs.last[:name] %>
8
11
  </li>
9
- <% end %>
10
- <li class="<%= options[:active_class] %>">
11
- <%= @__bs_breadcrumbs.last[:name] %>
12
- </li>
13
- </ul>
12
+ </ol>
13
+ </nav>
14
14
  <% end %>