twitter-bootstrap-rails 5.5.1 → 5.6.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -0
  3. data/README.md +84 -5
  4. data/app/assets/javascripts/twitter/bootstrap/bootstrap.min.js +3 -3
  5. data/app/assets/stylesheets/twitter-bootstrap-static/bootstrap.css +3 -3
  6. data/lib/generators/bootstrap/agent/agent_generator.rb +12 -0
  7. data/lib/generators/bootstrap/agent/templates/guide.md.erb +23 -3
  8. data/lib/generators/bootstrap/bootstrap5_markup.rb +22 -0
  9. data/lib/generators/bootstrap/cdn/cdn_generator.rb +32 -2
  10. data/lib/generators/bootstrap/cdn_tags.rb +11 -0
  11. data/lib/generators/bootstrap/install/install_generator.rb +77 -21
  12. data/lib/generators/bootstrap/layout/layout_generator.rb +15 -0
  13. data/lib/generators/bootstrap/layout/templates/layout.html.erb +4 -1
  14. data/lib/generators/bootstrap/layout/templates/layout.html.haml +4 -1
  15. data/lib/generators/bootstrap/layout/templates/layout.html.slim +4 -1
  16. data/lib/generators/bootstrap/nes/nes_generator.rb +101 -0
  17. data/lib/generators/bootstrap/snippets/snippet_base.rb +4 -0
  18. data/lib/generators/bootstrap/stimulus/stimulus_generator.rb +49 -0
  19. data/lib/generators/bootstrap/stimulus/templates/bootstrap_controller.js.tt +67 -0
  20. data/lib/generators/bootstrap/themed/themed_generator.rb +4 -0
  21. data/lib/twitter/bootstrap/rails/config.rb +17 -4
  22. data/lib/twitter/bootstrap/rails/doctor.rb +125 -6
  23. data/lib/twitter/bootstrap/rails/version.rb +37 -5
  24. data/spec/lib/generators/cdn_generator_spec.rb +31 -0
  25. data/spec/lib/generators/doctor_generator_spec.rb +52 -0
  26. data/spec/lib/generators/install_generator_spec.rb +51 -1
  27. data/spec/lib/generators/layout_generator_spec.rb +24 -0
  28. data/spec/lib/generators/nes_generator_spec.rb +164 -0
  29. data/spec/lib/generators/no_hardcoded_versions_spec.rb +3 -1
  30. data/spec/lib/generators/stimulus_generator_spec.rb +65 -0
  31. data/spec/support/generator_spec_helper.rb +2 -0
  32. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js +3 -3
  33. data/vendor/assets/javascripts/twitter/bootstrap/bootstrap.esm.min.js +7 -0
  34. data/vendor/assets/javascripts/twitter/bootstrap/popper.esm.js +15 -0
  35. data/vendor/assets/stylesheets/twitter/bootstrap/bootstrap.min.css +3 -3
  36. metadata +28 -10
@@ -0,0 +1,164 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ describe Bootstrap::Generators::NesGenerator do
5
+ let(:nes) { Twitter::Bootstrap::Rails::BOOTSTRAP_NES }
6
+ let(:alias_spec) { "npm:#{nes[:package]}@#{nes[:version]}" }
7
+
8
+ def package_json
9
+ JSON.parse(read_destination("package.json"))
10
+ end
11
+
12
+ before do
13
+ stub_rails_application
14
+ write_destination("package.json", JSON.pretty_generate(
15
+ "name" => "app", "dependencies" => { "bootstrap" => "^4.6.2", "jquery" => "^3.7.1" }
16
+ ))
17
+ end
18
+
19
+ it "points bootstrap at the NES package, as a dependency and an override" do
20
+ run_generator(described_class)
21
+
22
+ expect(package_json["dependencies"]).to include("bootstrap" => alias_spec, "jquery" => "^3.7.1")
23
+ expect(package_json["overrides"]).to eq("bootstrap" => { "." => alias_spec })
24
+ end
25
+
26
+ it "adds the registry to .npmrc, reading the token from an environment variable" do
27
+ write_destination(".npmrc", "save-exact=true\n")
28
+ run_generator(described_class)
29
+ npmrc = read_destination(".npmrc")
30
+
31
+ expect(npmrc).to include("save-exact=true")
32
+ expect(npmrc).to include("@neverendingsupport:registry=#{nes[:registry]}")
33
+ expect(npmrc).to include("//registry.nes.herodevs.com/npm/pkg/:_authToken=${HERODEVS_NES_TOKEN}")
34
+ end
35
+
36
+ it "takes another variable name for the token" do
37
+ run_generator(described_class, %w[--token-env=NES_TOKEN])
38
+
39
+ expect(read_destination(".npmrc")).to include(":_authToken=${NES_TOKEN}")
40
+ end
41
+
42
+ it "does not repeat itself when run again" do
43
+ run_generator(described_class)
44
+ run_generator(described_class, %w[--force])
45
+
46
+ expect(read_destination(".npmrc").scan("@neverendingsupport:registry").size).to eq(1)
47
+ end
48
+
49
+ it "keeps an auth line the app already has" do
50
+ write_destination(".npmrc", "//registry.nes.herodevs.com/npm/pkg/:_authToken=${MY_TOKEN}\n")
51
+ run_generator(described_class)
52
+
53
+ expect(read_destination(".npmrc").scan("_authToken").size).to eq(1)
54
+ end
55
+
56
+ it "records NES mode" do
57
+ run_generator(described_class)
58
+
59
+ expect(read_destination("config/initializers/bootstrap.rb")).to include("asset_mode = :nes")
60
+ end
61
+
62
+ it "says what to do next, and that the gem's markup is Bootstrap 5" do
63
+ output = run_generator(described_class)
64
+
65
+ expect(output).to include("HERODEVS_NES_TOKEN").and include("npm install").and include("jQuery")
66
+ expect(output).to include("Bootstrap 5 markup")
67
+ end
68
+
69
+ it "refuses an app without package.json" do
70
+ FileUtils.rm(destination_path("package.json"))
71
+
72
+ expect { run_generator(described_class) }.to raise_error(Rails::Generators::Error, /package\.json/)
73
+ end
74
+
75
+ describe "the doctor on an NES app" do
76
+ before { run_generator(described_class) }
77
+
78
+ def report
79
+ Twitter::Bootstrap::Rails::Doctor.new(destination_root).report
80
+ end
81
+
82
+ def check(id)
83
+ report[:checks].find { |c| c[:id] == id }
84
+ end
85
+
86
+ it "reports the NES version and distribution" do
87
+ expect(report).to include(:asset_mode => "nes", :bootstrap_version => nes[:bootstrap_version],
88
+ :bootstrap_distribution => "HeroDevs Bootstrap NES")
89
+ end
90
+
91
+ it "is happy with what the generator wrote" do
92
+ expect(check("nes_package")[:status]).to eq("ok")
93
+ expect(check("nes_registry")[:status]).to eq("ok")
94
+ end
95
+
96
+ it "reports an error when package.json no longer uses the NES package" do
97
+ write_destination("package.json", JSON.pretty_generate("dependencies" => { "bootstrap" => "^4.6.2" }))
98
+
99
+ expect(check("nes_package")).to include(:status => "error", :fix => a_string_including("bootstrap:nes"))
100
+ end
101
+
102
+ it "warns about an older NES release" do
103
+ json = package_json
104
+ json["dependencies"]["bootstrap"] = "npm:#{nes[:package]}@4.6.2-bootstrap-4.6.3"
105
+ write_destination("package.json", JSON.pretty_generate(json))
106
+
107
+ expect(check("nes_package")).to include(:status => "warn", :message => a_string_including("4.6.3"))
108
+ end
109
+
110
+ it "warns when a token is written into .npmrc" do
111
+ write_destination(".npmrc", "@neverendingsupport:registry=#{nes[:registry]}\n" \
112
+ "//registry.nes.herodevs.com/npm/pkg/:_authToken=abc123secret\n")
113
+
114
+ expect(check("nes_registry")).to include(:status => "warn", :fix => a_string_including("${HERODEVS_NES_TOKEN}"))
115
+ expect(check("nes_registry").to_s).not_to include("abc123secret")
116
+ end
117
+
118
+ it "reports an error without the registry" do
119
+ write_destination(".npmrc", "")
120
+
121
+ expect(check("nes_registry")[:status]).to eq("error")
122
+ end
123
+
124
+ it "does not treat Bootstrap 4 markup as legacy" do
125
+ write_destination("app/views/tasks/index.html.erb", %{<a data-toggle="modal" class="btn btn-default">x</a>})
126
+
127
+ expect(report[:legacy_markup]).to be_empty
128
+ expect(check("legacy_markup")[:message]).to include("Bootstrap 4")
129
+ end
130
+
131
+ it "does not look for the vendored Bootstrap 5 files" do
132
+ expect(report[:checks].map { |c| c[:id] }).not_to include("bootstrap_css", "bootstrap_js")
133
+ end
134
+ end
135
+
136
+ describe "the agent guide on an NES app" do
137
+ let(:skill) { read_destination(".claude/skills/bootstrap-rails/SKILL.md") }
138
+
139
+ before do
140
+ run_generator(described_class)
141
+ Twitter::Bootstrap::Rails.asset_mode = :nes
142
+ run_generator(Bootstrap::Generators::AgentGenerator)
143
+ end
144
+
145
+ it "tells agents to write Bootstrap 4 markup and not to use the Bootstrap 5 generators" do
146
+ expect(skill).to include("Bootstrap #{nes[:bootstrap_version]}").and include("HeroDevs")
147
+ expect(skill).to include("Write Bootstrap 4 markup")
148
+ expect(skill).to include("bootstrap-v4-v6-migration")
149
+ end
150
+
151
+ it "does not list Bootstrap 4 markup as markup to avoid" do
152
+ expect(skill).not_to include("## Markup to avoid")
153
+ end
154
+ end
155
+
156
+ describe "generators that write Bootstrap 5 markup" do
157
+ before { Twitter::Bootstrap::Rails.asset_mode = :nes }
158
+
159
+ it "warn on an NES app" do
160
+ expect(run_generator(Bootstrap::Generators::LayoutGenerator)).to include("Bootstrap 5 markup")
161
+ expect(run_generator(Bootstrap::Generators::HeaderGenerator)).to include("Bootstrap 5 markup")
162
+ end
163
+ end
164
+ end
@@ -34,7 +34,9 @@ describe "generator templates" do
34
34
  "vendor/assets/stylesheets/twitter/bootstrap/bootstrap.min.css" => "Bootstrap v#{version}",
35
35
  "vendor/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js" => "Bootstrap v#{version}",
36
36
  "app/assets/stylesheets/twitter-bootstrap-static/bootstrap.css" => "Bootstrap v#{version}",
37
- "app/assets/javascripts/twitter/bootstrap/bootstrap.min.js" => "Bootstrap v#{version}"
37
+ "app/assets/javascripts/twitter/bootstrap/bootstrap.min.js" => "Bootstrap v#{version}",
38
+ "vendor/assets/javascripts/twitter/bootstrap/bootstrap.esm.min.js" => "Bootstrap v#{version}",
39
+ "vendor/assets/javascripts/twitter/bootstrap/popper.esm.js" => "@popperjs/core v#{Twitter::Bootstrap::Rails::POPPER_VERSION}"
38
40
  }.each do |path, banner|
39
41
  full = File.join(gem_root, path)
40
42
  expect(File.exist?(full)).to be(true), "missing vendored asset #{path}"
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+ require 'open3'
3
+
4
+ describe Bootstrap::Generators::StimulusGenerator do
5
+ let(:controller) { "app/javascript/controllers/bootstrap_controller.js" }
6
+
7
+ before { write_destination("app/javascript/controllers/index.js", %{eagerLoadControllersFrom("controllers", application)\n}) }
8
+
9
+ it "writes a controller that sets up and tears down Bootstrap components" do
10
+ run_generator(described_class)
11
+ js = read_destination(controller)
12
+
13
+ expect(js).to include('import { Controller } from "@hotwired/stimulus"')
14
+ expect(js).to include("connect()").and include("disconnect()")
15
+ expect(js).to include("turbo:before-cache")
16
+ expect(js).to include("Tooltip").and include("Popover")
17
+ end
18
+
19
+ it "uses the global Bootstrap from the bundle by default" do
20
+ run_generator(described_class)
21
+
22
+ js = read_destination(controller)
23
+
24
+ expect(js).to include("window.bootstrap")
25
+ expect(js).not_to include('from "bootstrap"')
26
+ end
27
+
28
+ it "imports Bootstrap when it is pinned in the importmap" do
29
+ write_destination("config/importmap.rb", %{pin "bootstrap", to: "twitter/bootstrap/bootstrap.esm.min.js"\n})
30
+ run_generator(described_class)
31
+
32
+ js = read_destination(controller)
33
+
34
+ expect(js).to include('import * as bootstrap from "bootstrap"')
35
+ expect(js).not_to include("window.bootstrap")
36
+ end
37
+
38
+ it "says how to attach it" do
39
+ expect(run_generator(described_class)).to include('data-controller="bootstrap"')
40
+ end
41
+
42
+ it "reminds apps that register controllers by hand to update the manifest" do
43
+ write_destination("app/javascript/controllers/index.js", %{application.register("hello", HelloController)\n})
44
+
45
+ expect(run_generator(described_class)).to include("stimulus:manifest:update")
46
+ end
47
+
48
+ it "refuses an app without Stimulus" do
49
+ FileUtils.rm_rf(destination_path("app/javascript/controllers"))
50
+
51
+ expect { run_generator(described_class) }.to raise_error(Rails::Generators::Error, /stimulus-rails/)
52
+ end
53
+
54
+ it "writes valid JavaScript in both forms", :if => system("node --version", :out => File::NULL, :err => File::NULL) do
55
+ [false, true].each do |pinned|
56
+ write_destination("config/importmap.rb", pinned ? %{pin "bootstrap"\n} : "")
57
+ run_generator(described_class, %w[--force])
58
+ path = destination_path(controller).sub(/\.js\z/, ".mjs")
59
+ FileUtils.cp(destination_path(controller), path)
60
+
61
+ _out, err, status = Open3.capture3("node", "--check", path)
62
+ expect(status).to be_success, err
63
+ end
64
+ end
65
+ end
@@ -10,6 +10,8 @@ require 'generators/bootstrap/starter/starter_generator'
10
10
  require 'generators/bootstrap/cdn/cdn_generator'
11
11
  require 'generators/bootstrap/doctor/doctor_generator'
12
12
  require 'generators/bootstrap/agent/agent_generator'
13
+ require 'generators/bootstrap/stimulus/stimulus_generator'
14
+ require 'generators/bootstrap/nes/nes_generator'
13
15
  require 'generators/bootstrap/snippets/snippet_catalog'
14
16
 
15
17
  Bootstrap::Generators::SnippetCatalog::GENERATORS.each_key do |name|