trap 2.0 → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +19 -0
- data/.rubocop.yml +14 -0
- data/Gemfile +2 -0
- data/README.md +26 -4
- data/Rakefile +2 -1
- data/bin/console +4 -3
- data/lib/trap/helpers/bootstrap_helper.rb +88 -11
- data/lib/trap/version.rb +3 -1
- data/lib/trap.rb +3 -1
- data/trap.gemspec +8 -6
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cf16945c4f212f6aef573445c4070d9e9c916250fcd25144fb1457e5608ce6e8
|
4
|
+
data.tar.gz: 9a7b52dcce3532f7bb0f4c7bb82a93e677ee67f93227071e01a127f3cbefe33a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88e6015b3fb23d6ea8cac7e240c48409139dd573ba8e4950428f1cc4a0898ffc8eed51524b31288773798b609eee697960c4dd999d50ec818a4ea097cfdcc768
|
7
|
+
data.tar.gz: 58d341852ea440da9f7af1b6d64cd32b3065f1ba0ed90b5883b50867a9b549e676a98793c42de01d226ca5c2ddbdb10286baecb83c640804916cc88e796b3efb
|
@@ -0,0 +1,19 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v1
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: actions/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-versions: 2.6.5, 2.7.0, 2.5.7, 2.4.9
|
14
|
+
- name: Build and test with Rake
|
15
|
+
run: |
|
16
|
+
gem install bundler -v '1.17.2'
|
17
|
+
bundle install --jobs 4 --retry 3
|
18
|
+
bundle exec rspec
|
19
|
+
rubocop
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Documentation:
|
2
|
+
Enabled: false
|
3
|
+
Metrics/LineLength:
|
4
|
+
Max: 120
|
5
|
+
Metrics/BlockLength:
|
6
|
+
Enabled: false
|
7
|
+
Include:
|
8
|
+
- spec/
|
9
|
+
Metrics/AbcSize:
|
10
|
+
Max: 18
|
11
|
+
Layout/ArgumentAlignment:
|
12
|
+
EnforcedStyle: with_fixed_indentation
|
13
|
+
AllCops:
|
14
|
+
TargetRubyVersion: 2.7
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# Trap
|
1
|
+
# Trap [![Build Status](https://github.com/kalashnikovisme/trap/workflows/Ruby/badge.svg)](https://github.com/kalashnikovisme/trap/actions)
|
2
2
|
|
3
|
-
Bootstrap helpers
|
3
|
+
Bootstrap helpers. Bootstrap 4.x compatible.
|
4
|
+
|
5
|
+
Use `trap 1.x` for Bootstrap 3.x compatible.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -28,7 +30,9 @@ module ApplicationHelper
|
|
28
30
|
end
|
29
31
|
```
|
30
32
|
|
31
|
-
List of methods you can use with Trap
|
33
|
+
## List of methods you can use with Trap
|
34
|
+
|
35
|
+
### Menu items
|
32
36
|
|
33
37
|
* menu_item
|
34
38
|
Bootstrap navbar item
|
@@ -47,7 +51,25 @@ Using `menu_item` instead of
|
|
47
51
|
</li>
|
48
52
|
```
|
49
53
|
|
50
|
-
|
54
|
+
* model_menu_item
|
55
|
+
Bootstrap navbar item based on ActiveRecord
|
56
|
+
|
57
|
+
```erb
|
58
|
+
<%= model_menu_item model:, route:, icon:, number:, pluralize: %>
|
59
|
+
```
|
60
|
+
|
61
|
+
### Dropdown
|
62
|
+
|
63
|
+
You can create dropdowns with something like this:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
= dropdown t("admin.navbar.links.#{item.keys.first}") do
|
67
|
+
= dropdown_item text, link
|
68
|
+
= dropdown_divider
|
69
|
+
= dropdown_model_item model: model, route: ::Tramway::Admin::Engine.routes.url_helpers.singleton_path(model: model)
|
70
|
+
```
|
71
|
+
|
72
|
+
## For Bootstrap 3
|
51
73
|
|
52
74
|
You should use `trap-1.x` versions to include Bootstrap 3. Contributing to `bootstrap-3` branch.
|
53
75
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'trap'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "trap"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
@@ -1,18 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BootstrapHelper
|
2
4
|
def menu_item(name = nil, path = '#', *args, &block)
|
3
5
|
path = name || path if block_given?
|
4
6
|
options = args.extract_options!
|
5
7
|
options[:class] = [options[:class], 'nav-link'].join(' ')
|
6
|
-
content_tag :li, class: "nav-item #{
|
7
|
-
|
8
|
+
content_tag :li, class: "nav-item #{active?(path, options)}" do
|
9
|
+
if block_given?
|
10
|
+
name = path
|
11
|
+
path = options
|
12
|
+
end
|
8
13
|
link_to name, path, options, &block
|
9
14
|
end
|
10
15
|
end
|
11
16
|
|
17
|
+
def model_menu_item(model:, route:, icon: nil, number: nil, pluralize: nil)
|
18
|
+
title = model.is_a?(Class) ? (pluralize || model.model_name.human.pluralize(:ru)) : model
|
19
|
+
if icon
|
20
|
+
build_menu_item_with_icon route: route, icon: icon, number: number, title: title
|
21
|
+
else
|
22
|
+
menu_item title, route
|
23
|
+
end
|
24
|
+
end
|
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
|
+
|
12
46
|
private
|
13
47
|
|
14
|
-
def
|
15
|
-
:active if uri_state(path, options).in? [
|
48
|
+
def active?(path, options = {})
|
49
|
+
:active if uri_state(path, options).in? %i[active chosen]
|
16
50
|
end
|
17
51
|
|
18
52
|
def uri_state(uri, options = {})
|
@@ -23,16 +57,59 @@ module BootstrapHelper
|
|
23
57
|
else
|
24
58
|
request.path
|
25
59
|
end
|
26
|
-
|
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: { 'bs-toggle': :dropdown },
|
94
|
+
aria: { 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)
|
27
100
|
:inactive
|
28
|
-
elsif
|
101
|
+
elsif uri_state_is_active?(request_uri: request_uri, options: options, root_url: root_url, uri: uri)
|
29
102
|
:active
|
30
103
|
else
|
31
|
-
|
32
|
-
:chosen
|
33
|
-
else
|
34
|
-
:inactive
|
35
|
-
end
|
104
|
+
request_uri.start_with?(uri) && !root ? :chosen : :inactive
|
36
105
|
end
|
37
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
|
38
115
|
end
|
data/lib/trap/version.rb
CHANGED
data/lib/trap.rb
CHANGED
data/trap.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'trap/version'
|
5
6
|
|
@@ -9,16 +10,17 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Pavel Kalashnikov']
|
10
11
|
spec.email = ['kalashnikovisme@gmail.com']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
13
|
+
spec.summary = 'Bootstrap helpers'
|
14
|
+
spec.description = 'Bootstrap helpers'
|
14
15
|
spec.homepage = 'https://github.com/kalashnikovisme/trap'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
17
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
19
|
spec.bindir = 'exe'
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = %w[lib app]
|
21
22
|
|
22
|
-
spec.add_development_dependency 'bundler', '>= 1.8'
|
23
23
|
spec.add_development_dependency 'rake', '>= 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'rubocop'
|
24
26
|
end
|
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '4.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:
|
11
|
+
date: 2022-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '10.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '10.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
description: Bootstrap helpers
|
42
56
|
email:
|
43
57
|
- kalashnikovisme@gmail.com
|
@@ -45,7 +59,9 @@ executables: []
|
|
45
59
|
extensions: []
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
62
|
+
- ".github/workflows/ruby.yml"
|
48
63
|
- ".gitignore"
|
64
|
+
- ".rubocop.yml"
|
49
65
|
- ".travis.yml"
|
50
66
|
- CODE_OF_CONDUCT.md
|
51
67
|
- Gemfile
|
@@ -78,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
94
|
- !ruby/object:Gem::Version
|
79
95
|
version: '0'
|
80
96
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.6.11
|
97
|
+
rubygems_version: 3.0.3.1
|
83
98
|
signing_key:
|
84
99
|
specification_version: 4
|
85
100
|
summary: Bootstrap helpers
|