effective_bootstrap 0.9.1 → 0.9.2

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: 456bfec1d309b5a42655fc3cc6f0974aa652447c03b5bb4087fac75234b5224b
4
- data.tar.gz: 6cc6d0f44fe7e6e5e70252c12f00d28ab2f5d068ea55f327e6e134b4771e7edb
3
+ metadata.gz: a09d2f8d91357f5486377ae6a31483533bf214f4c8f1ba536bc9061828529370
4
+ data.tar.gz: e6a42b55fc5b377d7ccebf1b7418c41df907ed4b66de6ee58407690e46e82767
5
5
  SHA512:
6
- metadata.gz: c74d48645ebb72fcc48cc64a528bb712b1217df473620a789788bb8055c8e55c4987e329d74bc69362891af23df7d2eaaa95655de5ba8e7cae16b76b596bff14
7
- data.tar.gz: daffd96de52135a3c5b977bb1c4df77d6a32777b36c894d96ba951bda5b2005e1ce186a283bb0cc3be0942f6711b7c61a690f8d0b3c10ffec638e0b5e4978efe
6
+ metadata.gz: 95b1495a52b26a3970754866ef7d35735be448daa675c3f21745ec8ff6298d893d8ecc912d37b28d1dd03ffad3fed29fa3adbcc26e6a278a050a6565bb052dbb
7
+ data.tar.gz: 174be86ba9a4064b21a3dcdbe4c13787165a574a31f93773ac12de60d20212e37edea12793197afa360502f95f6f2fd8941281696f114f881c2aa61da6fea470
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Boostrap4 Helpers
2
4
 
3
5
  module EffectiveBootstrapHelper
@@ -72,15 +74,27 @@ module EffectiveBootstrapHelper
72
74
  # variations can be :dropup, :dropleft, :dropright
73
75
  # split can be true, false
74
76
  # right is to right align things
77
+ DROPDOWN_SPLIT_OPTS = {class: "btn dropdown-toggle dropdown-toggle-split btn-sm btn-outline-primary", type: 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false}
78
+ DROPDOWN_UNSPLIT_OPTS= {class: "btn dropdown-toggle btn-sm btn-outline-primary", type: 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false}
79
+
80
+ DROPDOWN_DROPLEFT_GROUP_OPTS = {class: 'btn-group'}
81
+ DROPDOWN_DROPLEFT_OPTS = {class: 'btn-group dropleft', role: 'group'}
82
+
83
+ DROPDOWN_MENU_OPTS = {class: 'dropdown-menu'}
84
+ DROPDOWN_MENU_RIGHT_OPTS = {class: 'dropdown-menu dropdown-menu-right'}
85
+
86
+ DROPDOWN_BTN_CLASS = 'btn-sm btn-outline-primary'
87
+ DROPDOWN_TOGGLE_DROPDOWN = "<span class='sr-only'>Toggle Dropdown</span>".html_safe
88
+
75
89
  def dropdown(variation: nil, split: true, btn_class: nil, btn_content: nil, right: false, &block)
76
90
  raise 'expected a block' unless block_given?
77
91
 
78
- btn_class = btn_class.presence || 'btn-outline-primary'
92
+ btn_class ||= DROPDOWN_BTN_CLASS
79
93
 
94
+ # Process all dropdown_link_tos
80
95
  @_dropdown_link_tos = []
81
96
  @_dropdown_split = split
82
-
83
- # process dropdown_link_tos
97
+ @_dropdown_button_class = btn_class
84
98
  yield
85
99
 
86
100
  return @_dropdown_link_tos.first if @_dropdown_link_tos.length <= 1
@@ -88,31 +102,37 @@ module EffectiveBootstrapHelper
88
102
  # Build tags
89
103
  first = @_dropdown_link_tos.first
90
104
 
91
- button = content_tag(:button, class: "btn #{btn_class} dropdown-toggle" + (split ? " dropdown-toggle-split" : ''), type: 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) do
92
- btn_content || content_tag(:span, 'Toggle Dropdown', class: 'sr-only')
105
+ button_opts = (split ? DROPDOWN_SPLIT_OPTS : DROPDOWN_UNSPLIT_OPTS)
106
+
107
+ if btn_class != DROPDOWN_BTN_CLASS
108
+ button_opts[:class] = button_opts[:class].sub(DROPDOWN_BTN_CLASS, btn_class)
109
+ end
110
+
111
+ button = content_tag(:button, button_opts) do
112
+ btn_content || DROPDOWN_TOGGLE_DROPDOWN
93
113
  end
94
114
 
115
+ menu_opts = (right ? DROPDOWN_MENU_RIGHT_OPTS : DROPDOWN_MENU_OPTS)
116
+
95
117
  menu = if split
96
- content_tag(:div, @_dropdown_link_tos[1..-1].join.html_safe, class: ['dropdown-menu', ('dropdown-menu-right' if right)].compact.join(' '))
118
+ content_tag(:div, @_dropdown_link_tos[1..-1].join.html_safe, menu_opts)
97
119
  else
98
- content_tag(:div, @_dropdown_link_tos.join.html_safe, class: ['dropdown-menu', ('dropdown-menu-right' if right)].compact.join(' '))
120
+ content_tag(:div, @_dropdown_link_tos.join.html_safe, menu_opts)
99
121
  end
100
122
 
101
- retval = if split
123
+ @_dropdown_link_tos = nil
124
+
125
+ if split && variation == :dropleft
126
+ content_tag(:div, DROPDOWN_DROPLEFT_GROUP_OPTS) do
127
+ content_tag(:div, (button + menu), DROPDOWN_DROPLEFT_OPTS) + first.html_safe
128
+ end
129
+ elsif split
102
130
  content_tag(:div, class: 'btn-group') do
103
- content_tag(:div, class: ['btn-group', variation.to_s.presence].compact.join(' '), role: 'group') do
104
- [:dropleft].include?(variation) ? (button + menu) : (first + button + menu)
105
- end + ([:dropleft].include?(variation) ? first : '').html_safe
131
+ content_tag(:div, (first + button + menu), class: "btn-group #{variation}", role: 'group')
106
132
  end
107
133
  else
108
- content_tag(:div, class: 'dropdown') do
109
- button + menu
110
- end
134
+ content_tag(:div, (button + menu), class: 'dropdown')
111
135
  end
112
-
113
- @_dropdown_link_tos = nil
114
-
115
- retval
116
136
  end
117
137
 
118
138
  # This is a special variant of dropdown
@@ -135,17 +155,17 @@ module EffectiveBootstrapHelper
135
155
 
136
156
  # Works with dots do and dropdown do
137
157
  def dropdown_link_to(label, path, options = {})
138
- btn_class = options.delete(:btn_class).presence || 'btn-outline-primary'
158
+ btn_class = options.delete(:btn_class).presence || @_dropdown_button_class || 'btn-outline-primary'
139
159
 
140
160
  unless @_dropdown_link_tos
141
- options[:class] = [options[:class], 'dropdown-item'].compact.join(' ')
161
+ options[:class] = (options[:class] ? "dropdown-item #{options[:class]}" : 'dropdown-item')
142
162
  return link_to(label, path, options)
143
163
  end
144
164
 
145
165
  if @_dropdown_link_tos.length == 0 && @_dropdown_split
146
- options[:class] = [options[:class], 'btn', btn_class].compact.join(' ')
166
+ options[:class] = (options[:class] ? "btn #{btn_class} #{options[:class]}" : "btn #{btn_class}")
147
167
  else
148
- options[:class] = [options[:class], 'dropdown-item'].compact.join(' ')
168
+ options[:class] = (options[:class] ? "dropdown-item #{options[:class]}" : 'dropdown-item')
149
169
  end
150
170
 
151
171
  @_dropdown_link_tos << link_to(label, path, options)
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.9.2'.freeze
3
3
  end
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: 0.9.1
4
+ version: 0.9.2
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: 2020-09-17 00:00:00.000000000 Z
11
+ date: 2020-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails