trap 2.2 → 3.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: 1ddfeac6f412bcc95002dd44fc9f5de6535412117a0da30fcfd02d88e2013de1
4
- data.tar.gz: 3dd2db672921d36c84b5db1c0491df45dd4b706c024ab50fef81582562f08427
3
+ metadata.gz: 49e62e1f47a818266ae94e494c0a1b00873f369cdd9551480151aab1e4efb02e
4
+ data.tar.gz: f53e3fceef11df36d09396aaf7053c162664e8198fc4993ef126da9715931a68
5
5
  SHA512:
6
- metadata.gz: 7b53dffe6731661c66022de323fbe23d6a1534811db8e7ccf4a19c7a9d609d3075659156ef57324770b5e56fb55e90aba044f51a83c700bfa17cbe8e5727432b
7
- data.tar.gz: 1d0491949ec8f825a57071b2cc191827da4980cc161537817f2141e63ca1802ba745bb801d2856c2725a0389540cdb2b74c30fcbcb4bccc2b841526d5fc91587
6
+ metadata.gz: 19f6220b141b43d97534f2bc25f56d0a85188d51742e9d55f385fccc894e3219bfbe283daa850ddd31fec26da62c67b99aa4f7aa3023c4351cba25d9416ea09c
7
+ data.tar.gz: 924996bce0caac8f7a6cea9339da5a08974b462a458b7e40263164d1d6cc44b52c60dfa67ca2f383abe4ce33a94e552ea902ab991e225cd970916d2a81f3a269
@@ -2,10 +2,12 @@ Documentation:
2
2
  Enabled: false
3
3
  Metrics/LineLength:
4
4
  Max: 120
5
+ Metrics/BlockLength:
6
+ Enabled: false
7
+ Include:
8
+ - spec/
5
9
  Metrics/AbcSize:
6
10
  Max: 18
7
- Style/ClassAndModuleChildren:
8
- EnforcedStyle: compact
9
11
  Layout/ArgumentAlignment:
10
12
  EnforcedStyle: with_fixed_indentation
11
13
  AllCops:
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Trap
2
2
 
3
- Bootstrap helpers
3
+ Bootstrap helpers. Bootstrap 4.x compatible.
4
+ Use `trap 1.x` for Bootstrap 3.x compatible.
4
5
 
5
6
  ## Installation
6
7
 
@@ -47,7 +48,7 @@ Using `menu_item` instead of
47
48
  </li>
48
49
  ```
49
50
 
50
- ## For Bootstrap
51
+ ## For Bootstrap 3
51
52
 
52
53
  You should use `trap-1.x` versions to include Bootstrap 3. Contributing to `bootstrap-3` branch.
53
54
 
@@ -5,7 +5,7 @@ module BootstrapHelper
5
5
  path = name || path if block_given?
6
6
  options = args.extract_options!
7
7
  options[:class] = [options[:class], 'nav-link'].join(' ')
8
- content_tag :li, class: "nav-item #{is_active?(path, options)}" do
8
+ content_tag :li, class: "nav-item #{active?(path, options)}" do
9
9
  if block_given?
10
10
  name = path
11
11
  path = options
@@ -17,23 +17,35 @@ module BootstrapHelper
17
17
  def model_menu_item(model:, route:, icon: nil, number: nil, pluralize: nil)
18
18
  title = model.is_a?(Class) ? (pluralize || model.model_name.human.pluralize(:ru)) : model
19
19
  if icon
20
- menu_item route do
21
- concat icon_element icon
22
- concat ' '
23
- concat title
24
- if number && number != 0
25
- concat ' '
26
- concat(content_tag(:span, number.to_s, class: 'badge danger'))
27
- end
28
- end
20
+ build_menu_item_with_icon route: route, icon: icon, number: number, title: title
29
21
  else
30
22
  menu_item title, route
31
23
  end
32
24
  end
33
25
 
26
+ def dropdown(text, icon = nil, &block)
27
+ content_tag :li, class: 'nav-item dropdown' do
28
+ build_a_tag_for_dropdown text: text, icon: icon, &block
29
+ end
30
+ end
31
+
32
+ def dropdown_item(text, link)
33
+ link_to(text, link, class: 'dropdown-item')
34
+ end
35
+
36
+ def dropdown_model_item(model:, route:, pluralize: nil)
37
+ title = pluralize || model.model_name.human.pluralize(:ru)
38
+ dropdown_item title, route
39
+ end
40
+
41
+ def dropdown_divider
42
+ content_tag(:div, class: 'dropdown-divider') do
43
+ end
44
+ end
45
+
34
46
  private
35
47
 
36
- def is_active?(path, options = {})
48
+ def active?(path, options = {})
37
49
  :active if uri_state(path, options).in? %i[active chosen]
38
50
  end
39
51
 
@@ -45,16 +57,59 @@ module BootstrapHelper
45
57
  else
46
58
  request.path
47
59
  end
48
- if !options[:method].nil? || !options['data-method'].nil?
60
+ active_uri_state options: options, uri: uri, request_uri: request_uri, root_url: root_url, root: root
61
+ end
62
+
63
+ def build_menu_item_with_icon(route:, icon:, title:, number:)
64
+ menu_item route do
65
+ concat icon_element icon
66
+ concat ' '
67
+ concat title
68
+ if number && number != 0
69
+ concat ' '
70
+ concat(content_tag(:span, number.to_s, class: 'badge danger'))
71
+ end
72
+ end
73
+ end
74
+
75
+ def build_a_tag_for_dropdown(text:, icon:, &block)
76
+ concat(link_to('#', **dropdown_link_attributes(text)) do
77
+ if icon
78
+ concat content_tag :span, '', class: "glyphicon glyphicon-#{icon}"
79
+ concat ' '
80
+ end
81
+ concat text
82
+ end)
83
+ concat(content_tag(:div, class: 'dropdown-menu', aria: { labelledby: text }) do
84
+ yield(block)
85
+ end)
86
+ end
87
+
88
+ def dropdown_link_attributes(text)
89
+ {
90
+ class: 'nav-link dropdown-toggle',
91
+ id: text,
92
+ role: :button,
93
+ data: { toggle: :dropdown },
94
+ aria: { haspopup: true, expanded: false }
95
+ }
96
+ end
97
+
98
+ def active_uri_state(options:, uri:, request_uri:, root_url:, root:)
99
+ if uri_state_is_inactive?(options: options)
49
100
  :inactive
50
- elsif uri == request_uri || (options[:root] && (request_uri == '/') || (request_uri == root_url))
101
+ elsif uri_state_is_active?(request_uri: request_uri, options: options, root_url: root_url, uri: uri)
51
102
  :active
52
103
  else
53
- if request_uri.start_with?(uri) && !root
54
- :chosen
55
- else
56
- :inactive
57
- end
104
+ request_uri.start_with?(uri) && !root ? :chosen : :inactive
58
105
  end
59
106
  end
107
+
108
+ def uri_state_is_inactive?(options:)
109
+ !options[:method].nil? || !options['data-method'].nil?
110
+ end
111
+
112
+ def uri_state_is_active?(request_uri:, options:, root_url:, uri:)
113
+ uri == request_uri || (options[:root] && (request_uri == '/') || (request_uri == root_url))
114
+ end
60
115
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trap
4
- VERSION = '2.2'
4
+ VERSION = '3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trap
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.2'
4
+ version: '3.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-25 00:00:00.000000000 Z
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler