effective_bootstrap 1.16.3 → 1.17.0

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: 7a43d4059d694f254fb05f0cb43f12dc5f3b5fbeb5df8dc7aa7aa21fc8a3bad9
4
- data.tar.gz: 8967aad36784c29bd334837b2bf9d4683258e7afafd61d509821dd31a860688c
3
+ metadata.gz: 911b7b8dbe6840081eac56f04deca54f72b96244d920b8ec552738ee322677b0
4
+ data.tar.gz: a84456a02edbc9ccefdb53d39e6f60356c8b1299a4942dba7ae59f7ea62781dc
5
5
  SHA512:
6
- metadata.gz: 8dc33e68ff3d7383d22d60971c577490c4fbc9d93f606ec66b7ac45a38cb1fca4ef2ef514525b0b1a0fa974b65d36599791ae14d2f134bd8a5ad0b1ac3ca0670
7
- data.tar.gz: 383b522a6c0839f578f545f7535aac54682a9640f1c88c3d61d48879a445683047f0a95d373b0b3b74777bed218be622fa5f1a387979d4841f06263fe5630928
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
- # Figure out all the button / link options
133
- link_opts = { 'data-toggle': 'collapse', role: 'button', href: "##{id}", 'aria-controls': "##{id}", 'aria-expanded': show }
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
- link_opts[:class] = opts.delete(:link_class) || 'btn btn-link'
146
- link_opts[:class] += ' effective-collapse-actions hidden-print'
147
- link_opts[:class] += ' collapsed' unless show
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
- # The div and the card now
150
- div_class = opts.delete(:div_class)
151
- card_class = opts.delete(:card_class) || 'card card-body my-2'
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
- content_tag(:div, {class: 'tab-content'}.merge(content)) do
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.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)
604
636
 
605
637
  (@_tab_labels.push(label) and return) if @_tab_mode == :validate
606
638
 
607
- controls = opts.delete(:controls) || label.to_s.parameterize.gsub('_', '-')
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
- yield
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
@@ -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.3'.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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.3
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-10-24 00:00:00.000000000 Z
11
+ date: 2023-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails