twitter-bootstrap-rails 5.3.1 → 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 +124 -0
- data/README.md +221 -4
- data/app/assets/javascripts/twitter/bootstrap/bootstrap.min.js +3 -3
- data/app/assets/stylesheets/twitter-bootstrap-static/bootstrap.css +3 -3
- 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/badge/badge_generator.rb +13 -0
- data/lib/generators/bootstrap/breadcrumb/breadcrumb_generator.rb +13 -0
- data/lib/generators/bootstrap/button/button_generator.rb +13 -0
- data/lib/generators/bootstrap/cdn/cdn_generator.rb +39 -0
- data/lib/generators/bootstrap/cdn_tags.rb +43 -0
- data/lib/generators/bootstrap/doctor/doctor_generator.rb +39 -0
- data/lib/generators/bootstrap/dropdown/dropdown_generator.rb +13 -0
- data/lib/generators/bootstrap/features/features_generator.rb +13 -0
- data/lib/generators/bootstrap/footer/footer_generator.rb +13 -0
- data/lib/generators/bootstrap/header/header_generator.rb +13 -0
- data/lib/generators/bootstrap/hero/hero_generator.rb +13 -0
- data/lib/generators/bootstrap/install/install_generator.rb +120 -61
- data/lib/generators/bootstrap/install/templates/application.js +1 -1
- data/lib/generators/bootstrap/install/templates/bootstrap.js +10 -3
- data/lib/generators/bootstrap/install/templates/bootstrap_and_overrides.css +2 -2
- data/lib/generators/bootstrap/jumbotron/jumbotron_generator.rb +13 -0
- data/lib/generators/bootstrap/layout/layout_generator.rb +65 -1
- data/lib/generators/bootstrap/layout/templates/layout.html.erb +14 -9
- data/lib/generators/bootstrap/layout/templates/layout.html.haml +28 -43
- data/lib/generators/bootstrap/layout/templates/layout.html.slim +25 -40
- data/lib/generators/bootstrap/list_group/list_group_generator.rb +13 -0
- data/lib/generators/bootstrap/modal/modal_generator.rb +13 -0
- data/lib/generators/bootstrap/partial/templates/_login.html.erb +11 -15
- data/lib/generators/bootstrap/sidebar/sidebar_generator.rb +13 -0
- data/lib/generators/bootstrap/snippets/snippet_base.rb +145 -0
- data/lib/generators/bootstrap/snippets/snippet_catalog.rb +134 -0
- data/lib/generators/bootstrap/snippets/templates/badges/pills.html.erb +10 -0
- data/lib/generators/bootstrap/snippets/templates/badges/subtle.html.erb +10 -0
- data/lib/generators/bootstrap/snippets/templates/badges/subtle_bordered.html.erb +20 -0
- data/lib/generators/bootstrap/snippets/templates/badges/with_avatar.html.erb +34 -0
- data/lib/generators/bootstrap/snippets/templates/badges/with_avatar_divider.html.erb +66 -0
- data/lib/generators/bootstrap/snippets/templates/badges/with_icons.html.erb +26 -0
- data/lib/generators/bootstrap/snippets/templates/breadcrumbs/basic.html.erb +9 -0
- data/lib/generators/bootstrap/snippets/templates/breadcrumbs/chevron.html.erb +18 -0
- data/lib/generators/bootstrap/snippets/templates/breadcrumbs/custom.html.erb +18 -0
- data/lib/generators/bootstrap/snippets/templates/breadcrumbs/with_icons.html.erb +18 -0
- data/lib/generators/bootstrap/snippets/templates/buttons/circle.html.erb +20 -0
- data/lib/generators/bootstrap/snippets/templates/buttons/grid.html.erb +6 -0
- data/lib/generators/bootstrap/snippets/templates/buttons/loading.html.erb +10 -0
- data/lib/generators/bootstrap/snippets/templates/buttons/pills.html.erb +11 -0
- data/lib/generators/bootstrap/snippets/templates/buttons/with_icons.html.erb +14 -0
- data/lib/generators/bootstrap/snippets/templates/dropdowns/calendar.html.erb +156 -0
- data/lib/generators/bootstrap/snippets/templates/dropdowns/mega_menu.html.erb +140 -0
- data/lib/generators/bootstrap/snippets/templates/dropdowns/simple.html.erb +20 -0
- data/lib/generators/bootstrap/snippets/templates/dropdowns/with_icons.html.erb +88 -0
- data/lib/generators/bootstrap/snippets/templates/dropdowns/with_search.html.erb +64 -0
- data/lib/generators/bootstrap/snippets/templates/features/columns_with_icons.html.erb +46 -0
- data/lib/generators/bootstrap/snippets/templates/features/custom_cards.html.erb +79 -0
- data/lib/generators/bootstrap/snippets/templates/features/hanging_icons.html.erb +41 -0
- data/lib/generators/bootstrap/snippets/templates/features/icon_grid.html.erb +77 -0
- data/lib/generators/bootstrap/snippets/templates/features/with_title.html.erb +50 -0
- data/lib/generators/bootstrap/snippets/templates/footers/columns.html.erb +43 -0
- data/lib/generators/bootstrap/snippets/templates/footers/simple.html.erb +15 -0
- data/lib/generators/bootstrap/snippets/templates/footers/with_brand.html.erb +22 -0
- data/lib/generators/bootstrap/snippets/templates/footers/with_nav.html.erb +12 -0
- data/lib/generators/bootstrap/snippets/templates/footers/with_newsletter.html.erb +62 -0
- data/lib/generators/bootstrap/snippets/templates/headers/centered.html.erb +15 -0
- data/lib/generators/bootstrap/snippets/templates/headers/dark_double.html.erb +66 -0
- data/lib/generators/bootstrap/snippets/templates/headers/dark_search.html.erb +25 -0
- data/lib/generators/bootstrap/snippets/templates/headers/double.html.erb +28 -0
- data/lib/generators/bootstrap/snippets/templates/headers/grid_dropdown.html.erb +47 -0
- data/lib/generators/bootstrap/snippets/templates/headers/light_search.html.erb +34 -0
- data/lib/generators/bootstrap/snippets/templates/headers/nav_pills.html.erb +11 -0
- data/lib/generators/bootstrap/snippets/templates/headers/with_auth_buttons.html.erb +22 -0
- data/lib/generators/bootstrap/snippets/templates/heroes/centered.html.erb +13 -0
- data/lib/generators/bootstrap/snippets/templates/heroes/centered_screenshot.html.erb +17 -0
- data/lib/generators/bootstrap/snippets/templates/heroes/cropped_image.html.erb +17 -0
- data/lib/generators/bootstrap/snippets/templates/heroes/dark.html.erb +14 -0
- data/lib/generators/bootstrap/snippets/templates/heroes/signup_form.html.erb +26 -0
- data/lib/generators/bootstrap/snippets/templates/heroes/with_image.html.erb +17 -0
- data/lib/generators/bootstrap/snippets/templates/icons/_bootstrap_icons.html.erb +134 -0
- data/lib/generators/bootstrap/snippets/templates/jumbotrons/basic.html.erb +10 -0
- data/lib/generators/bootstrap/snippets/templates/jumbotrons/full_width.html.erb +12 -0
- data/lib/generators/bootstrap/snippets/templates/jumbotrons/placeholder.html.erb +13 -0
- data/lib/generators/bootstrap/snippets/templates/jumbotrons/with_icon.html.erb +22 -0
- data/lib/generators/bootstrap/snippets/templates/list-groups/checkable.html.erb +24 -0
- data/lib/generators/bootstrap/snippets/templates/list-groups/checkboxes.html.erb +45 -0
- data/lib/generators/bootstrap/snippets/templates/list-groups/checkboxes_expanded.html.erb +52 -0
- data/lib/generators/bootstrap/snippets/templates/list-groups/radios.html.erb +32 -0
- data/lib/generators/bootstrap/snippets/templates/list-groups/with_avatars.html.erb +36 -0
- data/lib/generators/bootstrap/snippets/templates/modals/confirm.html.erb +18 -0
- data/lib/generators/bootstrap/snippets/templates/modals/sheet.html.erb +19 -0
- data/lib/generators/bootstrap/snippets/templates/modals/signup.html.erb +44 -0
- data/lib/generators/bootstrap/snippets/templates/modals/whats_new.html.erb +41 -0
- data/lib/generators/bootstrap/snippets/templates/sidebars/collapsible.html.erb +90 -0
- data/lib/generators/bootstrap/snippets/templates/sidebars/dark.html.erb +67 -0
- data/lib/generators/bootstrap/snippets/templates/sidebars/icon_only.html.erb +59 -0
- data/lib/generators/bootstrap/snippets/templates/sidebars/light.html.erb +67 -0
- data/lib/generators/bootstrap/snippets/templates/sidebars/list_group.html.erb +94 -0
- data/lib/generators/bootstrap/starter/starter_generator.rb +37 -0
- data/lib/generators/bootstrap/starter/templates/starter.html.erb +13 -0
- 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/bootstrap.rb +1 -0
- data/lib/twitter/bootstrap/rails/config.rb +54 -0
- data/lib/twitter/bootstrap/rails/doctor.rb +207 -0
- data/lib/twitter/bootstrap/rails/engine.rb +0 -8
- data/lib/twitter/bootstrap/rails/legacy_markup.rb +119 -0
- data/lib/twitter/bootstrap/rails/version.rb +28 -1
- data/lib/twitter-bootstrap-rails.rb +0 -1
- data/spec/lib/breadcrumbs_spec.rb +8 -2
- data/spec/lib/generators/agent_generator_spec.rb +111 -0
- data/spec/lib/generators/cdn_generator_spec.rb +42 -0
- data/spec/lib/generators/doctor_generator_spec.rb +216 -0
- data/spec/lib/generators/install_generator_spec.rb +148 -0
- data/spec/lib/generators/layout_generator_spec.rb +124 -0
- data/spec/lib/generators/no_hardcoded_versions_spec.rb +45 -0
- data/spec/lib/generators/snippet_generators_spec.rb +224 -0
- data/spec/lib/generators/starter_generator_spec.rb +54 -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 +5 -1
- data/spec/support/generator_spec_helper.rb +89 -0
- data/vendor/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js +3 -3
- data/vendor/assets/stylesheets/twitter/bootstrap/bootstrap.min.css +3 -3
- metadata +114 -120
- data/app/assets/fonts/glyphicons-halflings-regular.eot +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.svg +0 -288
- data/app/assets/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff +0 -0
- data/app/assets/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/app/helpers/glyph_helper.rb +0 -23
- data/lib/generators/bootstrap/install/templates/bootstrap.coffee +0 -3
- data/lib/generators/bootstrap/install/templates/bootstrap_and_overrides.less +0 -21
- data/spec/lib/twitter_bootstrap_rails/glyph_helper_spec.rb +0 -24
- data/vendor/assets/stylesheets/twitter-bootstrap-static/bootstrap.css.erb +0 -6684
- data/vendor/static-source/bootstrap.less +0 -1
- data/vendor/static-source/sprites.less +0 -6
- data/vendor/toolkit/twitter/bootstrap/alerts.less +0 -73
- data/vendor/toolkit/twitter/bootstrap/badges.less +0 -66
- data/vendor/toolkit/twitter/bootstrap/bootstrap.less +0 -55
- data/vendor/toolkit/twitter/bootstrap/breadcrumbs.less +0 -26
- data/vendor/toolkit/twitter/bootstrap/button-groups.less +0 -244
- data/vendor/toolkit/twitter/bootstrap/buttons.less +0 -166
- data/vendor/toolkit/twitter/bootstrap/carousel.less +0 -270
- data/vendor/toolkit/twitter/bootstrap/close.less +0 -34
- data/vendor/toolkit/twitter/bootstrap/code.less +0 -69
- data/vendor/toolkit/twitter/bootstrap/component-animations.less +0 -33
- data/vendor/toolkit/twitter/bootstrap/dropdowns.less +0 -216
- data/vendor/toolkit/twitter/bootstrap/forms.less +0 -613
- data/vendor/toolkit/twitter/bootstrap/glyphicons.less +0 -305
- data/vendor/toolkit/twitter/bootstrap/grid.less +0 -84
- data/vendor/toolkit/twitter/bootstrap/input-groups.less +0 -171
- data/vendor/toolkit/twitter/bootstrap/jumbotron.less +0 -54
- data/vendor/toolkit/twitter/bootstrap/labels.less +0 -64
- data/vendor/toolkit/twitter/bootstrap/list-group.less +0 -130
- data/vendor/toolkit/twitter/bootstrap/media.less +0 -66
- data/vendor/toolkit/twitter/bootstrap/mixins/alerts.less +0 -14
- data/vendor/toolkit/twitter/bootstrap/mixins/background-variant.less +0 -9
- data/vendor/toolkit/twitter/bootstrap/mixins/border-radius.less +0 -18
- data/vendor/toolkit/twitter/bootstrap/mixins/buttons.less +0 -65
- data/vendor/toolkit/twitter/bootstrap/mixins/center-block.less +0 -7
- data/vendor/toolkit/twitter/bootstrap/mixins/clearfix.less +0 -22
- data/vendor/toolkit/twitter/bootstrap/mixins/forms.less +0 -85
- data/vendor/toolkit/twitter/bootstrap/mixins/gradients.less +0 -59
- data/vendor/toolkit/twitter/bootstrap/mixins/grid-framework.less +0 -91
- data/vendor/toolkit/twitter/bootstrap/mixins/grid.less +0 -122
- data/vendor/toolkit/twitter/bootstrap/mixins/hide-text.less +0 -21
- data/vendor/toolkit/twitter/bootstrap/mixins/image.less +0 -33
- data/vendor/toolkit/twitter/bootstrap/mixins/labels.less +0 -12
- data/vendor/toolkit/twitter/bootstrap/mixins/list-group.less +0 -30
- data/vendor/toolkit/twitter/bootstrap/mixins/nav-divider.less +0 -10
- data/vendor/toolkit/twitter/bootstrap/mixins/nav-vertical-align.less +0 -9
- data/vendor/toolkit/twitter/bootstrap/mixins/opacity.less +0 -8
- data/vendor/toolkit/twitter/bootstrap/mixins/pagination.less +0 -24
- data/vendor/toolkit/twitter/bootstrap/mixins/panels.less +0 -24
- data/vendor/toolkit/twitter/bootstrap/mixins/progress-bar.less +0 -10
- data/vendor/toolkit/twitter/bootstrap/mixins/reset-filter.less +0 -8
- data/vendor/toolkit/twitter/bootstrap/mixins/reset-text.less +0 -18
- data/vendor/toolkit/twitter/bootstrap/mixins/resize.less +0 -6
- data/vendor/toolkit/twitter/bootstrap/mixins/responsive-visibility.less +0 -15
- data/vendor/toolkit/twitter/bootstrap/mixins/size.less +0 -10
- data/vendor/toolkit/twitter/bootstrap/mixins/tab-focus.less +0 -9
- data/vendor/toolkit/twitter/bootstrap/mixins/table-row.less +0 -28
- data/vendor/toolkit/twitter/bootstrap/mixins/text-emphasis.less +0 -9
- data/vendor/toolkit/twitter/bootstrap/mixins/text-overflow.less +0 -8
- data/vendor/toolkit/twitter/bootstrap/mixins/vendor-prefixes.less +0 -227
- data/vendor/toolkit/twitter/bootstrap/mixins.less +0 -40
- data/vendor/toolkit/twitter/bootstrap/modals.less +0 -150
- data/vendor/toolkit/twitter/bootstrap/navbar.less +0 -660
- data/vendor/toolkit/twitter/bootstrap/navs.less +0 -242
- data/vendor/toolkit/twitter/bootstrap/normalize.less +0 -424
- data/vendor/toolkit/twitter/bootstrap/pager.less +0 -54
- data/vendor/toolkit/twitter/bootstrap/pagination.less +0 -89
- data/vendor/toolkit/twitter/bootstrap/panels.less +0 -271
- data/vendor/toolkit/twitter/bootstrap/popovers.less +0 -131
- data/vendor/toolkit/twitter/bootstrap/print.less +0 -101
- data/vendor/toolkit/twitter/bootstrap/progress-bars.less +0 -87
- data/vendor/toolkit/twitter/bootstrap/responsive-embed.less +0 -35
- data/vendor/toolkit/twitter/bootstrap/responsive-utilities.less +0 -194
- data/vendor/toolkit/twitter/bootstrap/scaffolding.less +0 -161
- data/vendor/toolkit/twitter/bootstrap/tables.less +0 -234
- data/vendor/toolkit/twitter/bootstrap/theme.less +0 -291
- data/vendor/toolkit/twitter/bootstrap/thumbnails.less +0 -36
- data/vendor/toolkit/twitter/bootstrap/tooltip.less +0 -101
- data/vendor/toolkit/twitter/bootstrap/type.less +0 -302
- data/vendor/toolkit/twitter/bootstrap/utilities.less +0 -55
- data/vendor/toolkit/twitter/bootstrap/variables.less +0 -1751
- data/vendor/toolkit/twitter/bootstrap/wells.less +0 -29
- data/vendor/toolkit/twitter/bootstrap_base.less +0 -2
|
@@ -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,42 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bootstrap::Generators::CdnGenerator do
|
|
4
|
+
let(:cdn) { Twitter::Bootstrap::Rails::BOOTSTRAP_CDN }
|
|
5
|
+
|
|
6
|
+
it "prints the stylesheet link and the JS bundle by default" do
|
|
7
|
+
output = run_generator(described_class)
|
|
8
|
+
|
|
9
|
+
expect(output).to include(cdn[:css][:url])
|
|
10
|
+
expect(output).to include(cdn[:css][:integrity])
|
|
11
|
+
expect(output).to include(cdn[:bundle][:url])
|
|
12
|
+
expect(output).to include(cdn[:bundle][:integrity])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "prints only the stylesheet link with --css" do
|
|
16
|
+
output = run_generator(described_class, %w[--css])
|
|
17
|
+
|
|
18
|
+
expect(output).to include(cdn[:css][:url])
|
|
19
|
+
expect(output).not_to include(cdn[:bundle][:url])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "prints only the bundle script with --js" do
|
|
23
|
+
output = run_generator(described_class, %w[--js])
|
|
24
|
+
|
|
25
|
+
expect(output).to include(cdn[:bundle][:url])
|
|
26
|
+
expect(output).not_to include(cdn[:css][:url])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "prints the Popper pair with --separate-popper" do
|
|
30
|
+
output = run_generator(described_class, %w[--separate-popper])
|
|
31
|
+
|
|
32
|
+
expect(output).to include(cdn[:popper][:url])
|
|
33
|
+
expect(output).to include(cdn[:js][:url])
|
|
34
|
+
expect(output).not_to include(cdn[:bundle][:url])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "writes nothing to disk" do
|
|
38
|
+
run_generator(described_class)
|
|
39
|
+
|
|
40
|
+
expect(Dir.children(destination_root)).to be_empty
|
|
41
|
+
end
|
|
42
|
+
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
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bootstrap::Generators::InstallGenerator do
|
|
4
|
+
let(:vendored_css) { 'app/assets/stylesheets/twitter/bootstrap/bootstrap.min.css' }
|
|
5
|
+
let(:vendored_js) { 'app/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js' }
|
|
6
|
+
|
|
7
|
+
describe "static (the default)" do
|
|
8
|
+
it "vendors both Bootstrap dist files into the app" do
|
|
9
|
+
run_generator(described_class, %w[static])
|
|
10
|
+
|
|
11
|
+
expect(destination_exist?(vendored_css)).to be true
|
|
12
|
+
expect(destination_exist?(vendored_js)).to be true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "vendors the Bootstrap version this gem declares" do
|
|
16
|
+
run_generator(described_class, %w[static])
|
|
17
|
+
|
|
18
|
+
expect(read_destination(vendored_css)).to include("Bootstrap v#{Twitter::Bootstrap::Rails::BOOTSTRAP_VERSION}")
|
|
19
|
+
expect(read_destination(vendored_js)).to include("Bootstrap v#{Twitter::Bootstrap::Rails::BOOTSTRAP_VERSION}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "defaults to static when no mode is given" do
|
|
23
|
+
run_generator(described_class)
|
|
24
|
+
|
|
25
|
+
expect(destination_exist?(vendored_css)).to be true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "writes manifests that require the vendored files" do
|
|
29
|
+
run_generator(described_class, %w[static])
|
|
30
|
+
|
|
31
|
+
expect(read_destination('app/assets/javascripts/application.js'))
|
|
32
|
+
.to include("//= require twitter/bootstrap/bootstrap.bundle.min")
|
|
33
|
+
expect(read_destination('app/assets/stylesheets/bootstrap_and_overrides.css'))
|
|
34
|
+
.to include("*= require twitter/bootstrap/bootstrap.min")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "adds the require lines to manifests the app already has" do
|
|
38
|
+
write_destination('app/assets/javascripts/application.js', "// application\n//= require_tree .\n")
|
|
39
|
+
write_destination('app/assets/stylesheets/application.css', "/*\n *= require_self\n *= require_tree .\n*/\n")
|
|
40
|
+
|
|
41
|
+
run_generator(described_class, %w[static])
|
|
42
|
+
|
|
43
|
+
expect(read_destination('app/assets/javascripts/application.js'))
|
|
44
|
+
.to include("//= require twitter/bootstrap/bootstrap.bundle.min")
|
|
45
|
+
expect(read_destination('app/assets/stylesheets/application.css'))
|
|
46
|
+
.to include("*= require bootstrap_and_overrides")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "says what to add by hand when a manifest has no Sprockets anchor" do
|
|
50
|
+
# A Propshaft app's application.css is plain CSS with nothing to anchor to.
|
|
51
|
+
write_destination('app/assets/stylesheets/application.css', "/*\n * Propshaft manifest.\n */\n")
|
|
52
|
+
|
|
53
|
+
output = run_generator(described_class, %w[static])
|
|
54
|
+
|
|
55
|
+
expect(output).to match(/has no `require_self` directive to anchor to/)
|
|
56
|
+
expect(output).to include("*= require bootstrap_and_overrides")
|
|
57
|
+
expect(read_destination('app/assets/stylesheets/application.css')).not_to include("require bootstrap_and_overrides")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "does not duplicate require lines when run twice" do
|
|
61
|
+
run_generator(described_class, %w[static])
|
|
62
|
+
run_generator(described_class, %w[static])
|
|
63
|
+
|
|
64
|
+
js = read_destination('app/assets/javascripts/application.js')
|
|
65
|
+
expect(js.scan("require twitter/bootstrap/bootstrap.bundle.min").length).to eq(1)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "writes no CDN initializer" do
|
|
69
|
+
run_generator(described_class, %w[static])
|
|
70
|
+
|
|
71
|
+
expect(destination_exist?('config/initializers/bootstrap.rb')).to be false
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "raises rather than silently installing nothing when a dist file is missing" do
|
|
75
|
+
allow(File).to receive(:file?).and_call_original
|
|
76
|
+
allow(File).to receive(:file?).with(/bootstrap\.min\.css\z/).and_return(false)
|
|
77
|
+
|
|
78
|
+
expect {
|
|
79
|
+
run_generator(described_class, %w[static])
|
|
80
|
+
}.to raise_error(described_class::MissingAssetError, /bootstrap\.min\.css/)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Propshaft is the Rails 8 default and has no Sprockets directives: a
|
|
85
|
+
# `//= require` line there is an inert comment, so writing manifests that rely
|
|
86
|
+
# on one would ship an app with no Bootstrap at all.
|
|
87
|
+
describe "static on a Propshaft app" do
|
|
88
|
+
before { Twitter::Bootstrap::Rails.asset_pipeline = :propshaft }
|
|
89
|
+
|
|
90
|
+
it "still vendors both dist files" do
|
|
91
|
+
run_generator(described_class, %w[static])
|
|
92
|
+
|
|
93
|
+
expect(destination_exist?(vendored_css)).to be true
|
|
94
|
+
expect(destination_exist?(vendored_js)).to be true
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "writes no Sprockets manifests" do
|
|
98
|
+
run_generator(described_class, %w[static])
|
|
99
|
+
|
|
100
|
+
expect(destination_exist?('app/assets/javascripts/application.js')).to be false
|
|
101
|
+
expect(destination_exist?('app/assets/stylesheets/bootstrap_and_overrides.css')).to be false
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "does not touch an existing application.css" do
|
|
105
|
+
original = "/*\n * Propshaft manifest.\n */\n"
|
|
106
|
+
write_destination('app/assets/stylesheets/application.css', original)
|
|
107
|
+
|
|
108
|
+
run_generator(described_class, %w[static])
|
|
109
|
+
|
|
110
|
+
expect(read_destination('app/assets/stylesheets/application.css')).to eq(original)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "points the user at bootstrap:layout" do
|
|
114
|
+
output = run_generator(described_class, %w[static])
|
|
115
|
+
|
|
116
|
+
expect(output).to match(/vendored for Propshaft/)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe "cdn" do
|
|
121
|
+
it "vendors nothing" do
|
|
122
|
+
run_generator(described_class, %w[cdn])
|
|
123
|
+
|
|
124
|
+
expect(destination_exist?(vendored_css)).to be false
|
|
125
|
+
expect(destination_exist?(vendored_js)).to be false
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "writes an initializer selecting cdn mode" do
|
|
129
|
+
run_generator(described_class, %w[cdn])
|
|
130
|
+
|
|
131
|
+
expect(read_destination('config/initializers/bootstrap.rb'))
|
|
132
|
+
.to include("Twitter::Bootstrap::Rails.asset_mode = :cdn")
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "creates no asset manifests" do
|
|
136
|
+
run_generator(described_class, %w[cdn])
|
|
137
|
+
|
|
138
|
+
expect(destination_exist?('app/assets/javascripts/application.js')).to be false
|
|
139
|
+
expect(destination_exist?('app/assets/stylesheets/bootstrap_and_overrides.css')).to be false
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "rejects an unknown mode" do
|
|
144
|
+
expect {
|
|
145
|
+
run_generator(described_class, %w[less])
|
|
146
|
+
}.to raise_error(Rails::Generators::Error, /Expected 'static' or 'cdn'/)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Bootstrap::Generators::LayoutGenerator do
|
|
4
|
+
let(:cdn) { Twitter::Bootstrap::Rails::BOOTSTRAP_CDN }
|
|
5
|
+
|
|
6
|
+
# The generated layout for the given engine.
|
|
7
|
+
def generate_layout(args = [], engine: :erb)
|
|
8
|
+
stub_rails_application(engine)
|
|
9
|
+
run_generator(described_class, args)
|
|
10
|
+
read_destination("app/views/layouts/application.html.#{engine}")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
[:erb, :haml, :slim].each do |engine|
|
|
14
|
+
context "with the #{engine} template engine" do
|
|
15
|
+
it "uses the asset pipeline by default" do
|
|
16
|
+
layout = generate_layout([], :engine => engine)
|
|
17
|
+
|
|
18
|
+
expect(layout).to include('stylesheet_link_tag "application"')
|
|
19
|
+
expect(layout).to include('javascript_include_tag "application"')
|
|
20
|
+
expect(layout).not_to include("cdn.jsdelivr.net")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "emits the CDN link and bundle with --cdn" do
|
|
24
|
+
layout = generate_layout(%w[--cdn], :engine => engine)
|
|
25
|
+
|
|
26
|
+
expect(layout).to include(cdn[:css][:url])
|
|
27
|
+
expect(layout).to include(cdn[:css][:integrity])
|
|
28
|
+
expect(layout).to include(cdn[:bundle][:url])
|
|
29
|
+
expect(layout).to include(cdn[:bundle][:integrity])
|
|
30
|
+
expect(layout).to include('crossorigin="anonymous"')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "does not also link the pipeline when using --cdn" do
|
|
34
|
+
layout = generate_layout(%w[--cdn], :engine => engine)
|
|
35
|
+
|
|
36
|
+
expect(layout).not_to include('stylesheet_link_tag')
|
|
37
|
+
expect(layout).not_to include('javascript_include_tag')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "emits Popper and bootstrap.js instead of the bundle with --cdn --separate-popper" do
|
|
41
|
+
layout = generate_layout(%w[--cdn --separate-popper], :engine => engine)
|
|
42
|
+
|
|
43
|
+
expect(layout).to include(cdn[:popper][:url])
|
|
44
|
+
expect(layout).to include(cdn[:popper][:integrity])
|
|
45
|
+
expect(layout).to include(cdn[:js][:url])
|
|
46
|
+
expect(layout).to include(cdn[:js][:integrity])
|
|
47
|
+
expect(layout).not_to include(cdn[:bundle][:url])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "includes the important globals: doctype, html lang, and viewport" do
|
|
51
|
+
layout = generate_layout([], :engine => engine)
|
|
52
|
+
|
|
53
|
+
expect(layout).to match(/\A(<!doctype html>|!!!|doctype html)/)
|
|
54
|
+
expect(layout).to match(/lang[^\n]*en/)
|
|
55
|
+
expect(layout).to include("width=device-width, initial-scale=1")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "carries no Bootstrap 3 markup" do
|
|
59
|
+
layout = generate_layout([], :engine => engine)
|
|
60
|
+
|
|
61
|
+
expect(layout).not_to include("navbar-default")
|
|
62
|
+
expect(layout).not_to include("icon-bar")
|
|
63
|
+
expect(layout).not_to include("html5shiv")
|
|
64
|
+
expect(layout).not_to match(/\bwell\b/)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "on a Propshaft app" do
|
|
70
|
+
before { Twitter::Bootstrap::Rails.asset_pipeline = :propshaft }
|
|
71
|
+
|
|
72
|
+
[:erb, :haml, :slim].each do |engine|
|
|
73
|
+
it "links the vendored Bootstrap explicitly in #{engine}, since require directives are inert" do
|
|
74
|
+
layout = generate_layout([], :engine => engine)
|
|
75
|
+
|
|
76
|
+
expect(layout).to include('stylesheet_link_tag "twitter/bootstrap/bootstrap.min", "application"')
|
|
77
|
+
expect(layout).to include('javascript_include_tag "twitter/bootstrap/bootstrap.bundle.min"')
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "does not link an application.js that Propshaft apps do not have" do
|
|
82
|
+
layout = generate_layout
|
|
83
|
+
|
|
84
|
+
expect(layout).not_to include('javascript_include_tag "twitter/bootstrap/bootstrap.bundle.min", "application"')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "still uses the CDN when asked" do
|
|
88
|
+
layout = generate_layout(%w[--cdn])
|
|
89
|
+
|
|
90
|
+
expect(layout).to include(cdn[:css][:url])
|
|
91
|
+
expect(layout).not_to include('stylesheet_link_tag')
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "names the layout after the given argument" do
|
|
96
|
+
stub_rails_application(:erb)
|
|
97
|
+
run_generator(described_class, %w[admin])
|
|
98
|
+
|
|
99
|
+
expect(destination_exist?("app/views/layouts/admin.html.erb")).to be true
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "warns and falls back to the bundle when --separate-popper is used without --cdn" do
|
|
103
|
+
stub_rails_application(:erb)
|
|
104
|
+
output = run_generator(described_class, %w[--separate-popper])
|
|
105
|
+
|
|
106
|
+
expect(output).to match(/separate-popper only applies with --cdn/)
|
|
107
|
+
expect(read_destination("app/views/layouts/application.html.erb")).not_to include(cdn[:popper][:url])
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "defaults to CDN tags when bootstrap:install recorded cdn mode" do
|
|
111
|
+
Twitter::Bootstrap::Rails.asset_mode = :cdn
|
|
112
|
+
layout = generate_layout
|
|
113
|
+
|
|
114
|
+
expect(layout).to include(cdn[:css][:url])
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "lets --no-cdn override a recorded cdn mode" do
|
|
118
|
+
Twitter::Bootstrap::Rails.asset_mode = :cdn
|
|
119
|
+
layout = generate_layout(%w[--no-cdn])
|
|
120
|
+
|
|
121
|
+
expect(layout).to include('stylesheet_link_tag "application"')
|
|
122
|
+
expect(layout).not_to include("cdn.jsdelivr.net")
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# Bumping Bootstrap should be a one-file change. If a template hardcodes a CDN
|
|
4
|
+
# URL or an integrity hash, that promise quietly breaks.
|
|
5
|
+
describe "generator templates" do
|
|
6
|
+
gem_root = File.expand_path("../../../..", __FILE__)
|
|
7
|
+
|
|
8
|
+
let(:template_files) do
|
|
9
|
+
Dir[File.join(gem_root, "lib/generators/**/templates/**/*")].select { |f| File.file?(f) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "has templates to check" do
|
|
13
|
+
expect(template_files).not_to be_empty
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "hardcodes no Bootstrap CDN version" do
|
|
17
|
+
offenders = template_files.select { |f| File.read(f).include?("bootstrap@") }
|
|
18
|
+
|
|
19
|
+
expect(offenders).to be_empty,
|
|
20
|
+
"these templates hardcode a CDN version instead of using the constants: #{offenders.inspect}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "hardcodes no Subresource Integrity hash" do
|
|
24
|
+
offenders = template_files.select { |f| File.read(f).match?(/sha384-/) }
|
|
25
|
+
|
|
26
|
+
expect(offenders).to be_empty,
|
|
27
|
+
"these templates hardcode an integrity hash instead of using the constants: #{offenders.inspect}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "keeps the vendored assets on the version the gem declares" do
|
|
31
|
+
version = Twitter::Bootstrap::Rails::BOOTSTRAP_VERSION
|
|
32
|
+
|
|
33
|
+
{
|
|
34
|
+
"vendor/assets/stylesheets/twitter/bootstrap/bootstrap.min.css" => "Bootstrap v#{version}",
|
|
35
|
+
"vendor/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js" => "Bootstrap v#{version}",
|
|
36
|
+
"app/assets/stylesheets/twitter-bootstrap-static/bootstrap.css" => "Bootstrap v#{version}",
|
|
37
|
+
"app/assets/javascripts/twitter/bootstrap/bootstrap.min.js" => "Bootstrap v#{version}"
|
|
38
|
+
}.each do |path, banner|
|
|
39
|
+
full = File.join(gem_root, path)
|
|
40
|
+
expect(File.exist?(full)).to be(true), "missing vendored asset #{path}"
|
|
41
|
+
expect(File.read(full, 400)).to include(banner),
|
|
42
|
+
"#{path} is not Bootstrap #{version}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|