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: a3ae83f617d9b5fe35307b2b685480ba6ca0e8973cf66ffc0f6b401929ca3cdc
4
- data.tar.gz: 6bd06b8c2580d0421fe91ac55182396bb1cf52fd0e4c9b6089d0954a395e90dd
3
+ metadata.gz: 911b7b8dbe6840081eac56f04deca54f72b96244d920b8ec552738ee322677b0
4
+ data.tar.gz: a84456a02edbc9ccefdb53d39e6f60356c8b1299a4942dba7ae59f7ea62781dc
5
5
  SHA512:
6
- metadata.gz: a0b275deee025c6631bd2a9419cb33ddf7b4bbd5789d35940836ed39107f749442826d66b615ba46713c623fa6c0fdc99e9af201a1d26bebf5b069f8de4b6ef7
7
- data.tar.gz: 5755a4b4080a05265cb35ea3c3a740c2e80dccc81e56f4051921d65adf41454e7a0dcf91c9836206cac20d645574d21fdc18db7ef6c03b64e273ff85caca25a6
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
- content_tag(:div, {class: 'tab-content'}.merge(content)) do
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.delete(:label) || effective_bootstrap_human_name(resource, plural: (opts.key?(:plural) ? opts.delete(:plural) : true), prefer_model_name: true)
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.delete(:controls) || label.to_s.parameterize.gsub('_', '-')
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
- yield
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
@@ -6,4 +6,7 @@ EffectiveBootstrap.setup do |config|
6
6
  # Adds a before_action to ApplicationController
7
7
  # To save and restore the active bootstrap tabs
8
8
  config.save_tabs = true
9
+
10
+ # Adds benchmark stats to each of the = tab helpers
11
+ config.benchmarks = false
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '1.16.4'.freeze
2
+ VERSION = '1.17.0'.freeze
3
3
  end
@@ -6,7 +6,7 @@ require 'effective_bootstrap/version'
6
6
  module EffectiveBootstrap
7
7
 
8
8
  def self.config_keys
9
- [:use_custom_data_confirm, :save_tabs]
9
+ [:use_custom_data_confirm, :save_tabs, :benchmarks]
10
10
  end
11
11
 
12
12
  include EffectiveGem
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.4
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect