smart_navigation 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -5
- data/lib/smart_navigation.rb +0 -2
- data/lib/smart_navigation/helper.rb +1 -3
- data/lib/smart_navigation/renderer.rb +129 -150
- data/lib/smart_navigation/version.rb +1 -1
- metadata +2 -3
- data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d5ac40179ef25a551ff65d8387a6dd54bea6f1d6a763e075239d2914d7546e0
|
4
|
+
data.tar.gz: 2094525fb6e61a72b3cb475e0296bd9c95f179bb93a521a34a64e690d55df6bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d555b6b743d7ced442c14088da60daf005187350cac596ef7ace1e70bc94cdd43221b684430fc0aeec1f22d8b648511860da1818495a0a27ba5cd470dced284f
|
7
|
+
data.tar.gz: 46a4e1f5b405c50de3f30a1c43d30c22f3e7150d1652f69efda09bc7388699bc439dc4b3522e5bb9e17f22042168b4361da6fd583df14a1bb71be27c51de72e1
|
data/README.md
CHANGED
@@ -103,12 +103,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
103
103
|
|
104
104
|
## Contributing
|
105
105
|
|
106
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/smart-navigation.
|
106
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/smart-navigation.
|
107
107
|
|
108
108
|
## License
|
109
109
|
|
110
110
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
111
|
-
|
112
|
-
## Code of Conduct
|
113
|
-
|
114
|
-
Everyone interacting in the SmartNavigation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hardpixel/smart-navigation/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/smart_navigation.rb
CHANGED
@@ -4,12 +4,10 @@ require 'smart_navigation/version'
|
|
4
4
|
module SmartNavigation
|
5
5
|
extend ActiveSupport::Autoload
|
6
6
|
|
7
|
-
# Autoload modules
|
8
7
|
autoload :Renderer
|
9
8
|
autoload :Helper
|
10
9
|
end
|
11
10
|
|
12
|
-
# Include action view helpers
|
13
11
|
if defined? ActionView::Base
|
14
12
|
ActionView::Base.send :include, SmartNavigation::Helper
|
15
13
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module SmartNavigation
|
2
2
|
module Helper
|
3
|
-
|
4
|
-
def smart_navigation_for(items, options={})
|
3
|
+
def smart_navigation_for(items, options = {})
|
5
4
|
SmartNavigation::Renderer.new(self, items, options).render
|
6
5
|
end
|
7
6
|
|
8
|
-
# Alias helper method
|
9
7
|
alias :navigation_for :smart_navigation_for
|
10
8
|
end
|
11
9
|
end
|
@@ -1,197 +1,176 @@
|
|
1
1
|
module SmartNavigation
|
2
2
|
class Renderer
|
3
|
-
|
4
|
-
def initialize(view_context, items, options={})
|
3
|
+
def initialize(view_context, items, options = {})
|
5
4
|
@context = view_context
|
6
5
|
@items = sort_items items
|
7
6
|
@options = merge_options options
|
8
7
|
end
|
9
8
|
|
10
|
-
# Render menu
|
11
9
|
def render
|
12
10
|
menu_tag @items.map { |k, v| item_tag(v, @options[:menu_icons]) }.join
|
13
11
|
end
|
14
12
|
|
15
13
|
private
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
15
|
+
def default_options
|
16
|
+
{
|
17
|
+
menu_class: 'menu',
|
18
|
+
menu_html: {},
|
19
|
+
menu_icons: true,
|
20
|
+
item_class: 'menu-item',
|
21
|
+
separator_class: 'separator',
|
22
|
+
submenu_parent_class: 'has-submenu',
|
23
|
+
submenu_class: 'submenu',
|
24
|
+
submenu_item_class: 'submenu-item',
|
25
|
+
active_class: 'active',
|
26
|
+
active_submenu_class: 'open',
|
27
|
+
submenu_icons: false,
|
28
|
+
submenu_toggle: nil,
|
29
|
+
icon_prefix: 'icon icon-',
|
30
|
+
icon_default: 'missing',
|
31
|
+
icon_position: 'left',
|
32
|
+
keep_defaults: true
|
33
|
+
}
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
default_options.merge(options)
|
45
|
-
end
|
36
|
+
def merge_options(options)
|
37
|
+
if options[:keep_defaults] == false
|
38
|
+
options
|
39
|
+
else
|
40
|
+
default_options.merge(options)
|
46
41
|
end
|
42
|
+
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
44
|
+
def sort_items(items)
|
45
|
+
items.sort_by { |_k, v| v[:order] }.to_h
|
46
|
+
end
|
52
47
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
paths = [@context.request.path, @context.request.url]
|
48
|
+
def page_parent?(item)
|
49
|
+
url = item_url item
|
50
|
+
paths = [@context.request.path, @context.request.url]
|
57
51
|
|
58
|
-
|
59
|
-
|
52
|
+
url.present? && item[:root].blank? && paths.any? { |i| i.starts_with?(url) }
|
53
|
+
end
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
"##{item[:id]}"
|
67
|
-
end
|
55
|
+
def item_url(item)
|
56
|
+
if item[:url].present?
|
57
|
+
mixed_value(item[:url])
|
58
|
+
elsif item[:id].present?
|
59
|
+
"##{item[:id]}"
|
68
60
|
end
|
61
|
+
end
|
69
62
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
true
|
78
|
-
end
|
63
|
+
def render_item?(item)
|
64
|
+
if item[:if]
|
65
|
+
mixed_value(item[:if]).present?
|
66
|
+
elsif item[:unless]
|
67
|
+
mixed_value(item[:unless]).blank?
|
68
|
+
else
|
69
|
+
true
|
79
70
|
end
|
71
|
+
end
|
80
72
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
current = page_parent?(item) if item[:children].blank? and current.blank?
|
73
|
+
def current_page?(item)
|
74
|
+
current = @context.current_page?(item_url(item))
|
75
|
+
current = page_parent?(item) if item[:children].blank? and current.blank?
|
85
76
|
|
86
|
-
|
87
|
-
|
77
|
+
current
|
78
|
+
end
|
88
79
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
current = Hash(item[:children]).any? { |_k, v| current_group?(v) } if current.blank?
|
80
|
+
def current_group?(item)
|
81
|
+
current = current_page?(item)
|
82
|
+
current = Hash(item[:children]).any? { |_k, v| current_page?(v) } if current.blank?
|
83
|
+
current = Hash(item[:children]).any? { |_k, v| current_group?(v) } if current.blank?
|
94
84
|
|
95
|
-
|
96
|
-
|
85
|
+
current
|
86
|
+
end
|
97
87
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
88
|
+
def tag(*args, &block)
|
89
|
+
@context.content_tag(*args, &block)
|
90
|
+
end
|
102
91
|
|
103
|
-
|
104
|
-
|
105
|
-
icon = tag :i, nil, class: "#{@options[:icon_prefix]}#{name || @options[:icon_default]}"
|
92
|
+
def icon_tag(name, label = nil)
|
93
|
+
icon = tag :i, nil, class: "#{@options[:icon_prefix]}#{name || @options[:icon_default]}"
|
106
94
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
95
|
+
if @options[:icon_position] == 'left'
|
96
|
+
"#{icon}#{label}".html_safe
|
97
|
+
else
|
98
|
+
"#{label}#{icon}".html_safe
|
112
99
|
end
|
100
|
+
end
|
113
101
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
end
|
102
|
+
def toggle_tag
|
103
|
+
"#{@options[:submenu_toggle]}".html_safe
|
104
|
+
end
|
118
105
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
106
|
+
def separator_tag(item)
|
107
|
+
tag :li, item[:label], class: @options[:separator_class]
|
108
|
+
end
|
109
|
+
|
110
|
+
def item_link_tag(item, icons = false)
|
111
|
+
label = tag :span, item[:label]
|
112
|
+
label = icon_tag("#{item[:icon]}", label) if icons.present?
|
113
|
+
label = label + toggle_tag if item[:children].present?
|
114
|
+
url = item_url(item)
|
123
115
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
label
|
128
|
-
label = label + toggle_tag if item[:children].present?
|
129
|
-
url = item_url(item)
|
130
|
-
|
131
|
-
if url.nil?
|
132
|
-
tag :a, label.html_safe, Hash(item[:html])
|
133
|
-
else
|
134
|
-
@context.link_to label.html_safe, url, Hash(item[:html])
|
135
|
-
end
|
116
|
+
if url.nil?
|
117
|
+
tag :a, label.html_safe, Hash(item[:html])
|
118
|
+
else
|
119
|
+
@context.link_to label.html_safe, url, Hash(item[:html])
|
136
120
|
end
|
121
|
+
end
|
137
122
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
active = @options[:active_submenu_class] if active.present?
|
123
|
+
def submenu_item_tag(item, active = false)
|
124
|
+
items = sort_items item[:children]
|
125
|
+
items = items.map { |_k, v| item_tag(v, @options[:submenu_icons], true) }.join
|
126
|
+
active = @options[:active_submenu_class] if active.present?
|
143
127
|
|
144
|
-
|
145
|
-
|
128
|
+
tag(:ul, items.html_safe, class: "#{active} #{@options[:submenu_class]}".strip)
|
129
|
+
end
|
146
130
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
content = link + submenu
|
131
|
+
def group_item_tag(item, icons = false)
|
132
|
+
active = @options[:active_class] if current_group?(item)
|
133
|
+
link = item_link_tag item, icons
|
134
|
+
submenu = submenu_item_tag item, active
|
135
|
+
content = link + submenu
|
153
136
|
|
154
|
-
|
155
|
-
|
137
|
+
tag :li, content.html_safe, class: "#{active} #{@options[:submenu_parent_class]}".strip
|
138
|
+
end
|
156
139
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
opts = opts.merge(class: "#{opts[:class]} #{active} #{iclass}".strip)
|
140
|
+
def single_item_tag(item, icons = false, subitem = false)
|
141
|
+
active = @options[:active_class] if current_page?(item)
|
142
|
+
iclass = subitem ? @options[:submenu_item_class] : @options[:item_class]
|
143
|
+
link = item_link_tag(item, icons)
|
144
|
+
opts = Hash(item[:wrapper_html])
|
145
|
+
opts = opts.merge(class: "#{opts[:class]} #{active} #{iclass}".strip)
|
164
146
|
|
165
|
-
|
166
|
-
|
147
|
+
tag :li, link.html_safe, opts
|
148
|
+
end
|
167
149
|
|
168
|
-
|
169
|
-
|
170
|
-
if render_item?(item)
|
171
|
-
if item[:separator].present?
|
172
|
-
separator_tag(item)
|
173
|
-
elsif item[:children].present?
|
174
|
-
group_item_tag(item, icons)
|
175
|
-
else
|
176
|
-
single_item_tag(item, icons, subitem)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
150
|
+
def item_tag(item, icons = false, subitem = false)
|
151
|
+
return unless render_item?(item)
|
180
152
|
|
181
|
-
|
182
|
-
|
183
|
-
|
153
|
+
if item[:separator].present?
|
154
|
+
separator_tag(item)
|
155
|
+
elsif item[:children].present?
|
156
|
+
group_item_tag(item, icons)
|
157
|
+
else
|
158
|
+
single_item_tag(item, icons, subitem)
|
184
159
|
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def menu_tag(items)
|
163
|
+
tag :ul, items.html_safe, Hash(@options[:menu_html]).merge(class: @options[:menu_class])
|
164
|
+
end
|
185
165
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
value
|
194
|
-
end
|
166
|
+
def mixed_value(value)
|
167
|
+
if value.is_a?(Proc)
|
168
|
+
@context.instance_exec(&value)
|
169
|
+
elsif value.is_a?(Symbol)
|
170
|
+
@context.send(value)
|
171
|
+
else
|
172
|
+
value
|
195
173
|
end
|
174
|
+
end
|
196
175
|
end
|
197
176
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_navigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonian Guveli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -73,7 +73,6 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- CODE_OF_CONDUCT.md
|
77
76
|
- Gemfile
|
78
77
|
- LICENSE.txt
|
79
78
|
- README.md
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at info@hardpixel.eu. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|