effective_bootstrap 1.16.4 → 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
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
|
@@ -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(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)
|
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