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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36c16b09d3a2279b54edd112603554924e5b52fc89d7438b4b53f30b83bec774
4
- data.tar.gz: b07f70d055ed8427e2b5500f17a23ba8278da3e9cbec3d072703c224a614dbd8
3
+ metadata.gz: 8d5ac40179ef25a551ff65d8387a6dd54bea6f1d6a763e075239d2914d7546e0
4
+ data.tar.gz: 2094525fb6e61a72b3cb475e0296bd9c95f179bb93a521a34a64e690d55df6bf
5
5
  SHA512:
6
- metadata.gz: 17dc4ece357920ef1423a65c1a12ecf421f7e6715afac2062b741e874e88339e1d45de2d094ecca6e45203ba098f6149a99e6924ad5fbaae5d39f623189e6a82
7
- data.tar.gz: 8f3f8f2d48c73c7267f09398dbfc1277722fbe7e1a94b993bcd9f2ac3252a94ff3caae891edc9e0cb0384cb5304deca837000aa45fb877b60460128691ca1b41
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. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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).
@@ -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
- # Render navigation builder
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
- # Initialize builder
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
- # Default options
18
- def default_options
19
- {
20
- menu_class: 'menu',
21
- menu_html: {},
22
- menu_icons: true,
23
- item_class: 'menu-item',
24
- separator_class: 'separator',
25
- submenu_parent_class: 'has-submenu',
26
- submenu_class: 'submenu',
27
- submenu_item_class: 'submenu-item',
28
- active_class: 'active',
29
- active_submenu_class: 'open',
30
- submenu_icons: false,
31
- submenu_toggle: nil,
32
- icon_prefix: 'icon icon-',
33
- icon_default: 'missing',
34
- icon_position: 'left',
35
- keep_defaults: true
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
- # Get merged options
40
- def merge_options(options)
41
- if options[:keep_defaults] == false
42
- options
43
- else
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
- # Sort items by order
49
- def sort_items(items)
50
- items.sort_by { |_k, v| v[:order] }.to_h
51
- end
44
+ def sort_items(items)
45
+ items.sort_by { |_k, v| v[:order] }.to_h
46
+ end
52
47
 
53
- # Check if url parent
54
- def page_parent?(item)
55
- url = item_url item
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
- url.present? && item[:root].blank? && paths.any? { |i| i.starts_with?(url) }
59
- end
52
+ url.present? && item[:root].blank? && paths.any? { |i| i.starts_with?(url) }
53
+ end
60
54
 
61
- # Get menu item url
62
- def item_url(item)
63
- if item[:url].present?
64
- mixed_value(item[:url])
65
- elsif item[:id].present?
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
- # Check if should render item
71
- def render_item?(item)
72
- if item[:if]
73
- mixed_value(item[:if]).present?
74
- elsif item[:unless]
75
- mixed_value(item[:unless]).blank?
76
- else
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
- # Check if current page
82
- def current_page?(item)
83
- current = @context.current_page?(item_url(item))
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
- current
87
- end
77
+ current
78
+ end
88
79
 
89
- # Check if current group
90
- def current_group?(item)
91
- current = current_page?(item)
92
- current = Hash(item[:children]).any? { |_k, v| current_page?(v) } if current.blank?
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
- current
96
- end
85
+ current
86
+ end
97
87
 
98
- # Create html tag
99
- def tag(*args, &block)
100
- @context.content_tag(*args, &block)
101
- end
88
+ def tag(*args, &block)
89
+ @context.content_tag(*args, &block)
90
+ end
102
91
 
103
- # Create menu icon
104
- def icon_tag(name, label=nil)
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
- if @options[:icon_position] == 'left'
108
- "#{icon}#{label}".html_safe
109
- else
110
- "#{label}#{icon}".html_safe
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
- # Create submenu toggle tag
115
- def toggle_tag
116
- "#{@options[:submenu_toggle]}".html_safe
117
- end
102
+ def toggle_tag
103
+ "#{@options[:submenu_toggle]}".html_safe
104
+ end
118
105
 
119
- # Create menu separator
120
- def separator_tag(item)
121
- tag :li, item[:label], class: @options[:separator_class]
122
- end
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
- # Create item link
125
- def item_link_tag(item, icons=false)
126
- label = tag :span, item[:label]
127
- label = icon_tag("#{item[:icon]}", label) if icons.present?
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
- # Create submenu item
139
- def submenu_item_tag(item, active=false)
140
- items = sort_items item[:children]
141
- items = items.map { |_k, v| item_tag(v, @options[:submenu_icons], true) }.join
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
- tag(:ul, items.html_safe, class: "#{active} #{@options[:submenu_class]}".strip)
145
- end
128
+ tag(:ul, items.html_safe, class: "#{active} #{@options[:submenu_class]}".strip)
129
+ end
146
130
 
147
- # Create group menu item
148
- def group_item_tag(item, icons=false)
149
- active = @options[:active_class] if current_group?(item)
150
- link = item_link_tag item, icons
151
- submenu = submenu_item_tag item, active
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
- tag :li, content.html_safe, class: "#{active} #{@options[:submenu_parent_class]}".strip
155
- end
137
+ tag :li, content.html_safe, class: "#{active} #{@options[:submenu_parent_class]}".strip
138
+ end
156
139
 
157
- # Create single menu item
158
- def single_item_tag(item, icons=false, subitem=false)
159
- active = @options[:active_class] if current_page?(item)
160
- iclass = subitem ? @options[:submenu_item_class] : @options[:item_class]
161
- link = item_link_tag(item, icons)
162
- opts = Hash(item[:wrapper_html])
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
- tag :li, link.html_safe, opts
166
- end
147
+ tag :li, link.html_safe, opts
148
+ end
167
149
 
168
- # Create menu list item
169
- def item_tag(item, icons=false, subitem=false)
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
- # Create menu list
182
- def menu_tag(items)
183
- tag :ul, items.html_safe, Hash(@options[:menu_html]).merge(class: @options[:menu_class])
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
- # Parse mixed value
187
- def mixed_value(value)
188
- if value.is_a?(Proc)
189
- @context.instance_exec(&value)
190
- elsif value.is_a?(Symbol)
191
- @context.send(value)
192
- else
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
@@ -1,3 +1,3 @@
1
1
  module SmartNavigation
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  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.1
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: 2018-05-31 00:00:00.000000000 Z
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/