smart_navigation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 322510ff431e621ac05e9a7114fc15ad656bd6be
4
+ data.tar.gz: 4257511a0085900ef8be0f89bb0a7bb105da50b3
5
+ SHA512:
6
+ metadata.gz: 6fa49d788f5b38b65c19688393888c3b19a991e6eec39048d2bfda5d0382e3c25407cde74aad5b2ba0f7ee5c0d07df37e7de801e17da59711ecbce5f9933e199
7
+ data.tar.gz: 68a2d5cdf34287d02cbd335c832d42a5fd05ab09a7d18f5be4386b80f79c518ba0347fba8f80588f4910f4f9e3015280563f3c4245d34a2a136d6bacdd861467
@@ -0,0 +1,74 @@
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/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smart_navigation.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jonian Guveli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # SmartNavigation
2
+
3
+ View helpers for navigation menus. Build navigation menus from hash configs.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/smart_navigation.svg)](https://badge.fury.io/rb/smart_navigation)
6
+ [![Build Status](https://travis-ci.org/hardpixel/smart-navigation.svg?branch=master)](https://travis-ci.org/hardpixel/smart-navigation)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c484472c3989ff4a7c33/maintainability)](https://codeclimate.com/github/hardpixel/smart-navigation/maintainability)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'smart_navigation'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install smart_navigation
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`.
32
+
33
+ ## Contributing
34
+
35
+ 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.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the ActiveContent 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/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,11 @@
1
+ module SmartNavigation
2
+ module Helper
3
+ # Render navigation builder
4
+ def smart_navigation_for(items, options={})
5
+ SmartNavigation::Renderer.new(self, items, options).render
6
+ end
7
+
8
+ # Alias helper method
9
+ alias :navigation_for :smart_navigation_for
10
+ end
11
+ end
@@ -0,0 +1,108 @@
1
+ module SmartNavigation
2
+ class Renderer
3
+ # Initialize builder
4
+ def initialize(view_context, items, options={})
5
+ @context = view_context
6
+ @items = sort_items items
7
+ @menu_class = options.fetch :menu_class, 'menu'
8
+ @sep_class = options.fetch :separator_class, 'separator'
9
+ @group_class = options.fetch :group_class, 'menu-group'
10
+ @submenu_class = options.fetch :submenu_class, 'submenu'
11
+ @active_class = options.fetch :active_class, 'active'
12
+ @active_submenu_class = options.fetch :active_submenu_class, 'open'
13
+ @submenu_icons = options.fetch :submenu_icons, false
14
+ end
15
+
16
+ # Sort items by order
17
+ def sort_items(items)
18
+ items.sort_by { |_k, v| v[:order] }.to_h
19
+ end
20
+
21
+ # Get menu item url
22
+ def item_url(item)
23
+ params = { controller: item[:controller], action: item[:action] }
24
+ params[:action] ? url_for(params) : "##{item[:id]}"
25
+ end
26
+
27
+ # Check if current page
28
+ def current_page?(item)
29
+ url = item_url(item)
30
+ @context.current_page?(url)
31
+ end
32
+
33
+ # Check if current group
34
+ def current_group?(item)
35
+ current = item[:children].any? { |_k, v| current_page?(v) }
36
+ current = item[:children].any? { |_k, v| current_group?(v) } if current.blank?
37
+ current
38
+ end
39
+
40
+ # Create menu separator
41
+ def separator_tag(item)
42
+ content_tag :li, item[:label], class: @sep_class
43
+ end
44
+
45
+ # Create item link
46
+ def item_link_tag(item, icons=false)
47
+ arrow = content_tag :span, icon('angle-left pull-right'), class: 'pull-right-container'
48
+ label = content_tag :span, item[:label]
49
+ label = icon("#{item[:icon]}") + label if icons.present?
50
+ label = label + arrow if item[:children].present?
51
+
52
+ link_to label.html_safe, item_url(item)
53
+ end
54
+
55
+ # Create submenu item
56
+ def submenu_item_tag(item, active=false)
57
+ items = sort_items item[:children]
58
+ items = items.map { |_k, v| item_tag(v, @submenu_icons) }.join
59
+ active = @active_submenu_class if active.present?
60
+
61
+ content_tag(:ul, items.html_safe, class: "#{active} #{@submenu_class}")
62
+ end
63
+
64
+ # Create group menu item
65
+ def group_item_tag(item, icons=false)
66
+ active = @active_class if current_group?(item)
67
+ link = item_link_tag item, icons
68
+ submenu = submenu_item_tag item, active
69
+ content = link + submenu
70
+
71
+ content_tag :li, content.html_safe, class: "#{active} #{@group_class}"
72
+ end
73
+
74
+ # Create single menu item
75
+ def single_item_tag(item, icons=false)
76
+ active = @active_class if current_page?(item)
77
+ link = item_link_tag(item, icons)
78
+
79
+ content_tag :li, link.html_safe, class: "#{active}"
80
+ end
81
+
82
+ # Create menu list item
83
+ def item_tag(item, icons=false)
84
+ if item[:separator].present?
85
+ separator_tag(item)
86
+ elsif item[:children].present?
87
+ group_item_tag(item, icons)
88
+ else
89
+ single_item_tag(item, icons)
90
+ end
91
+ end
92
+
93
+ # Create menu list
94
+ def menu_tag(items)
95
+ content_tag :ul, items.html_safe, class: @menu_class
96
+ end
97
+
98
+ # Render menu
99
+ def render
100
+ menu_tag @items.map { |k, v| item_tag(v, true) }.join
101
+ end
102
+
103
+ # Get app helpers if method is missing
104
+ def method_missing(method, *args, &block)
105
+ @context.respond_to?(method) ? @context.send(method, *args, &block) : super
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,3 @@
1
+ module SmartNavigation
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_support'
2
+ require 'smart_navigation/version'
3
+
4
+ module SmartNavigation
5
+ extend ActiveSupport::Autoload
6
+
7
+ # Autoload modules
8
+ autoload :Renderer
9
+ autoload :Helper
10
+ end
11
+
12
+ # Include action view helpers
13
+ if defined? ActionView::Base
14
+ ActionView::Base.send :include, SmartNavigation::Helper
15
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_navigation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonian Guveli
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.14'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.14'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '5.0'
75
+ description: View helpers for navigation menus. Build navigation menus from hash configs.
76
+ email:
77
+ - jonian@hardpixel.eu
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - lib/smart_navigation.rb
88
+ - lib/smart_navigation/helper.rb
89
+ - lib/smart_navigation/renderer.rb
90
+ - lib/smart_navigation/version.rb
91
+ homepage: https://github.com/hardpixel/smart-navigation
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.13
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: View helpers for navigation menus
115
+ test_files: []