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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/README.md +72 -1
- data/app/helpers/badge_label_helper.rb +5 -6
- data/app/helpers/bootstrap_flash_helper.rb +10 -5
- data/app/helpers/flash_block_helper.rb +6 -4
- data/app/helpers/form_errors_helper.rb +3 -2
- data/app/helpers/modal_helper.rb +13 -13
- data/app/helpers/navbar_helper.rb +54 -47
- data/app/helpers/twitter_breadcrumbs_helper.rb +2 -2
- data/app/views/twitter-bootstrap/_breadcrumbs.html.erb +11 -11
- data/lib/generators/bootstrap/agent/agent_generator.rb +81 -0
- data/lib/generators/bootstrap/agent/templates/guide.md.erb +61 -0
- data/lib/generators/bootstrap/doctor/doctor_generator.rb +39 -0
- data/lib/generators/bootstrap/partial/templates/_login.html.erb +11 -15
- data/lib/generators/bootstrap/snippets/snippet_base.rb +23 -4
- data/lib/generators/bootstrap/themed/templates/_form.html.haml +7 -9
- data/lib/generators/bootstrap/themed/templates/_form.html.slim +8 -10
- data/lib/generators/bootstrap/themed/templates/edit.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/edit.html.haml +1 -1
- data/lib/generators/bootstrap/themed/templates/edit.html.slim +1 -1
- data/lib/generators/bootstrap/themed/templates/index.html.haml +4 -4
- data/lib/generators/bootstrap/themed/templates/index.html.slim +4 -4
- data/lib/generators/bootstrap/themed/templates/new.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/new.html.haml +1 -1
- data/lib/generators/bootstrap/themed/templates/new.html.slim +1 -1
- data/lib/generators/bootstrap/themed/templates/show.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/show.html.haml +3 -3
- data/lib/generators/bootstrap/themed/templates/show.html.slim +3 -3
- data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.erb +1 -1
- data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.haml +2 -2
- data/lib/generators/bootstrap/themed/templates/simple_form/_form.html.slim +2 -2
- data/lib/twitter/bootstrap/rails/doctor.rb +207 -0
- data/lib/twitter/bootstrap/rails/legacy_markup.rb +119 -0
- data/lib/twitter/bootstrap/rails/version.rb +1 -1
- data/spec/lib/breadcrumbs_spec.rb +8 -2
- data/spec/lib/generators/agent_generator_spec.rb +111 -0
- data/spec/lib/generators/doctor_generator_spec.rb +216 -0
- data/spec/lib/generators/snippet_generators_spec.rb +23 -0
- data/spec/lib/twitter_bootstrap_rails/badge_label_helper_spec.rb +7 -3
- data/spec/lib/twitter_bootstrap_rails/bootstrap_flash_helper_spec.rb +23 -45
- data/spec/lib/twitter_bootstrap_rails/breadcrumbs_view_spec.rb +35 -0
- data/spec/lib/twitter_bootstrap_rails/flash_block_helper_spec.rb +26 -0
- data/spec/lib/twitter_bootstrap_rails/form_errors_helper_spec.rb +2 -2
- data/spec/lib/twitter_bootstrap_rails/legacy_markup_spec.rb +74 -0
- data/spec/lib/twitter_bootstrap_rails/modal_helper_spec.rb +21 -8
- data/spec/lib/twitter_bootstrap_rails/navbar_helper_spec.rb +94 -92
- data/spec/spec_helper.rb +0 -1
- data/spec/support/generator_spec_helper.rb +2 -0
- metadata +21 -3
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
module Twitter
|
|
2
|
+
module Bootstrap
|
|
3
|
+
module Rails
|
|
4
|
+
# Finds Bootstrap 2-4 markup that does nothing on the Bootstrap 5 this gem
|
|
5
|
+
# ships. bootstrap:doctor reports what it finds, bootstrap:agent turns the
|
|
6
|
+
# same tables into guidance, and a spec holds the gem's own templates to it.
|
|
7
|
+
module LegacyMarkup
|
|
8
|
+
DATA_ATTRIBUTES = %w[toggle target dismiss ride slide slide-to parent spy].freeze
|
|
9
|
+
|
|
10
|
+
CLASSES = {
|
|
11
|
+
"btn-default" => "btn-secondary",
|
|
12
|
+
"btn-xs" => "btn-sm",
|
|
13
|
+
"btn-block" => "w-100",
|
|
14
|
+
"navbar-default" => "bg-body-tertiary",
|
|
15
|
+
"navbar-inverse" => "bg-dark with data-bs-theme=\"dark\"",
|
|
16
|
+
"navbar-toggle" => "navbar-toggler",
|
|
17
|
+
"navbar-header" => "nothing (remove the wrapper)",
|
|
18
|
+
"navbar-left" => "me-auto",
|
|
19
|
+
"navbar-right" => "ms-auto",
|
|
20
|
+
"icon-bar" => "navbar-toggler-icon",
|
|
21
|
+
"caret" => "nothing (dropdown-toggle draws it)",
|
|
22
|
+
"divider" => "dropdown-divider on an hr",
|
|
23
|
+
"dropdown-submenu" => "dropdown-header (Bootstrap 5 has no nested dropdowns)",
|
|
24
|
+
"panel" => "card",
|
|
25
|
+
"panel-default" => "card",
|
|
26
|
+
"panel-heading" => "card-header",
|
|
27
|
+
"panel-body" => "card-body",
|
|
28
|
+
"panel-footer" => "card-footer",
|
|
29
|
+
"well" => "card",
|
|
30
|
+
"jumbotron" => "p-5 bg-body-tertiary rounded-3",
|
|
31
|
+
"page-header" => "border-bottom pb-2 mb-4",
|
|
32
|
+
"label" => "badge",
|
|
33
|
+
"badge-pill" => "rounded-pill",
|
|
34
|
+
"form-group" => "mb-3",
|
|
35
|
+
"form-inline" => "row with col-auto columns",
|
|
36
|
+
"form-horizontal" => "row with col-* columns",
|
|
37
|
+
"control-group" => "mb-3",
|
|
38
|
+
"control-label" => "form-label",
|
|
39
|
+
"controls" => "nothing (remove the wrapper)",
|
|
40
|
+
"has-error" => "is-invalid on the input",
|
|
41
|
+
"help-block" => "form-text",
|
|
42
|
+
"input-group-addon" => "input-group-text",
|
|
43
|
+
"custom-select" => "form-select",
|
|
44
|
+
"sr-only" => "visually-hidden",
|
|
45
|
+
"close" => "btn-close",
|
|
46
|
+
"in" => "show",
|
|
47
|
+
"hidden" => "d-none",
|
|
48
|
+
"pull-left" => "float-start",
|
|
49
|
+
"pull-right" => "float-end",
|
|
50
|
+
"float-left" => "float-start",
|
|
51
|
+
"float-right" => "float-end",
|
|
52
|
+
"text-left" => "text-start",
|
|
53
|
+
"text-right" => "text-end",
|
|
54
|
+
"font-weight-bold" => "fw-bold"
|
|
55
|
+
}.freeze
|
|
56
|
+
|
|
57
|
+
# [pattern, block turning the match into its replacement, example for docs]
|
|
58
|
+
CLASS_PATTERNS = [
|
|
59
|
+
[/\Acol-xs-(\d+)\z/, ->(m) { "col-#{m[1]}" }, "col-xs-6 becomes col-6"],
|
|
60
|
+
[/\Aglyphicon(-[\w-]+)?\z/, ->(_) { "Bootstrap Icons" }, "glyphicon-* becomes Bootstrap Icons"],
|
|
61
|
+
[/\A(?:label|badge)-(default|primary|secondary|success|info|warning|danger)\z/,
|
|
62
|
+
->(m) { "text-bg-#{m[1] == 'default' ? 'secondary' : m[1]}" }, "label-warning and badge-warning become text-bg-warning"],
|
|
63
|
+
[/\A([mp])([lr])(-(?:sm|md|lg|xl|xxl))?-(\d|auto)\z/,
|
|
64
|
+
->(m) { "#{m[1]}#{m[2] == 'l' ? 's' : 'e'}#{m[3]}-#{m[4]}" }, "ml-3 and pr-md-2 become ms-3 and pe-md-2"]
|
|
65
|
+
].freeze
|
|
66
|
+
|
|
67
|
+
DATA_ATTRIBUTE = /(?<![\w-])data-(#{DATA_ATTRIBUTES.join('|')})(?![\w-])/
|
|
68
|
+
RUBY_DATA_HASH = /(?:\bdata:\s*|:data\s*=>\s*)\{([^}]*)\}/
|
|
69
|
+
RUBY_DATA_KEY = /(?<![\w-]):?(#{DATA_ATTRIBUTES.join('|')})(?:\s*:|\s*=>)/
|
|
70
|
+
CLASS_VALUE = /(?:\bclass\s*=\s*|\bclass:\s*|:class\s*=>\s*|["']class["']\s*=>\s*)(["'])(.*?)\1/
|
|
71
|
+
EMBEDDED_CODE = /<%.*?%>|#\{.*?\}/
|
|
72
|
+
SHORTHAND = {
|
|
73
|
+
".haml" => /\A\s*(?:%[\w:-]+)?(?:#[\w-]+)?((?:\.[\w-]+)+)/,
|
|
74
|
+
".slim" => /\A\s*(?:[a-z][\w:-]*)?(?:#[\w-]+)?((?:\.[\w-]+)+)/
|
|
75
|
+
}.freeze
|
|
76
|
+
|
|
77
|
+
module_function
|
|
78
|
+
|
|
79
|
+
# Returns [{ :line, :found, :replacement }, ...] for a file's contents.
|
|
80
|
+
# extension (".erb", ".haml", ...) decides whether to read class shorthand.
|
|
81
|
+
def scan(text, extension)
|
|
82
|
+
text.each_line.with_index(1).flat_map do |line, number|
|
|
83
|
+
scan_line(line, extension).map { |found, replacement| { :line => number, :found => found, :replacement => replacement } }
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def scan_line(line, extension)
|
|
88
|
+
data_attributes(line) + class_names(line, extension).filter_map do |name|
|
|
89
|
+
replacement = replacement_for(name)
|
|
90
|
+
[name, replacement] if replacement
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def data_attributes(line)
|
|
95
|
+
names = line.scan(DATA_ATTRIBUTE).flatten
|
|
96
|
+
line.scan(RUBY_DATA_HASH).flatten.each { |pairs| names.concat(pairs.scan(RUBY_DATA_KEY).flatten) }
|
|
97
|
+
names.map { |name| ["data-#{name}", "data-bs-#{name}"] }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def class_names(line, extension)
|
|
101
|
+
names = line.scan(CLASS_VALUE).flat_map { |_quote, value| value.gsub(EMBEDDED_CODE, " ").split }
|
|
102
|
+
shorthand = SHORTHAND[extension] && line[SHORTHAND[extension], 1]
|
|
103
|
+
names.concat(shorthand.split(".").reject(&:empty?)) if shorthand
|
|
104
|
+
names
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def replacement_for(name)
|
|
108
|
+
return CLASSES[name] if CLASSES.key?(name)
|
|
109
|
+
|
|
110
|
+
CLASS_PATTERNS.each do |pattern, replacement, _example|
|
|
111
|
+
match = pattern.match(name)
|
|
112
|
+
return replacement.call(match) if match
|
|
113
|
+
end
|
|
114
|
+
nil
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -44,6 +44,12 @@ describe Twitter::Bootstrap::Breadcrumbs do
|
|
|
44
44
|
def test_models_path
|
|
45
45
|
'/test_model'
|
|
46
46
|
end
|
|
47
|
+
|
|
48
|
+
# polymorphic_path looks up custom mappings here before calling the named
|
|
49
|
+
# route helper above. A bare AbstractController has no route set of its own.
|
|
50
|
+
def _routes
|
|
51
|
+
@_routes ||= ActionDispatch::Routing::RouteSet.new
|
|
52
|
+
end
|
|
47
53
|
end
|
|
48
54
|
|
|
49
55
|
describe 'Breadcrumbs generation' do
|
|
@@ -51,12 +57,12 @@ describe Twitter::Bootstrap::Breadcrumbs do
|
|
|
51
57
|
before do
|
|
52
58
|
options = { :scope => [:breadcrumbs, 'test'] }
|
|
53
59
|
[:class_i18n, :instance_i18n, :show, :symbolized].each do |name|
|
|
54
|
-
I18n.
|
|
60
|
+
expect(I18n).to receive(:t).with(name, **options).and_return(name.to_s)
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
name = :base_i18n
|
|
58
64
|
options = { :scope => [:breadcrumbs, 'base_test'] }
|
|
59
|
-
I18n.
|
|
65
|
+
expect(I18n).to receive(:t).with(name, **options).and_return(name)
|
|
60
66
|
|
|
61
67
|
@controller = TestController.new
|
|
62
68
|
@controller.process(:show)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bootstrap::Generators::AgentGenerator do
|
|
4
|
+
let(:rails_mod) { Twitter::Bootstrap::Rails }
|
|
5
|
+
let(:skill_path) { ".claude/skills/bootstrap-rails/SKILL.md" }
|
|
6
|
+
|
|
7
|
+
before { stub_rails_application }
|
|
8
|
+
|
|
9
|
+
def skill
|
|
10
|
+
read_destination(skill_path)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def agents
|
|
14
|
+
read_destination("AGENTS.md")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "writes a Claude skill with the frontmatter Claude needs" do
|
|
18
|
+
run_generator(described_class)
|
|
19
|
+
|
|
20
|
+
expect(skill).to start_with("---\nname: bootstrap-rails\ndescription: ")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "writes the guide to AGENTS.md" do
|
|
24
|
+
run_generator(described_class)
|
|
25
|
+
|
|
26
|
+
expect(agents).to include("Bootstrap #{rails_mod::BOOTSTRAP_VERSION}")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "keeps what is already in AGENTS.md" do
|
|
30
|
+
write_destination("AGENTS.md", "# My rules\n\nUse tabs.\n")
|
|
31
|
+
|
|
32
|
+
run_generator(described_class)
|
|
33
|
+
|
|
34
|
+
expect(agents).to start_with("# My rules\n\nUse tabs.\n")
|
|
35
|
+
expect(agents).to include("Bootstrap #{rails_mod::BOOTSTRAP_VERSION}")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "replaces its own section when run again instead of adding another" do
|
|
39
|
+
write_destination("AGENTS.md", "# My rules\n")
|
|
40
|
+
rails_mod.asset_pipeline = :sprockets
|
|
41
|
+
run_generator(described_class)
|
|
42
|
+
rails_mod.asset_pipeline = :propshaft
|
|
43
|
+
run_generator(described_class)
|
|
44
|
+
|
|
45
|
+
expect(agents.scan("bootstrap-rails:start").size).to eq(1)
|
|
46
|
+
expect(agents).to include("Propshaft")
|
|
47
|
+
expect(agents).not_to include("Sprockets directives")
|
|
48
|
+
expect(agents).to start_with("# My rules\n")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "does not stop to ask when the skill already exists" do
|
|
52
|
+
run_generator(described_class)
|
|
53
|
+
rails_mod.asset_pipeline = :propshaft
|
|
54
|
+
allow($stdin).to receive(:gets).and_raise("prompted for input")
|
|
55
|
+
|
|
56
|
+
expect { run_generator(described_class) }.not_to raise_error
|
|
57
|
+
expect(skill).to include("Propshaft")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "skips each file on request" do
|
|
61
|
+
run_generator(described_class, %w[--no-claude])
|
|
62
|
+
expect(destination_exist?(skill_path)).to be false
|
|
63
|
+
expect(destination_exist?("AGENTS.md")).to be true
|
|
64
|
+
|
|
65
|
+
FileUtils.rm(destination_path("AGENTS.md"))
|
|
66
|
+
run_generator(described_class, %w[--no-agents])
|
|
67
|
+
expect(destination_exist?(skill_path)).to be true
|
|
68
|
+
expect(destination_exist?("AGENTS.md")).to be false
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "writes nothing with --pretend" do
|
|
72
|
+
write_destination("AGENTS.md", "# Mine\n")
|
|
73
|
+
|
|
74
|
+
run_generator(described_class, %w[--pretend])
|
|
75
|
+
|
|
76
|
+
expect(agents).to eq("# Mine\n")
|
|
77
|
+
expect(destination_exist?(skill_path)).to be false
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe "the guide" do
|
|
81
|
+
it "describes this app's setup" do
|
|
82
|
+
rails_mod.asset_pipeline = :propshaft
|
|
83
|
+
stub_rails_application(:haml)
|
|
84
|
+
run_generator(described_class)
|
|
85
|
+
|
|
86
|
+
expect(skill).to include("Propshaft").and include("Template engine: haml")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "lists every snippet generator and variant from the catalog" do
|
|
90
|
+
run_generator(described_class)
|
|
91
|
+
catalog = Bootstrap::Generators::SnippetCatalog
|
|
92
|
+
|
|
93
|
+
catalog::GENERATORS.each do |generator, category|
|
|
94
|
+
expect(skill).to include("bootstrap:#{generator}")
|
|
95
|
+
catalog.variant_names(category).each { |variant| expect(skill).to include(variant) }
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "names the old markup to avoid, from the same table the doctor uses" do
|
|
100
|
+
run_generator(described_class)
|
|
101
|
+
|
|
102
|
+
expect(skill).to include("data-toggle").and include("btn-default").and include("btn-secondary")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "tells agents how to check their work" do
|
|
106
|
+
run_generator(described_class)
|
|
107
|
+
|
|
108
|
+
expect(skill).to include("rails g bootstrap:doctor --json")
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bootstrap::Generators::DoctorGenerator do
|
|
4
|
+
let(:rails_mod) { Twitter::Bootstrap::Rails }
|
|
5
|
+
let(:version) { rails_mod::BOOTSTRAP_VERSION }
|
|
6
|
+
|
|
7
|
+
before { stub_rails_application }
|
|
8
|
+
|
|
9
|
+
def report
|
|
10
|
+
rails_mod::Doctor.new(destination_root).report
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def check(id)
|
|
14
|
+
report[:checks].find { |c| c[:id] == id }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def install_static_on_propshaft
|
|
18
|
+
rails_mod.asset_pipeline = :propshaft
|
|
19
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
20
|
+
run_generator(Bootstrap::Generators::LayoutGenerator)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "where Bootstrap comes from" do
|
|
24
|
+
it "is happy with a Propshaft app set up by the generators" do
|
|
25
|
+
install_static_on_propshaft
|
|
26
|
+
|
|
27
|
+
expect(report).to include(:status => "ok", :asset_mode => "static", :asset_pipeline => "propshaft")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "is happy with a Sprockets app set up by the generators" do
|
|
31
|
+
rails_mod.asset_pipeline = :sprockets
|
|
32
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
33
|
+
run_generator(Bootstrap::Generators::LayoutGenerator)
|
|
34
|
+
|
|
35
|
+
expect(report).to include(:status => "ok", :asset_pipeline => "sprockets")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "is happy with a CDN app set up by the generators" do
|
|
39
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[cdn])
|
|
40
|
+
run_generator(Bootstrap::Generators::LayoutGenerator, %w[--cdn])
|
|
41
|
+
|
|
42
|
+
expect(report).to include(:status => "ok", :asset_mode => "cdn")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "reports an error when a Propshaft layout does not link the vendored files" do
|
|
46
|
+
rails_mod.asset_pipeline = :propshaft
|
|
47
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
48
|
+
write_destination("app/views/layouts/application.html.erb", %{<%= stylesheet_link_tag "application" %>})
|
|
49
|
+
|
|
50
|
+
expect(check("bootstrap_css")).to include(:status => "error", :fix => a_string_including("bootstrap:layout"))
|
|
51
|
+
expect(check("bootstrap_js")[:status]).to eq("error")
|
|
52
|
+
expect(report[:status]).to eq("error")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "reports an error when the layout links vendored files that are not there" do
|
|
56
|
+
rails_mod.asset_pipeline = :propshaft
|
|
57
|
+
write_destination("app/views/layouts/application.html.erb",
|
|
58
|
+
%{<%= stylesheet_link_tag "twitter/bootstrap/bootstrap.min" %>})
|
|
59
|
+
|
|
60
|
+
expect(check("bootstrap_css")).to include(:status => "error", :fix => a_string_including("bootstrap:install"))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "reports an error when a Sprockets manifest requires Bootstrap but no layout links it" do
|
|
64
|
+
rails_mod.asset_pipeline = :sprockets
|
|
65
|
+
run_generator(Bootstrap::Generators::InstallGenerator, %w[static])
|
|
66
|
+
|
|
67
|
+
expect(check("bootstrap_css")[:status]).to eq("error")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "only warns when Bootstrap comes from a JavaScript bundler it can't verify" do
|
|
71
|
+
write_destination("package.json", %{{"dependencies": {"bootstrap": "^5.3.0"}}})
|
|
72
|
+
|
|
73
|
+
expect(check("bootstrap_css")[:status]).to eq("warn")
|
|
74
|
+
expect(check("bootstrap_js")[:status]).to eq("warn")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "reads the mode from the layout if the initializer is missing" do
|
|
78
|
+
write_destination("app/views/layouts/application.html.erb",
|
|
79
|
+
%{<link href="https://cdn.jsdelivr.net/npm/bootstrap@#{version}/dist/css/bootstrap.min.css">})
|
|
80
|
+
|
|
81
|
+
expect(report[:asset_mode]).to eq("cdn")
|
|
82
|
+
expect(check("bootstrap_css")[:status]).to eq("ok")
|
|
83
|
+
expect(check("bootstrap_js")[:status]).to eq("error")
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe "the Bootstrap version" do
|
|
88
|
+
it "warns about an old CDN version" do
|
|
89
|
+
write_destination("app/views/layouts/application.html.erb",
|
|
90
|
+
%{<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css">})
|
|
91
|
+
|
|
92
|
+
expect(check("bootstrap_version")).to include(:status => "warn", :message => a_string_including("5.1.0"))
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "warns about old vendored files" do
|
|
96
|
+
install_static_on_propshaft
|
|
97
|
+
write_destination("app/assets/stylesheets/twitter/bootstrap/bootstrap.min.css", "/*! Bootstrap v5.3.3 */")
|
|
98
|
+
|
|
99
|
+
expect(check("bootstrap_version")).to include(:status => "warn", :message => a_string_including("5.3.3"))
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "accepts what the generators installed" do
|
|
103
|
+
install_static_on_propshaft
|
|
104
|
+
|
|
105
|
+
expect(check("bootstrap_version")[:status]).to eq("ok")
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
describe "the icon sprite" do
|
|
110
|
+
let(:layout) { "app/views/layouts/application.html.erb" }
|
|
111
|
+
|
|
112
|
+
before { run_generator(Bootstrap::Generators::HeaderGenerator) }
|
|
113
|
+
|
|
114
|
+
it "reports an error when it is installed but never rendered" do
|
|
115
|
+
write_destination(layout, "<body></body>")
|
|
116
|
+
|
|
117
|
+
expect(check("icon_sprite")).to include(:status => "error", :fix => a_string_including('render "shared/bootstrap_icons"'))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "is happy when it is rendered once" do
|
|
121
|
+
write_destination(layout, %{<%= render "shared/bootstrap_icons" %>})
|
|
122
|
+
|
|
123
|
+
expect(check("icon_sprite")[:status]).to eq("ok")
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it "warns when it is rendered more than once" do
|
|
127
|
+
write_destination(layout, %{<%= render "shared/bootstrap_icons" %>})
|
|
128
|
+
write_destination("app/views/tasks/index.html.erb", %{<%= render "shared/bootstrap_icons" %>})
|
|
129
|
+
|
|
130
|
+
expect(check("icon_sprite")[:status]).to eq("warn")
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "has nothing to say about the sprite when it is not installed" do
|
|
135
|
+
expect(check("icon_sprite")[:status]).to eq("ok")
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "warns about placeholder images left in a view, with the location" do
|
|
139
|
+
run_generator(Bootstrap::Generators::HeroGenerator, %w[centered])
|
|
140
|
+
|
|
141
|
+
expect(check("placeholder_images")[:status]).to eq("warn")
|
|
142
|
+
expect(check("placeholder_images")[:files].first).to start_with("app/views/shared/_hero.html.erb:")
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
describe "legacy markup" do
|
|
146
|
+
it "lists each finding with its location" do
|
|
147
|
+
write_destination("app/views/tasks/index.html.erb", %{<p>ok</p>\n<a class="btn btn-default" data-toggle="modal">x</a>})
|
|
148
|
+
|
|
149
|
+
expect(report[:legacy_markup]).to contain_exactly(
|
|
150
|
+
a_hash_including(:file => "app/views/tasks/index.html.erb", :line => 2, :found => "btn-default"),
|
|
151
|
+
a_hash_including(:file => "app/views/tasks/index.html.erb", :line => 2, :found => "data-toggle")
|
|
152
|
+
)
|
|
153
|
+
expect(check("legacy_markup")).to include(:status => "warn", :message => a_string_including("2"))
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "also scans helpers" do
|
|
157
|
+
write_destination("app/helpers/tasks_helper.rb", %{tag.a("x", class: "pull-right")})
|
|
158
|
+
|
|
159
|
+
expect(report[:legacy_markup].first[:found]).to eq("pull-right")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "does not scan other directories" do
|
|
163
|
+
write_destination("vendor/theme/index.html.erb", %{<a class="btn-default"></a>})
|
|
164
|
+
|
|
165
|
+
expect(report[:legacy_markup]).to be_empty
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
describe "facts" do
|
|
170
|
+
it "states the versions and template engine" do
|
|
171
|
+
expect(report).to include(
|
|
172
|
+
:bootstrap_version => version,
|
|
173
|
+
:gem_version => rails_mod::VERSION,
|
|
174
|
+
:rails_version => ::Rails.version,
|
|
175
|
+
:template_engine => "erb"
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
describe "the command" do
|
|
181
|
+
before { install_static_on_propshaft }
|
|
182
|
+
|
|
183
|
+
it "prints the report as JSON with --json" do
|
|
184
|
+
parsed = JSON.parse(run_generator(described_class, %w[--json]))
|
|
185
|
+
|
|
186
|
+
expect(parsed).to include("status" => "ok", "bootstrap_version" => version)
|
|
187
|
+
expect(parsed["checks"].map { |c| c["id"] }).to include("bootstrap_css", "legacy_markup")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "prints readable lines without --json" do
|
|
191
|
+
output = run_generator(described_class)
|
|
192
|
+
|
|
193
|
+
expect(output).to match(/\[ok\]\s+bootstrap_css/)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "writes nothing" do
|
|
197
|
+
before = Dir[destination_path("**/*")].sort
|
|
198
|
+
run_generator(described_class)
|
|
199
|
+
|
|
200
|
+
expect(Dir[destination_path("**/*")].sort).to eq(before)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it "exits non-zero when a check fails, so agents and CI can rely on it" do
|
|
204
|
+
FileUtils.rm(destination_path("app/views/layouts/application.html.erb"))
|
|
205
|
+
|
|
206
|
+
expect { run_generator(described_class, %w[--json]) }
|
|
207
|
+
.to raise_error(SystemExit) { |e| expect(e.status).to eq(1) }
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
it "exits normally on warnings" do
|
|
211
|
+
write_destination("app/views/tasks/index.html.erb", %{<a class="btn-default"></a>})
|
|
212
|
+
|
|
213
|
+
expect { run_generator(described_class) }.not_to raise_error
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
@@ -171,6 +171,29 @@ describe "Bootstrap snippet generators" do
|
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
+
describe "--json" do
|
|
175
|
+
let(:listing) { JSON.parse(run_generator(generator_for("hero"), %w[--json])) }
|
|
176
|
+
|
|
177
|
+
it "describes the generator and its default variant" do
|
|
178
|
+
expect(listing).to include("generator" => "bootstrap:hero", "category" => "heroes", "default" => "centered")
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "lists every variant with what it needs" do
|
|
182
|
+
expect(listing["variants"].map { |v| v["name"] }).to eq(Catalog.variant_names("heroes"))
|
|
183
|
+
expect(listing["variants"].first).to include("description" => a_kind_of(String), "icons" => false, "images" => true)
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "gives the command that generates each variant" do
|
|
187
|
+
expect(listing["variants"].last["command"]).to eq("rails g bootstrap:hero dark")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "writes nothing" do
|
|
191
|
+
listing
|
|
192
|
+
|
|
193
|
+
expect(Dir[destination_path("**/*")]).to be_empty
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
174
197
|
describe "--list" do
|
|
175
198
|
it "prints each variant with its description and writes nothing" do
|
|
176
199
|
output = run_generator(generator_for("sidebar"), %w[--list])
|
|
@@ -19,12 +19,16 @@ describe BadgeLabelHelper, :type => :helper do
|
|
|
19
19
|
.to eql(BADGE_WITH_CLASS.gsub(/\s/, '').downcase)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
it "should render tag_label as a badge, since Bootstrap 5 has no labels" do
|
|
23
|
+
expect(tag_label('Beta', :info)).to eql %{<span class="badge text-bg-info">Beta</span>}
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
it "should take a Number as its first parameter" do
|
|
23
27
|
expect(badge(12).gsub(/\s/, '').downcase)
|
|
24
28
|
.to eql(BADGE_WITH_NUMBER_PARAM.gsub(/\s/, '').downcase)
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
28
|
-
BASIC_BADGE = %{<span class="badge">New!</span>}
|
|
29
|
-
BADGE_WITH_CLASS = %{<span class="badge
|
|
30
|
-
BADGE_WITH_NUMBER_PARAM = %{<span class="badge">12</span>}
|
|
32
|
+
BASIC_BADGE = %{<span class="badge text-bg-secondary">New!</span>}
|
|
33
|
+
BADGE_WITH_CLASS = %{<span class="badge text-bg-warning">2</span>}
|
|
34
|
+
BADGE_WITH_NUMBER_PARAM = %{<span class="badge text-bg-secondary">12</span>}
|
|
@@ -29,16 +29,10 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
29
29
|
element = bootstrap_flash
|
|
30
30
|
|
|
31
31
|
expect(element).to have_tag(:div,
|
|
32
|
-
text: "
|
|
33
|
-
with: {class: "alert
|
|
32
|
+
text: "Hello",
|
|
33
|
+
with: {class: "alert alert-success alert-dismissible fade show"}) {
|
|
34
34
|
|
|
35
|
-
with_tag(:button,
|
|
36
|
-
text: "×",
|
|
37
|
-
with: {
|
|
38
|
-
class: "close",
|
|
39
|
-
"data-dismiss" => "alert"
|
|
40
|
-
}
|
|
41
|
-
)
|
|
35
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
42
36
|
|
|
43
37
|
}
|
|
44
38
|
end
|
|
@@ -49,16 +43,10 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
49
43
|
element = bootstrap_flash(class: "extra-class")
|
|
50
44
|
|
|
51
45
|
expect(element).to have_tag(:div,
|
|
52
|
-
text: "
|
|
53
|
-
with: {class: "alert
|
|
46
|
+
text: "Hello",
|
|
47
|
+
with: {class: "alert alert-success alert-dismissible fade show extra-class"}) {
|
|
54
48
|
|
|
55
|
-
with_tag(:button,
|
|
56
|
-
text: "×",
|
|
57
|
-
with: {
|
|
58
|
-
class: "close",
|
|
59
|
-
"data-dismiss" => "alert"
|
|
60
|
-
}
|
|
61
|
-
)
|
|
49
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
62
50
|
|
|
63
51
|
}
|
|
64
52
|
end
|
|
@@ -69,19 +57,13 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
69
57
|
element = bootstrap_flash(class: "extra-class", "data-no-transition-cache" => true)
|
|
70
58
|
|
|
71
59
|
expect(element).to have_tag(:div,
|
|
72
|
-
text: "
|
|
60
|
+
text: "Hello",
|
|
73
61
|
with: {
|
|
74
|
-
class: "alert
|
|
62
|
+
class: "alert alert-success alert-dismissible fade show extra-class",
|
|
75
63
|
"data-no-transition-cache" => true
|
|
76
64
|
}) {
|
|
77
65
|
|
|
78
|
-
with_tag(:button,
|
|
79
|
-
text: "×",
|
|
80
|
-
with: {
|
|
81
|
-
class: "close",
|
|
82
|
-
"data-dismiss" => "alert"
|
|
83
|
-
}
|
|
84
|
-
)
|
|
66
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
85
67
|
|
|
86
68
|
}
|
|
87
69
|
end
|
|
@@ -92,33 +74,29 @@ describe BootstrapFlashHelper, type: :helper do
|
|
|
92
74
|
element = bootstrap_flash
|
|
93
75
|
|
|
94
76
|
expect(element).to have_tag(:div,
|
|
95
|
-
text: "
|
|
96
|
-
with: {class: "alert
|
|
97
|
-
with_tag(:button,
|
|
98
|
-
text: "×",
|
|
99
|
-
with: {
|
|
100
|
-
class: "close",
|
|
101
|
-
"data-dismiss" => "alert"
|
|
102
|
-
}
|
|
103
|
-
)
|
|
77
|
+
text: "<script>alert(1)</script>",
|
|
78
|
+
with: {class: "alert alert-success alert-dismissible fade show"}) {
|
|
79
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"})
|
|
104
80
|
}
|
|
105
81
|
end
|
|
106
82
|
|
|
83
|
+
it "should keep the extra class on every message" do
|
|
84
|
+
allow(self).to receive(:flash) { {notice: ["One", "Two"]} }
|
|
85
|
+
|
|
86
|
+
element = bootstrap_flash(class: "extra-class")
|
|
87
|
+
|
|
88
|
+
expect(element).to have_tag("div.extra-class", count: 2)
|
|
89
|
+
end
|
|
90
|
+
|
|
107
91
|
it "should not escape a link if marked as safe by user" do
|
|
108
92
|
allow(self).to receive(:flash) { {notice: "<a href='example.com'>awesome link!</a>".html_safe} }
|
|
109
93
|
|
|
110
94
|
element = bootstrap_flash
|
|
111
95
|
|
|
112
96
|
expect(element).to have_tag(:div,
|
|
113
|
-
text: "
|
|
114
|
-
with: {class: "alert
|
|
115
|
-
with_tag(:button,
|
|
116
|
-
text: "×",
|
|
117
|
-
with: {
|
|
118
|
-
class: "close",
|
|
119
|
-
"data-dismiss" => "alert"
|
|
120
|
-
}
|
|
121
|
-
),
|
|
97
|
+
text: "awesome link!",
|
|
98
|
+
with: {class: "alert alert-success alert-dismissible fade show"}) { [
|
|
99
|
+
with_tag(:button, with: {class: "btn-close", "data-bs-dismiss" => "alert", type: "button", "aria-label" => "Close"}),
|
|
122
100
|
with_tag(:a,
|
|
123
101
|
text: 'awesome link!')
|
|
124
102
|
]
|