effective_bootstrap 1.16.4 → 1.17.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1eaa58fb353b2a90cb02cc7d6f309128d545acc73d4b1d2a3651674e1d75641
|
4
|
+
data.tar.gz: '03328a636c5de3f6fa45e98639fc638ef0ceb51c378552d1e9bb13df201790ab'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e20cbebaa2844632bfb805cc59812c8731363a993ca606473e1fc9d497c2b150e3032838f729e222b0d176f99fba67d81676c05e2b6b048a35b0a043f11489c
|
7
|
+
data.tar.gz: 90973730f22b12a6b1fe0767a5be2c6c3bf83b9f5c034712294950a797aaa97bdb259f65d45f754b6613090f6e24fae34b00ac05fd44343a906939799aaa1447
|
@@ -569,7 +569,7 @@ module EffectiveBootstrapHelper
|
|
569
569
|
# If you pass active 'label' it will make that tab active. Otherwise first.
|
570
570
|
# Unique will make sure the tab html IDs are unique
|
571
571
|
# $('#tab-demographics').tab('show')
|
572
|
-
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)
|
573
573
|
raise 'expected a block' unless block_given?
|
574
574
|
|
575
575
|
# The Active Tab might be set from a previous form submission, or passed into helper
|
@@ -587,31 +587,56 @@ module EffectiveBootstrapHelper
|
|
587
587
|
|
588
588
|
tab_active ||= :first if tab_active.nil?
|
589
589
|
@_tab_unique = effective_bootstrap_unique_id if unique
|
590
|
+
@_tab_benchmarks = {} if benchmarks # Enables benchmarks
|
590
591
|
|
591
592
|
# Generate the html in two passes
|
592
|
-
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
|
593
594
|
@_tab_mode = :tablist
|
594
595
|
@_tab_active = tab_active
|
595
596
|
|
596
597
|
yield # Yield to tab the first time
|
597
|
-
end
|
598
|
-
|
598
|
+
end
|
599
|
+
|
600
|
+
tabs_divs = content_tag(:div, {class: 'tab-content'}.merge(content)) do
|
599
601
|
@_tab_mode = :content
|
600
602
|
@_tab_active = tab_active
|
601
603
|
|
602
604
|
yield # Yield to tab the second time
|
603
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(0)
|
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)
|
604
629
|
end
|
605
630
|
|
606
631
|
NUMBERS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
607
632
|
|
608
633
|
def tab(resource, opts = {}, &block)
|
609
634
|
return if resource.kind_of?(Class) && !EffectiveResources.authorized?(self, :index, resource)
|
610
|
-
label = opts
|
635
|
+
label = opts[:label] || effective_bootstrap_human_name(resource, plural: opts.fetch(:plural, true), prefer_model_name: true)
|
611
636
|
|
612
637
|
(@_tab_labels.push(label) and return) if @_tab_mode == :validate
|
613
638
|
|
614
|
-
controls = opts
|
639
|
+
controls = opts[:controls] || label.to_s.parameterize.gsub('_', '-')
|
615
640
|
controls = "item-#{controls}" if NUMBERS.include?(controls[0]) # Can't start with a number
|
616
641
|
controls = controls[1..-1] if controls[0] == '#'
|
617
642
|
controls = "#{controls}-#{@_tab_unique}" if @_tab_unique
|
@@ -629,7 +654,11 @@ module EffectiveBootstrapHelper
|
|
629
654
|
else # Inserting the content into the tab itself
|
630
655
|
classes = ['tab-pane', 'fade', ('show active' if active), opts[:class].presence].compact.join(' ')
|
631
656
|
content_tag(:div, id: controls, class: classes, role: 'tabpanel', 'aria-labelledby': ('tab-' + controls), 'data-tab-label': label) do
|
632
|
-
|
657
|
+
if @_tab_benchmarks.kind_of?(Hash)
|
658
|
+
@_tab_benchmarks[label] = Benchmark.measure { yield }
|
659
|
+
else
|
660
|
+
yield
|
661
|
+
end
|
633
662
|
end
|
634
663
|
end
|
635
664
|
end
|
data/lib/effective_bootstrap.rb
CHANGED