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,61 @@
|
|
|
1
|
+
# Bootstrap in this app
|
|
2
|
+
|
|
3
|
+
This app uses Bootstrap <%= facts[:bootstrap_version] %> through the twitter-bootstrap-rails gem (<%= facts[:gem_version] %>). Prefer the gem's generators and helpers over writing Bootstrap markup from memory, which is often out of date.
|
|
4
|
+
|
|
5
|
+
This guide is generated. Run `rails g bootstrap:agent` again after upgrading the gem or changing the asset setup.
|
|
6
|
+
|
|
7
|
+
## This app
|
|
8
|
+
|
|
9
|
+
- Asset pipeline: <%= pipeline_note %>
|
|
10
|
+
- Bootstrap assets: <%= facts[:asset_mode] %>
|
|
11
|
+
- Template engine: <%= facts[:template_engine] %>
|
|
12
|
+
|
|
13
|
+
## Workflow
|
|
14
|
+
|
|
15
|
+
1. Run `rails g bootstrap:doctor --json` to see the app's current state. It writes nothing, and it exits 1 if a check reports an error.
|
|
16
|
+
2. Find a snippet with `rails g bootstrap:<name> --json`, which lists the variants and what each one needs.
|
|
17
|
+
3. Preview with `--pretend`, then run `rails g bootstrap:<name> <variant>`. Use `--as=NAME` and `--path=DIR` to choose where the partial goes.
|
|
18
|
+
4. Add the `render` call the generator prints. If it mentions the icon sprite, render that once, near the top of `<body>` in the layout.
|
|
19
|
+
5. If the generator warns about placeholder images, replace them with the app's own.
|
|
20
|
+
6. Run `rails g bootstrap:doctor --json` again and fix any errors.
|
|
21
|
+
|
|
22
|
+
Generators stop and ask before overwriting a file. Pass `--force` to overwrite or `--skip` to keep the existing file.
|
|
23
|
+
|
|
24
|
+
Snippets are always written as ERB partials. They render from any template engine.
|
|
25
|
+
|
|
26
|
+
## Snippets
|
|
27
|
+
|
|
28
|
+
| Generator | Variants (the first is the default) |
|
|
29
|
+
|---|---|
|
|
30
|
+
<% catalog::GENERATORS.each do |generator, category| -%>
|
|
31
|
+
| `bootstrap:<%= generator %>` | <%= catalog.variant_names(category).join(", ") %> |
|
|
32
|
+
<% end -%>
|
|
33
|
+
|
|
34
|
+
## Other generators
|
|
35
|
+
|
|
36
|
+
- `bootstrap:install static` or `bootstrap:install cdn`: sets up Bootstrap's assets.
|
|
37
|
+
- `bootstrap:layout [NAME]`: writes a layout that loads Bootstrap. Don't overwrite an existing layout without checking its contents first.
|
|
38
|
+
- `bootstrap:themed RESOURCE`: writes Bootstrap views for a scaffold.
|
|
39
|
+
- `bootstrap:cdn`: prints the CDN tags and writes nothing.
|
|
40
|
+
|
|
41
|
+
## View helpers
|
|
42
|
+
|
|
43
|
+
- Navigation: `nav_bar`, `menu_group`, `menu_item`, `menu_text`, `menu_divider`, `drop_down`, `drop_down_divider`, `drop_down_header`
|
|
44
|
+
- Messages: `bootstrap_flash`, `flash_block`
|
|
45
|
+
- Modals: `modal_dialog`, `modal_toggle`, `modal_cancel_button`
|
|
46
|
+
- Other: `badge`, `tag_label`, `render_breadcrumbs`, `add_breadcrumb`, and `error_span` on form builders
|
|
47
|
+
|
|
48
|
+
## Markup to avoid
|
|
49
|
+
|
|
50
|
+
These come from older Bootstrap versions and do nothing on this one. `bootstrap:doctor` reports them, with file and line, under `legacy_markup`. Plain names like `close` or `well` may be the app's own CSS classes, so check those before changing them.
|
|
51
|
+
|
|
52
|
+
Data attributes: <%= legacy::DATA_ATTRIBUTES.map { |name| "`data-#{name}`" }.join(", ") %> become `data-bs-*`.
|
|
53
|
+
|
|
54
|
+
| Old class | Use instead |
|
|
55
|
+
|---|---|
|
|
56
|
+
<% legacy::CLASSES.each do |old, replacement| -%>
|
|
57
|
+
| `<%= old %>` | <%= replacement %> |
|
|
58
|
+
<% end -%>
|
|
59
|
+
<% legacy::CLASS_PATTERNS.each do |_pattern, _replacement, example| -%>
|
|
60
|
+
| <%= example.split(" become").first %> | <%= example.split(/ becomes? /).last %> |
|
|
61
|
+
<% end -%>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'rails/generators'
|
|
3
|
+
require 'twitter/bootstrap/rails/doctor'
|
|
4
|
+
|
|
5
|
+
module Bootstrap
|
|
6
|
+
module Generators
|
|
7
|
+
# A generator rather than a rake task because rake rejects flags like --json.
|
|
8
|
+
# Writes nothing. Exits 1 if any check reports an error.
|
|
9
|
+
class DoctorGenerator < ::Rails::Generators::Base
|
|
10
|
+
desc "Checks how Bootstrap is set up in this app and finds markup from older Bootstrap versions"
|
|
11
|
+
|
|
12
|
+
class_option :json, :type => :boolean, :default => false,
|
|
13
|
+
:desc => 'Print the report as JSON'
|
|
14
|
+
|
|
15
|
+
def diagnose
|
|
16
|
+
report = Twitter::Bootstrap::Rails::Doctor.new(destination_root).report
|
|
17
|
+
|
|
18
|
+
options[:json] ? say(JSON.pretty_generate(report)) : print_report(report)
|
|
19
|
+
exit(1) if report[:status] == "error"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def print_report(report)
|
|
25
|
+
say "Bootstrap #{report[:bootstrap_version]} on Rails #{report[:rails_version]} " \
|
|
26
|
+
"(#{report[:asset_pipeline]}, #{report[:asset_mode]}, #{report[:template_engine]})\n"
|
|
27
|
+
|
|
28
|
+
report[:checks].each do |check|
|
|
29
|
+
say format("%-8s %-20s %s", "[#{check[:status]}]", check[:id], check[:message])
|
|
30
|
+
say " #{' ' * 20} Fix: #{check[:fix]}" if check[:fix]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
report[:legacy_markup].each do |finding|
|
|
34
|
+
say " #{finding[:file]}:#{finding[:line]} #{finding[:found]} -> #{finding[:replacement]}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
<h2>Sign in</h2>
|
|
2
2
|
|
|
3
|
-
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)
|
|
4
|
-
<div class="
|
|
5
|
-
<%= f.label :email, :class => '
|
|
6
|
-
|
|
7
|
-
<%= f.email_field :email %>
|
|
8
|
-
</div>
|
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
|
4
|
+
<div class="mb-3">
|
|
5
|
+
<%= f.label :email, :class => 'form-label' %>
|
|
6
|
+
<%= f.email_field :email, :class => 'form-control' %>
|
|
9
7
|
</div>
|
|
10
|
-
<div class="
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<%= f.password_field :password %>
|
|
14
|
-
</div>
|
|
8
|
+
<div class="mb-3">
|
|
9
|
+
<%= f.label :password, :class => 'form-label' %>
|
|
10
|
+
<%= f.password_field :password, :class => 'form-control' %>
|
|
15
11
|
</div>
|
|
16
12
|
|
|
17
13
|
<% if devise_mapping.rememberable? -%>
|
|
18
|
-
<div class=
|
|
19
|
-
<%= f.
|
|
20
|
-
<%= f.
|
|
14
|
+
<div class="mb-3 form-check">
|
|
15
|
+
<%= f.check_box :remember_me, :class => 'form-check-input' %>
|
|
16
|
+
<%= f.label :remember_me, :class => 'form-check-label' %>
|
|
21
17
|
</div>
|
|
22
18
|
<% end -%>
|
|
23
19
|
|
|
24
|
-
<%= f.submit "Sign in", :class => 'btn btn-
|
|
20
|
+
<%= f.submit "Sign in", :class => 'btn btn-primary' %>
|
|
25
21
|
|
|
26
22
|
<% end %>
|
|
27
23
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'json'
|
|
1
2
|
require 'rails/generators'
|
|
2
3
|
require 'twitter/bootstrap/rails/version'
|
|
3
4
|
require 'generators/bootstrap/snippets/snippet_catalog'
|
|
@@ -19,6 +20,8 @@ module Bootstrap
|
|
|
19
20
|
:desc => 'Directory to write the partial into'
|
|
20
21
|
class_option :list, :type => :boolean, :default => false,
|
|
21
22
|
:desc => 'List the available variants and exit'
|
|
23
|
+
class_option :json, :type => :boolean, :default => false,
|
|
24
|
+
:desc => 'List the available variants as JSON and exit'
|
|
22
25
|
class_option :icons, :type => :boolean, :default => true,
|
|
23
26
|
:desc => 'Also install the shared Bootstrap Icons sprite when the snippet needs it'
|
|
24
27
|
|
|
@@ -37,7 +40,8 @@ module Bootstrap
|
|
|
37
40
|
end
|
|
38
41
|
|
|
39
42
|
def list_variants
|
|
40
|
-
return unless
|
|
43
|
+
return unless listing?
|
|
44
|
+
return say(JSON.pretty_generate(catalog_listing)) if options[:json]
|
|
41
45
|
|
|
42
46
|
say "#{category} variants:\n\n"
|
|
43
47
|
SnippetCatalog.variants(category).each do |v|
|
|
@@ -47,13 +51,13 @@ module Bootstrap
|
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
def copy_snippet
|
|
50
|
-
return if
|
|
54
|
+
return if listing?
|
|
51
55
|
|
|
52
56
|
copy_file "#{category}/#{variant_name}.html.erb", partial_path
|
|
53
57
|
end
|
|
54
58
|
|
|
55
59
|
def copy_icons
|
|
56
|
-
return if
|
|
60
|
+
return if listing?
|
|
57
61
|
return unless variant[:icons] && options[:icons]
|
|
58
62
|
|
|
59
63
|
copy_file "icons/_#{ICONS_PARTIAL}.html.erb",
|
|
@@ -61,7 +65,7 @@ module Bootstrap
|
|
|
61
65
|
end
|
|
62
66
|
|
|
63
67
|
def report
|
|
64
|
-
return if
|
|
68
|
+
return if listing?
|
|
65
69
|
|
|
66
70
|
say "\nRender it with: <%= render \"#{render_path}\" %>"
|
|
67
71
|
if variant[:icons] && options[:icons]
|
|
@@ -78,6 +82,21 @@ module Bootstrap
|
|
|
78
82
|
|
|
79
83
|
private
|
|
80
84
|
|
|
85
|
+
def listing?
|
|
86
|
+
options[:list] || options[:json]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def catalog_listing
|
|
90
|
+
{
|
|
91
|
+
:generator => self.class.namespace,
|
|
92
|
+
:category => category,
|
|
93
|
+
:default => SnippetCatalog.default_variant(category),
|
|
94
|
+
:variants => SnippetCatalog.variants(category).map do |v|
|
|
95
|
+
v.merge(:command => "rails g #{self.class.namespace} #{v[:name]}")
|
|
96
|
+
end
|
|
97
|
+
}
|
|
98
|
+
end
|
|
99
|
+
|
|
81
100
|
def category
|
|
82
101
|
self.class.snippet_category
|
|
83
102
|
end
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
= form_for @<%= resource_name %>, html: { class: "
|
|
1
|
+
= form_for @<%= resource_name %>, html: { class: "<%= resource_name %>" } do |f|
|
|
2
2
|
<%- columns.each do |column| -%>
|
|
3
|
-
.
|
|
4
|
-
= f.label :<%= column.name %>, class: '
|
|
5
|
-
.
|
|
6
|
-
= f.<%= column.field_type %> :<%= column.name %>, class: 'form-control', required: true
|
|
3
|
+
.mb-3
|
|
4
|
+
= f.label :<%= column.name %>, class: 'form-label'
|
|
5
|
+
= f.<%= column.field_type %> :<%= column.name %>, class: 'form-control', required: true
|
|
7
6
|
= f.error_span(:<%= column.name %>)
|
|
8
7
|
<%- end -%>
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-default'
|
|
8
|
+
.mb-3
|
|
9
|
+
= f.submit nil, class: 'btn btn-primary'
|
|
10
|
+
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-secondary'
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
= form_for @<%= resource_name %>, html: { class: "
|
|
1
|
+
= form_for @<%= resource_name %>, html: { class: "<%= resource_name %>" } do |f|
|
|
2
2
|
<%- columns.each do |column| -%>
|
|
3
|
-
.
|
|
4
|
-
= f.label :<%= column.name %>, :class => '
|
|
5
|
-
.
|
|
6
|
-
= f.<%= column.field_type %> :<%= column.name %>, :class => 'form-control'
|
|
3
|
+
.mb-3
|
|
4
|
+
= f.label :<%= column.name %>, :class => 'form-label'
|
|
5
|
+
= f.<%= column.field_type %> :<%= column.name %>, :class => 'form-control'
|
|
7
6
|
= f.error_span(:<%= column.name %>)
|
|
8
7
|
<%- end -%>
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn'
|
|
8
|
+
.mb-3
|
|
9
|
+
= f.submit nil, :class => 'btn btn-primary'
|
|
10
|
+
'
|
|
11
|
+
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-secondary'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%%- model_class = <%= resource_name.classify %> -%>
|
|
2
|
-
<div class="
|
|
2
|
+
<div class="border-bottom pb-2 mb-4">
|
|
3
3
|
<h1><%%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human.titleize %></h1>
|
|
4
4
|
</div>
|
|
5
5
|
<%%= render :partial => 'form' %>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
- model_class = <%= resource_name.classify %>
|
|
2
|
-
.
|
|
2
|
+
.border-bottom.pb-2.mb-4
|
|
3
3
|
%h1=t '.title', :default => model_class.model_name.human.pluralize.titleize
|
|
4
4
|
%table.table.table-striped
|
|
5
5
|
%thead
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
<%- end -%>
|
|
20
20
|
%td=l <%= resource_name %>.created_at
|
|
21
21
|
%td
|
|
22
|
-
= link_to t('.show', :default => t("helpers.links.show")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-
|
|
23
|
-
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-
|
|
24
|
-
= link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-
|
|
22
|
+
= link_to t('.show', :default => t("helpers.links.show")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-sm btn-secondary'
|
|
23
|
+
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-sm btn-secondary'
|
|
24
|
+
= link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-sm btn-danger'
|
|
25
25
|
|
|
26
26
|
= link_to t('.new', :default => t("helpers.links.new")), new_<%= singular_controller_routing_path %>_path, :class => 'btn btn-primary'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
- model_class = <%= resource_name.classify %>
|
|
2
|
-
.
|
|
2
|
+
.border-bottom.pb-2.mb-4
|
|
3
3
|
h1=t '.title', :default => model_class.model_name.human.pluralize.titleize
|
|
4
4
|
table.table.table-striped
|
|
5
5
|
thead
|
|
@@ -19,10 +19,10 @@ table.table.table-striped
|
|
|
19
19
|
<%- end -%>
|
|
20
20
|
td=l <%= resource_name %>.created_at
|
|
21
21
|
td
|
|
22
|
-
= link_to t('.show', :default => t("helpers.links.show")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-
|
|
22
|
+
= link_to t('.show', :default => t("helpers.links.show")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-sm btn-secondary'
|
|
23
23
|
'
|
|
24
|
-
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-
|
|
24
|
+
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-sm btn-secondary'
|
|
25
25
|
'
|
|
26
|
-
= link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-
|
|
26
|
+
= link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-sm btn-danger'
|
|
27
27
|
|
|
28
28
|
= link_to t('.new', :default => t("helpers.links.new")), new_<%= singular_controller_routing_path %>_path, :class => 'btn btn-primary'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%%- model_class = <%= resource_name.classify %> -%>
|
|
2
|
-
<div class="
|
|
2
|
+
<div class="border-bottom pb-2 mb-4">
|
|
3
3
|
<h1><%%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize %></h1>
|
|
4
4
|
</div>
|
|
5
5
|
<%%= render :partial => 'form' %>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
- model_class = <%= resource_name.classify %>
|
|
2
|
-
.
|
|
2
|
+
.border-bottom.pb-2.mb-4
|
|
3
3
|
%h1=t '.title', :default => model_class.model_name.human.titleize
|
|
4
4
|
|
|
5
5
|
<%- columns.each do |column| -%>
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
<%- end -%>
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
= link_to t('.back', :default => t("helpers.links.back")), <%= controller_routing_path %>_path, :class => 'btn btn-
|
|
14
|
-
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn btn-
|
|
13
|
+
= link_to t('.back', :default => t("helpers.links.back")), <%= controller_routing_path %>_path, :class => 'btn btn-secondary'
|
|
14
|
+
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn btn-secondary'
|
|
15
15
|
= link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
- model_class = <%= resource_name.classify %>
|
|
2
|
-
.
|
|
2
|
+
.border-bottom.pb-2.mb-4
|
|
3
3
|
h1=t '.title', :default => model_class.model_name.human.titleize
|
|
4
4
|
|
|
5
5
|
<%- columns.each do |column| -%>
|
|
@@ -9,8 +9,8 @@ p
|
|
|
9
9
|
= @<%= resource_name %>.<%= column.name %>
|
|
10
10
|
<%- end -%>
|
|
11
11
|
|
|
12
|
-
= link_to t('.back', :default => t("helpers.links.back")), <%= controller_routing_path %>_path, :class => 'btn btn-
|
|
12
|
+
= link_to t('.back', :default => t("helpers.links.back")), <%= controller_routing_path %>_path, :class => 'btn btn-secondary'
|
|
13
13
|
'
|
|
14
|
-
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn btn-
|
|
14
|
+
= link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn btn-secondary'
|
|
15
15
|
'
|
|
16
16
|
= link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :method => "delete", :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, :class => 'btn btn-danger'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<%%= simple_form_for @<%= resource_name
|
|
1
|
+
<%%= simple_form_for @<%= resource_name %> do |f| %>
|
|
2
2
|
<%- columns.each do |column| -%>
|
|
3
3
|
<%%= f.input :<%= column.name %> %>
|
|
4
4
|
<%%= error_span(@<%= resource_name %>[:<%= column.name %>]) %>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
= simple_form_for @<%= resource_name
|
|
1
|
+
= simple_form_for @<%= resource_name %> do |f|
|
|
2
2
|
<%- columns.each do |column| -%>
|
|
3
3
|
= f.input :<%= column.name %>
|
|
4
4
|
= f.error_span :<%= column.name %>
|
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
= f.button :wrapped, :cancel => <%= controller_routing_path %>_path
|
|
8
8
|
<%- else -%>
|
|
9
9
|
= f.button :submit, :class => 'btn-primary'
|
|
10
|
-
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-
|
|
10
|
+
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-secondary'
|
|
11
11
|
<%- end -%>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
= simple_form_for @<%= resource_name
|
|
1
|
+
= simple_form_for @<%= resource_name %> do |f|
|
|
2
2
|
<%- columns.each do |column| -%>
|
|
3
3
|
= f.input :<%= column.name %>
|
|
4
4
|
= error_span(@<%= resource_name %>[:<%= column.name %>])
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<%- else -%>
|
|
9
9
|
= f.button :submit, :class => 'btn-primary'
|
|
10
10
|
'
|
|
11
|
-
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-
|
|
11
|
+
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn btn-secondary'
|
|
12
12
|
<%- end -%>
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
require 'twitter/bootstrap/rails/version'
|
|
2
|
+
require 'twitter/bootstrap/rails/config'
|
|
3
|
+
require 'twitter/bootstrap/rails/legacy_markup'
|
|
4
|
+
|
|
5
|
+
module Twitter
|
|
6
|
+
module Bootstrap
|
|
7
|
+
module Rails
|
|
8
|
+
# Inspects a host app and reports how Bootstrap is set up. Reads files only.
|
|
9
|
+
# Every check is { :id, :status, :message } plus :fix when there is one, and
|
|
10
|
+
# status is "ok", "warn" or "error".
|
|
11
|
+
class Doctor
|
|
12
|
+
VENDORED_CSS = "app/assets/stylesheets/twitter/bootstrap/bootstrap.min.css".freeze
|
|
13
|
+
VENDORED_JS = "app/assets/javascripts/twitter/bootstrap/bootstrap.bundle.min.js".freeze
|
|
14
|
+
SCANNED_EXTENSIONS = %w[.erb .haml .slim .rb].freeze
|
|
15
|
+
PLACEHOLDER_IMAGES = ["bootstrap-docs.png", "bootstrap-themes.png", "/docs/5.3/assets/", "unsplash-photo-"].freeze
|
|
16
|
+
SEVERITY = %w[ok warn error].freeze
|
|
17
|
+
|
|
18
|
+
def initialize(root)
|
|
19
|
+
@root = root
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def report
|
|
23
|
+
checks = [css_check, js_check, version_check, sprite_check, placeholder_check, legacy_check]
|
|
24
|
+
|
|
25
|
+
facts.merge(
|
|
26
|
+
:status => checks.map { |c| c[:status] }.max_by { |s| SEVERITY.index(s) },
|
|
27
|
+
:checks => checks,
|
|
28
|
+
:legacy_markup => legacy_markup
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def facts
|
|
33
|
+
{
|
|
34
|
+
:bootstrap_version => BOOTSTRAP_VERSION,
|
|
35
|
+
:gem_version => VERSION,
|
|
36
|
+
:rails_version => ::Rails.version,
|
|
37
|
+
:asset_pipeline => pipeline.to_s,
|
|
38
|
+
:asset_mode => asset_mode,
|
|
39
|
+
:template_engine => template_engine
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def pipeline
|
|
46
|
+
Twitter::Bootstrap::Rails.asset_pipeline
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def asset_mode
|
|
50
|
+
initializer = read("config/initializers/bootstrap.rb")
|
|
51
|
+
cdn = initializer.match?(/asset_mode\s*=\s*:cdn/) || layouts.match?(%r{cdn\.jsdelivr\.net/npm/bootstrap@})
|
|
52
|
+
cdn ? "cdn" : "static"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def template_engine
|
|
56
|
+
app = ::Rails.application
|
|
57
|
+
(app && app.config.generators.options.dig(:rails, :template_engine) || :erb).to_s
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def css_check
|
|
61
|
+
asset_check("bootstrap_css", "stylesheet",
|
|
62
|
+
:cdn => %r{bootstrap@[\d.]+/dist/css/bootstrap},
|
|
63
|
+
:vendored_name => "twitter/bootstrap/bootstrap.min",
|
|
64
|
+
:vendored_file => VENDORED_CSS,
|
|
65
|
+
:manifest => "app/assets/stylesheets/application.css",
|
|
66
|
+
:manifest_entry => %r{bootstrap_and_overrides|twitter/bootstrap|require_tree},
|
|
67
|
+
:layout_tag => /stylesheet_link_tag[^\n]*application/)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def js_check
|
|
71
|
+
asset_check("bootstrap_js", "JavaScript",
|
|
72
|
+
:cdn => %r{bootstrap@[\d.]+/dist/js/bootstrap},
|
|
73
|
+
:vendored_name => "twitter/bootstrap/bootstrap.bundle.min",
|
|
74
|
+
:vendored_file => VENDORED_JS,
|
|
75
|
+
:manifest => "app/assets/javascripts/application.js",
|
|
76
|
+
:manifest_entry => %r{twitter/bootstrap|require_tree},
|
|
77
|
+
:layout_tag => /javascript_include_tag[^\n]*application/)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def asset_check(id, label, source)
|
|
81
|
+
return check(id, "ok", "Bootstrap #{label} is linked from the CDN.") if layouts.match?(source[:cdn])
|
|
82
|
+
|
|
83
|
+
if linked_through_pipeline?(source)
|
|
84
|
+
return check(id, "ok", "Bootstrap #{label} is linked from the asset pipeline.") if exist?(source[:vendored_file])
|
|
85
|
+
|
|
86
|
+
return check(id, "error", "A layout links the Bootstrap #{label}, but #{source[:vendored_file]} does not exist.",
|
|
87
|
+
"Run `rails g bootstrap:install static`.")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
if bundled_elsewhere?
|
|
91
|
+
return check(id, "warn", "Bootstrap appears to come from package.json or the importmap, so the #{label} can't be verified.")
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
check(id, "error", "No layout loads the Bootstrap #{label}, so the page will render unstyled or without behaviour.",
|
|
95
|
+
"Run `rails g bootstrap:install static` (or `cdn`), then `rails g bootstrap:layout`, " \
|
|
96
|
+
"or link it from your own layout (`rails g bootstrap:cdn` prints the tags).")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def linked_through_pipeline?(source)
|
|
100
|
+
propshaft_link = layouts.include?(source[:vendored_name])
|
|
101
|
+
sprockets_link = layouts.match?(source[:layout_tag]) && read(source[:manifest]).match?(source[:manifest_entry])
|
|
102
|
+
|
|
103
|
+
case pipeline
|
|
104
|
+
when :propshaft then propshaft_link
|
|
105
|
+
when :sprockets then sprockets_link
|
|
106
|
+
else propshaft_link || sprockets_link
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def bundled_elsewhere?
|
|
111
|
+
read("package.json").match?(/"bootstrap"\s*:/) || read("config/importmap.rb").match?(/pin\s+["']bootstrap["']/)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def version_check
|
|
115
|
+
found = layouts.scan(/bootstrap@(\d+\.\d+\.\d+)/).flatten
|
|
116
|
+
[VENDORED_CSS, VENDORED_JS].each do |file|
|
|
117
|
+
found.concat(read(file)[0, 400].to_s.scan(/Bootstrap\s+v(\d+\.\d+\.\d+)/).flatten)
|
|
118
|
+
end
|
|
119
|
+
stale = found.uniq - [BOOTSTRAP_VERSION]
|
|
120
|
+
|
|
121
|
+
return check("bootstrap_version", "ok", "No Bootstrap version other than #{BOOTSTRAP_VERSION} found.") if stale.empty?
|
|
122
|
+
|
|
123
|
+
check("bootstrap_version", "warn",
|
|
124
|
+
"Found Bootstrap #{stale.join(', ')}, but this gem ships #{BOOTSTRAP_VERSION}.",
|
|
125
|
+
"Run `rails g bootstrap:install static --force` or update the CDN tags with `rails g bootstrap:cdn`.")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def sprite_check
|
|
129
|
+
sprite = view_files.find { |file| File.basename(file) == "_bootstrap_icons.html.erb" }
|
|
130
|
+
return check("icon_sprite", "ok", "The icon sprite is not installed.") unless sprite
|
|
131
|
+
|
|
132
|
+
renders = view_files.sum { |file| read(file).scan(/render\b[^\n]*bootstrap_icons/).size }
|
|
133
|
+
case renders
|
|
134
|
+
when 0
|
|
135
|
+
render_path = sprite.sub(%r{\Aapp/views/}, "").sub("_bootstrap_icons.html.erb", "bootstrap_icons")
|
|
136
|
+
check("icon_sprite", "error", "The icon sprite is installed but never rendered, so snippet icons come out empty.",
|
|
137
|
+
%{Add <%= render "#{render_path}" %> once, near the top of <body> in your layout.})
|
|
138
|
+
when 1
|
|
139
|
+
check("icon_sprite", "ok", "The icon sprite is rendered once.")
|
|
140
|
+
else
|
|
141
|
+
check("icon_sprite", "warn", "The icon sprite is rendered #{renders} times, which repeats its symbol ids.",
|
|
142
|
+
"Render it once, in your layout.")
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def placeholder_check
|
|
147
|
+
files = view_files.flat_map do |file|
|
|
148
|
+
read(file).each_line.with_index(1).filter_map do |line, number|
|
|
149
|
+
"#{file}:#{number}" if PLACEHOLDER_IMAGES.any? { |image| line.include?(image) }
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
return check("placeholder_images", "ok", "No docs-site placeholder images found.") if files.empty?
|
|
153
|
+
|
|
154
|
+
check("placeholder_images", "warn", "#{files.size} reference(s) to placeholder images that only exist on the Bootstrap docs site.",
|
|
155
|
+
"Point them at your own images.").merge(:files => files)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def legacy_check
|
|
159
|
+
count = legacy_markup.size
|
|
160
|
+
return check("legacy_markup", "ok", "No older Bootstrap markup found.") if count.zero?
|
|
161
|
+
|
|
162
|
+
check("legacy_markup", "warn", "#{count} use(s) of markup from older Bootstrap versions, listed in legacy_markup.",
|
|
163
|
+
"Apply each replacement. Plain names like `close` or `well` may be your own CSS classes, so check before changing those.")
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def legacy_markup
|
|
167
|
+
@legacy_markup ||= scanned_files.flat_map do |file|
|
|
168
|
+
LegacyMarkup.scan(read(file), File.extname(file)).map { |finding| { :file => file }.merge(finding) }
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def check(id, status, message, fix = nil)
|
|
173
|
+
result = { :id => id, :status => status, :message => message }
|
|
174
|
+
result[:fix] = fix if fix
|
|
175
|
+
result
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def layouts
|
|
179
|
+
@layouts ||= view_files.select { |file| file.start_with?("app/views/layouts/") }.map { |file| read(file) }.join("\n")
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def view_files
|
|
183
|
+
@view_files ||= relative_files("app/views/**/*").reject { |file| file.end_with?(".rb") }
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def scanned_files
|
|
187
|
+
relative_files("app/{views,helpers,components}/**/*")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def relative_files(pattern)
|
|
191
|
+
Dir[File.join(@root, pattern)]
|
|
192
|
+
.select { |file| File.file?(file) && SCANNED_EXTENSIONS.include?(File.extname(file)) }
|
|
193
|
+
.map { |file| file.delete_prefix("#{@root}/") }
|
|
194
|
+
.sort
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def exist?(relative)
|
|
198
|
+
File.file?(File.join(@root, relative))
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def read(relative)
|
|
202
|
+
exist?(relative) ? File.read(File.join(@root, relative)).scrub : ""
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|