twitter-bootstrap-rails 5.4.0 → 5.5.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -0
  3. data/README.md +72 -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 +81 -0
  13. data/lib/generators/bootstrap/agent/templates/guide.md.erb +61 -0
  14. data/lib/generators/bootstrap/doctor/doctor_generator.rb +39 -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 +207 -0
  34. data/lib/twitter/bootstrap/rails/legacy_markup.rb +119 -0
  35. data/lib/twitter/bootstrap/rails/version.rb +1 -1
  36. data/spec/lib/breadcrumbs_spec.rb +8 -2
  37. data/spec/lib/generators/agent_generator_spec.rb +111 -0
  38. data/spec/lib/generators/doctor_generator_spec.rb +216 -0
  39. data/spec/lib/generators/snippet_generators_spec.rb +23 -0
  40. data/spec/lib/twitter_bootstrap_rails/badge_label_helper_spec.rb +7 -3
  41. data/spec/lib/twitter_bootstrap_rails/bootstrap_flash_helper_spec.rb +23 -45
  42. data/spec/lib/twitter_bootstrap_rails/breadcrumbs_view_spec.rb +35 -0
  43. data/spec/lib/twitter_bootstrap_rails/flash_block_helper_spec.rb +26 -0
  44. data/spec/lib/twitter_bootstrap_rails/form_errors_helper_spec.rb +2 -2
  45. data/spec/lib/twitter_bootstrap_rails/legacy_markup_spec.rb +74 -0
  46. data/spec/lib/twitter_bootstrap_rails/modal_helper_spec.rb +21 -8
  47. data/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb +94 -92
  48. data/spec/spec_helper.rb +0 -1
  49. data/spec/support/generator_spec_helper.rb +2 -0
  50. metadata +21 -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: e749f38d103c9081159cd686251b083119950e45ac05a07ffbec1fdc9998c718
4
+ data.tar.gz: b68354a498fbccd9f3332c3c28c1e34984d236cad0aaaaf24b521e32361700d2
5
5
  SHA512:
6
- metadata.gz: b394fbf43caa16b0288e3357ec3c47745e1dc10c19149f18040a463165c0ca9a2e2843108db50c821941b01f800eb97f449e918056127ae90473cd39f466c8e7
7
- data.tar.gz: 1c51ce6849e58c49b9017ac95d7b58bff2c44bb6b23eff6137120f43450cf645a9328d9218ec83c842c99885ae51b5f8453a2c96aa33cd90ab2f6bfba942b578
6
+ metadata.gz: d89262fa8b657f75f13f3be3f0550f0999e06e14a2de6bc6d76fdab6171639b5785cd7167118d90aef0dae928ecff7f526d3c3daf1e2b31cb568c252ca391c4d
7
+ data.tar.gz: deb6bc95b028221c973918da2f69df302b862552e12f5744c7735fabf32c00eab231c82855e4beb2f52dcb15239c7a9325583bff128df349f7a7bcd235fe7fb4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,48 @@
1
+ ## 5.5.0
2
+
3
+ ### Added
4
+
5
+ - **`rails g bootstrap:doctor`** checks how Bootstrap is set up in an app: whether
6
+ layouts load its CSS and JS, stale versions, an unrendered icon sprite, leftover
7
+ placeholder images, and markup from older Bootstrap versions with file and line.
8
+ `--json` prints a machine-readable report. It writes nothing and exits 1 if a
9
+ check reports an error.
10
+ - **`rails g bootstrap:agent`** writes a guide for coding agents, tailored to the
11
+ app: a Claude skill and a section in `AGENTS.md`. It keeps the rest of `AGENTS.md`
12
+ and replaces its own section when run again.
13
+ - **`--json`** on every snippet generator lists the variants as JSON.
14
+
15
+ ### Changed
16
+
17
+ - **View helpers now produce Bootstrap 5 markup.** They were still producing
18
+ Bootstrap 3 markup, so toggles, dropdowns and close buttons did nothing on the
19
+ Bootstrap 5 this gem ships. This changes their HTML, so custom CSS or tests that
20
+ rely on the old output need updating:
21
+ - `nav_bar` and the menu helpers use `navbar-expand`, `nav-item` and `nav-link`.
22
+ `:inverse` uses `data-bs-theme="dark"`, and `:static` no longer adds a class.
23
+ - `menu_item` puts `active` on the link rather than the `li`.
24
+ - `drop_down_submenu` renders a labelled group, because Bootstrap 5 has no nested
25
+ dropdowns.
26
+ - `menu_text` renders a `span`.
27
+ - `badge` and `tag_label` render `badge text-bg-*`, defaulting to `secondary`.
28
+ - `modal_toggle` and `modal_cancel_button` use `btn-secondary`, and the modal title
29
+ is an `h5`.
30
+ - `error_span` defaults to `invalid-feedback d-block` inside `has-validation`.
31
+ - `render_breadcrumbs` renders `nav > ol.breadcrumb`. The divider is set through
32
+ `--bs-breadcrumb-divider`, so `:divider_class` no longer applies.
33
+ - The Haml and Slim themed templates, the simple_form templates and the Devise login
34
+ partial now use Bootstrap 5 markup too.
35
+
36
+ ### Fixed
37
+
38
+ - `modal_cancel_button` raised `NoMethodError` on Rails 8.1.
39
+ - `modal_dialog` ignored `:size`.
40
+ - `close_button` didn't escape its dismiss target.
41
+ - `bootstrap_flash` dropped the `:class` option after the first message.
42
+ - `flash_block` used `alert-notice` and `alert-alert`, which don't exist.
43
+ - `render_breadcrumbs` ignored its default options, so the last crumb wasn't styled
44
+ as active.
45
+
1
46
  ## 5.4.0
2
47
 
3
48
  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,39 @@ 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:header --json # list a snippet's variants as JSON
160
+ ```
161
+
162
+ `bootstrap:agent` writes `.claude/skills/bootstrap-rails/SKILL.md` and a section in
163
+ `AGENTS.md`, keeping anything else in that file. Run it again after upgrading the gem
164
+ or changing your asset setup. Use `--no-claude` or `--no-agents` to skip either one.
165
+
166
+ `bootstrap:doctor` writes nothing and exits 1 if a check reports an error, so it also
167
+ works as a CI step. It checks:
168
+
169
+ | Check | Looks for |
170
+ |---|---|
171
+ | `bootstrap_css`, `bootstrap_js` | Whether your layouts actually load Bootstrap, on Propshaft, Sprockets or the CDN |
172
+ | `bootstrap_version` | CDN tags or vendored files on a different version from the one this gem ships |
173
+ | `icon_sprite` | The sprite being installed but never rendered, or rendered more than once |
174
+ | `placeholder_images` | Docs-site images left in your views |
175
+ | `legacy_markup` | Markup from older Bootstrap versions in `app/views`, `app/helpers` and `app/components`, with file, line and replacement |
176
+
177
+ In an existing app, `legacy_markup` works as a migration to-do list. Plain names like
178
+ `close` or `well` may be your own CSS classes, so check those before changing them.
179
+ If Bootstrap comes from `package.json` or your importmap, the doctor warns that it
180
+ can't verify it rather than reporting an error.
181
+
139
182
  ## Quick Start
140
183
 
141
184
  ```bash
@@ -154,6 +197,24 @@ rails server
154
197
  Run `bootstrap:layout` even if you already have a layout — that step is what puts
155
198
  Bootstrap's CSS and JS on the page.
156
199
 
200
+ ## Upgrading to 5.5.0
201
+
202
+ 5.5.0 changes the HTML that the view helpers produce. They were still
203
+ writing Bootstrap 3 markup, so toggles, dropdowns and close buttons did nothing on
204
+ Bootstrap 5. If you have custom CSS or tests built on the old output, you'll need to
205
+ update them:
206
+
207
+ - `nav_bar` and the menu helpers use `navbar-expand`, `nav-item` and `nav-link`, and
208
+ `menu_item` puts `active` on the link rather than the `li`.
209
+ - `drop_down_submenu` renders a labelled group, because Bootstrap 5 has no nested
210
+ dropdowns.
211
+ - `badge` and `tag_label` render `badge text-bg-*`.
212
+ - `render_breadcrumbs` renders `nav > ol.breadcrumb`, and `:divider_class` no longer
213
+ applies.
214
+
215
+ See the [CHANGELOG](CHANGELOG.md) for the full list. `rails g bootstrap:doctor` finds
216
+ older Bootstrap markup in your own views and helpers.
217
+
157
218
  ## Upgrading to 5.4.0
158
219
 
159
220
  5.4.0 is a breaking release:
@@ -171,9 +232,19 @@ If you are on Rails 8, note that `bootstrap:install static` previously left
171
232
  Propshaft apps with no Bootstrap at all — that is fixed here. See the
172
233
  [CHANGELOG](CHANGELOG.md) for the full list.
173
234
 
235
+ ## Sponsor
236
+
237
+ [![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)
238
+ [![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)
239
+
240
+ - [Open Collective](https://opencollective.com/twitter-bootstrap-rails) — back the project with a one-off or monthly contribution
241
+ - [Patreon](https://www.patreon.com/cw/seyhunak) — become a patron
242
+ - [Bootstrap 5 for Rails](https://www.patreon.com/seyhunak/posts/twitter-rails-5-165533952) — release write-up on Patreon
243
+
174
244
  ## Buy me a Coffee
175
245
  ## ☕ Support the Project
176
246
 
247
+ [![Ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/S1B528UND3)
177
248
  [![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
249
 
179
250
  ## Contributors
@@ -197,4 +268,4 @@ Thanks to all contributors who are helping to make better.
197
268
 
198
269
  ## License
199
270
 
200
- MIT
271
+ 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 %>
@@ -0,0 +1,81 @@
1
+ require 'erb'
2
+ require 'rails/generators'
3
+ require 'twitter/bootstrap/rails/doctor'
4
+ require 'generators/bootstrap/snippets/snippet_catalog'
5
+
6
+ module Bootstrap
7
+ module Generators
8
+ # Writes a guide for coding agents, tailored to this app and built from the
9
+ # same catalog and tables the other commands use, so it can't drift from them.
10
+ class AgentGenerator < ::Rails::Generators::Base
11
+ SKILL_PATH = ".claude/skills/bootstrap-rails/SKILL.md".freeze
12
+ AGENTS_PATH = "AGENTS.md".freeze
13
+ SECTION_START = "<!-- bootstrap-rails:start -->".freeze
14
+ SECTION_END = "<!-- bootstrap-rails:end -->".freeze
15
+ SKILL_DESCRIPTION = "Use when adding or changing Bootstrap UI, layouts or styles in this Rails app. " \
16
+ "Covers the twitter-bootstrap-rails generators, helpers and checks.".freeze
17
+
18
+ source_root File.expand_path("../templates", __FILE__)
19
+ desc "Writes a guide for coding agents: a Claude skill and a section in AGENTS.md"
20
+
21
+ class_option :claude, :type => :boolean, :default => true,
22
+ :desc => "Write #{SKILL_PATH}"
23
+ class_option :agents, :type => :boolean, :default => true,
24
+ :desc => "Write a section into #{AGENTS_PATH}, keeping the rest of the file"
25
+
26
+ def write_skill
27
+ return unless options[:claude]
28
+
29
+ frontmatter = "---\nname: bootstrap-rails\ndescription: #{SKILL_DESCRIPTION}\n---\n\n"
30
+ # :force because this file is entirely generated, and a conflict prompt
31
+ # would hang an agent running the command.
32
+ create_file SKILL_PATH, frontmatter + guide, :force => true
33
+ end
34
+
35
+ def write_agents_section
36
+ return unless options[:agents]
37
+
38
+ section = "#{SECTION_START}\n#{guide}#{SECTION_END}\n"
39
+ path = File.join(destination_root, AGENTS_PATH)
40
+ existing = File.exist?(path) ? File.read(path) : nil
41
+
42
+ if existing.nil?
43
+ create_file AGENTS_PATH, section
44
+ elsif existing.include?(SECTION_START)
45
+ gsub_file(AGENTS_PATH, /#{Regexp.escape(SECTION_START)}.*?#{Regexp.escape(SECTION_END)}\n?/m) { section }
46
+ else
47
+ append_to_file AGENTS_PATH, "\n#{section}"
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def guide
54
+ @guide ||= ERB.new(File.read(File.join(self.class.source_root, "guide.md.erb")), :trim_mode => "-").result(binding)
55
+ end
56
+
57
+ def facts
58
+ @facts ||= Twitter::Bootstrap::Rails::Doctor.new(destination_root).facts
59
+ end
60
+
61
+ def catalog
62
+ SnippetCatalog
63
+ end
64
+
65
+ def legacy
66
+ Twitter::Bootstrap::Rails::LegacyMarkup
67
+ end
68
+
69
+ def pipeline_note
70
+ case facts[:asset_pipeline]
71
+ when "propshaft"
72
+ "Propshaft. It has no `require` directives, so the layout has to link Bootstrap's files by name."
73
+ when "sprockets"
74
+ "Sprockets. Bootstrap loads through Sprockets directives in the application manifests."
75
+ else
76
+ "Not detected. Run `rails g bootstrap:doctor` after installing an asset pipeline."
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end