effective_bootstrap 1.16.3 → 1.17.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/app/helpers/effective_bootstrap_helper.rb +51 -15
- data/config/effective_bootstrap.rb +3 -0
- data/lib/effective_bootstrap/version.rb +1 -1
- data/lib/effective_bootstrap.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 911b7b8dbe6840081eac56f04deca54f72b96244d920b8ec552738ee322677b0
|
4
|
+
data.tar.gz: a84456a02edbc9ccefdb53d39e6f60356c8b1299a4942dba7ae59f7ea62781dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b563346c69e73baac5fbcb490296388294d73216af1b0a14c95178545870d12e182998b41dc57a5aed34ad61e5affe1ec06064d95cdfe0c0f68470cf4e0ddc53
|
7
|
+
data.tar.gz: fe8a5bce59a2b6876e9dddd8851b90e4c36da0498c8eb89ec8ce98d6cd7e999c10826bc9d6f56976b1f40f469357b078dde62ac8dfe0d78194141157c59b119e
|
@@ -129,8 +129,9 @@ module EffectiveBootstrapHelper
|
|
129
129
|
id = "collapse-#{effective_bootstrap_unique_id}"
|
130
130
|
show = (opts.delete(:show) == true)
|
131
131
|
|
132
|
-
#
|
133
|
-
|
132
|
+
# The div and the card now
|
133
|
+
div_class = opts.delete(:div_class)
|
134
|
+
card_class = opts.delete(:card_class) || 'card card-body my-2'
|
134
135
|
|
135
136
|
# Two link labels
|
136
137
|
label_expand = opts.delete(:expand) || label.to_s.tap do |label|
|
@@ -142,13 +143,19 @@ module EffectiveBootstrapHelper
|
|
142
143
|
end + icon('chevron-up')
|
143
144
|
|
144
145
|
# The link html classes
|
145
|
-
|
146
|
-
|
147
|
-
|
146
|
+
link_class = opts.delete(:link_class) || 'btn btn-link'
|
147
|
+
link_class += ' effective-collapse-actions hidden-print'
|
148
|
+
link_class += ' collapsed' unless show
|
148
149
|
|
149
|
-
#
|
150
|
-
|
151
|
-
|
150
|
+
# Figure out all the button / link options
|
151
|
+
link_opts = {
|
152
|
+
'data-toggle': 'collapse',
|
153
|
+
role: 'button',
|
154
|
+
href: "##{id}",
|
155
|
+
'aria-controls': "##{id}",
|
156
|
+
'aria-expanded': show,
|
157
|
+
class: link_class
|
158
|
+
}.merge(opts)
|
152
159
|
|
153
160
|
# Normal collapse
|
154
161
|
link_tag = content_tag(:a, link_opts) do
|
@@ -562,7 +569,7 @@ module EffectiveBootstrapHelper
|
|
562
569
|
# If you pass active 'label' it will make that tab active. Otherwise first.
|
563
570
|
# Unique will make sure the tab html IDs are unique
|
564
571
|
# $('#tab-demographics').tab('show')
|
565
|
-
def tabs(active: nil, unique: false, ignore_save_tab: false, list: {}, content: {}, &block)
|
572
|
+
def tabs(active: nil, unique: false, ignore_save_tab: false, benchmarks: EffectiveBootstrap.benchmarks, list: {}, content: {}, &block)
|
566
573
|
raise 'expected a block' unless block_given?
|
567
574
|
|
568
575
|
# The Active Tab might be set from a previous form submission, or passed into helper
|
@@ -580,31 +587,56 @@ module EffectiveBootstrapHelper
|
|
580
587
|
|
581
588
|
tab_active ||= :first if tab_active.nil?
|
582
589
|
@_tab_unique = effective_bootstrap_unique_id if unique
|
590
|
+
@_tab_benchmarks = {} if benchmarks # Enables benchmarks
|
583
591
|
|
584
592
|
# Generate the html in two passes
|
585
|
-
content_tag(:ul, {class: 'nav nav-tabs', role: 'tablist'}.merge(list)) do
|
593
|
+
tabs_list = content_tag(:ul, {class: 'nav nav-tabs', role: 'tablist'}.merge(list)) do
|
586
594
|
@_tab_mode = :tablist
|
587
595
|
@_tab_active = tab_active
|
588
596
|
|
589
597
|
yield # Yield to tab the first time
|
590
|
-
end
|
591
|
-
|
598
|
+
end
|
599
|
+
|
600
|
+
tabs_divs = content_tag(:div, {class: 'tab-content'}.merge(content)) do
|
592
601
|
@_tab_mode = :content
|
593
602
|
@_tab_active = tab_active
|
594
603
|
|
595
604
|
yield # Yield to tab the second time
|
596
605
|
end
|
606
|
+
|
607
|
+
if benchmarks
|
608
|
+
total = @_tab_benchmarks.values.sum(&:real)
|
609
|
+
|
610
|
+
@_tab_benchmarks.each do |label, benchmark|
|
611
|
+
percent = (benchmark.real / total * 100).round(0)
|
612
|
+
amount = (benchmark.real * 1000).round(1)
|
613
|
+
|
614
|
+
badge_class = case amount
|
615
|
+
when (0.0..150.0) then ''
|
616
|
+
when (150.0..500.0) then 'badge-warning'
|
617
|
+
else 'badge-danger'
|
618
|
+
end
|
619
|
+
|
620
|
+
badge = content_tag(:span, "#{percent}% | #{amount}ms", class: "badge #{badge_class}")
|
621
|
+
|
622
|
+
tabs_list.sub!(label, label + '<br>' + badge)
|
623
|
+
end
|
624
|
+
|
625
|
+
tabs_list = tabs_list.html_safe
|
626
|
+
end
|
627
|
+
|
628
|
+
(tabs_list + tabs_divs)
|
597
629
|
end
|
598
630
|
|
599
631
|
NUMBERS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
600
632
|
|
601
633
|
def tab(resource, opts = {}, &block)
|
602
634
|
return if resource.kind_of?(Class) && !EffectiveResources.authorized?(self, :index, resource)
|
603
|
-
label = opts
|
635
|
+
label = opts[:label] || effective_bootstrap_human_name(resource, plural: opts.fetch(:plural, true), prefer_model_name: true)
|
604
636
|
|
605
637
|
(@_tab_labels.push(label) and return) if @_tab_mode == :validate
|
606
638
|
|
607
|
-
controls = opts
|
639
|
+
controls = opts[:controls] || label.to_s.parameterize.gsub('_', '-')
|
608
640
|
controls = "item-#{controls}" if NUMBERS.include?(controls[0]) # Can't start with a number
|
609
641
|
controls = controls[1..-1] if controls[0] == '#'
|
610
642
|
controls = "#{controls}-#{@_tab_unique}" if @_tab_unique
|
@@ -622,7 +654,11 @@ module EffectiveBootstrapHelper
|
|
622
654
|
else # Inserting the content into the tab itself
|
623
655
|
classes = ['tab-pane', 'fade', ('show active' if active), opts[:class].presence].compact.join(' ')
|
624
656
|
content_tag(:div, id: controls, class: classes, role: 'tabpanel', 'aria-labelledby': ('tab-' + controls), 'data-tab-label': label) do
|
625
|
-
|
657
|
+
if @_tab_benchmarks.kind_of?(Hash)
|
658
|
+
@_tab_benchmarks[label] = Benchmark.measure { yield }
|
659
|
+
else
|
660
|
+
yield
|
661
|
+
end
|
626
662
|
end
|
627
663
|
end
|
628
664
|
end
|
data/lib/effective_bootstrap.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|