structured_menus 0.0.1
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 +7 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +66 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +14 -0
- data/lib/structured_menus/adapters/dashboard_adapter.rb +28 -0
- data/lib/structured_menus/adapters/dropdown_adapter.rb +33 -0
- data/lib/structured_menus/configurator.rb +38 -0
- data/lib/structured_menus/dispatcher.rb +23 -0
- data/lib/structured_menus/version.rb +3 -0
- data/lib/structured_menus.rb +2 -0
- data/structured_menus.gemspec +25 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0bf8638465b18ff55d7769def7e225ec37d0a3e4
|
4
|
+
data.tar.gz: 2e7c8564de3bbf3aa00d68a18452197c01700446
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c715ac46996d845698dc886904c00c16a8b27dabfc9978a62fa888eb4106885cea33d22be5f77dfdd4df458781448a91c10d805c3b1970564295eae3cd7e08c
|
7
|
+
data.tar.gz: fc3b254949da858edc0deb1a3e438796f7c144bcf27a2f71688f3799af1dc98f99e9f89493e0a7e1ed1140e7ee4c21f31add909fd459e95ae3f288c630c4b805
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- '**/Rakefile'
|
4
|
+
- '**/config.ru'
|
5
|
+
Exclude:
|
6
|
+
- 'lib/**/*'
|
7
|
+
- 'bin/**/*'
|
8
|
+
- 'script/**/*'
|
9
|
+
- '**/*.json.jbuilder'
|
10
|
+
- 'vendor/bundle/**/*'
|
11
|
+
- 'node_modules/**/*'
|
12
|
+
- 'db/schema.rb' # auto-generated :(
|
13
|
+
- 'Capfile'
|
14
|
+
- 'config/routes.rb'
|
15
|
+
- 'config/initializers/devise.rb'
|
16
|
+
- 'test/**/*'
|
17
|
+
- 'vendor/**/*'
|
18
|
+
TargetRubyVersion: 2.4
|
19
|
+
|
20
|
+
Style/SymbolArray:
|
21
|
+
Enabled: false
|
22
|
+
Style/Documentation:
|
23
|
+
Enabled: false
|
24
|
+
Style/FileName:
|
25
|
+
Exclude:
|
26
|
+
- Gemfile
|
27
|
+
Style/FrozenStringLiteralComment:
|
28
|
+
EnforcedStyle: always
|
29
|
+
Enabled: true
|
30
|
+
Style/NumericPredicate:
|
31
|
+
AutoCorrect: true
|
32
|
+
EnforcedStyle: comparison
|
33
|
+
Enabled: true
|
34
|
+
Style/AsciiComments:
|
35
|
+
Enabled: false
|
36
|
+
Style/Lambda:
|
37
|
+
EnforcedStyle: literal
|
38
|
+
Style/TrivialAccessors:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
# Want to refactor some stuff? Remove these.
|
42
|
+
Metrics/AbcSize:
|
43
|
+
Enabled: false
|
44
|
+
Metrics/CyclomaticComplexity:
|
45
|
+
Enabled: false
|
46
|
+
Metrics/PerceivedComplexity:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Metrics/MethodLength:
|
50
|
+
Max: 100
|
51
|
+
Exclude:
|
52
|
+
- 'db/migrate/*'
|
53
|
+
Metrics/LineLength:
|
54
|
+
Max: 150
|
55
|
+
Metrics/ClassLength:
|
56
|
+
Enabled: false
|
57
|
+
Metrics/BlockLength:
|
58
|
+
Max: 30
|
59
|
+
ExcludedMethods:
|
60
|
+
- scope
|
61
|
+
- configure
|
62
|
+
- draw
|
63
|
+
- define
|
64
|
+
- test
|
65
|
+
- helpers
|
66
|
+
- field
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 ArtOfCode-
|
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,14 @@
|
|
1
|
+
# `structured_menus`
|
2
|
+
An easy way to create flexible menus for Rails apps.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
TBC
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
TBC
|
9
|
+
|
10
|
+
## Contributions
|
11
|
+
Welcome. Ping me a PR. For large changes you should probably open an issue first to discuss.
|
12
|
+
|
13
|
+
## License
|
14
|
+
Available under the terms of the MIT license.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module StructuredMenus::Adapters
|
2
|
+
class DashboardAdapter
|
3
|
+
include ActionView::Helpers::UrlHelper
|
4
|
+
include ActionView::Helpers::OutputSafetyHelper
|
5
|
+
|
6
|
+
# Accepted options:
|
7
|
+
#
|
8
|
+
# :if - only include this menu item if the provided block returns true when passed the current user (if not present, item is always included)
|
9
|
+
# :width - the number of cards to include in one row of the menu (max 12, default 4)
|
10
|
+
# :class - the CSS class to apply to each card's wrapper <div> (default dashboard-menu-card)
|
11
|
+
#
|
12
|
+
# You still need to provide your own styles for .dashboard-menu-card.
|
13
|
+
def self.show(menu, user, **options)
|
14
|
+
inst = new
|
15
|
+
width = options[:width] || 4
|
16
|
+
cards = menu.map do |i|
|
17
|
+
next unless !i['if'] || instance_eval(i['if']).call(user)
|
18
|
+
|
19
|
+
cls = options[:class] || 'dashboard-menu-card'
|
20
|
+
inst.raw("<div class=\"#{cls}\">#{inst.link_to inst.raw("<i class=\"fas fa-#{i['icon']}\"></i> #{i['name']}"), i['link']}</div>")
|
21
|
+
end.compact
|
22
|
+
|
23
|
+
inst.raw(cards.in_groups_of(12 / width).map(&:compact).map do |g|
|
24
|
+
'<div class="row">' + g.map { |c| "<div class=\"col-md-#{12 / width}\">#{c}</div>" }.join("\n") + '</div>'
|
25
|
+
end.join("\n"))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module StructuredMenus::Adapters
|
2
|
+
class DropdownAdapter
|
3
|
+
include ActionView::Helpers::UrlHelper
|
4
|
+
include ActionView::Helpers::OutputSafetyHelper
|
5
|
+
|
6
|
+
# Accepted options:
|
7
|
+
#
|
8
|
+
# :if - only include this menu item if the provided block returns true when passed the current user (if not present, item is always included)
|
9
|
+
# :include_icon - if true, include a FontAwesome icon (no fa- prefix) as specified by the `icon` property in the menu's YAML (default false)
|
10
|
+
# :include_ul - if true, wrap the dropdown <li> list in a <ul> (default true)
|
11
|
+
#
|
12
|
+
# With :include_icon, you still need to include FontAwesome yourself.
|
13
|
+
# With :include_ul, you still need to add the dropdown's trigger yourself.
|
14
|
+
def self.show(menu, user, **options)
|
15
|
+
inst = new
|
16
|
+
items = menu.map do |i|
|
17
|
+
next unless !i['if'] || instance_eval(i['if']).call(user)
|
18
|
+
|
19
|
+
if !options[:include_icon]
|
20
|
+
inst.raw("<li>#{inst.link_to i['name'], i['link']}</li>")
|
21
|
+
else
|
22
|
+
inst.raw("<li>#{inst.link_to inst.raw("<i class=\"fas fa-#{i['icon']}\"></i> #{i['name']}"), i['link']}</li>")
|
23
|
+
end
|
24
|
+
end.compact
|
25
|
+
|
26
|
+
if options[:include_ul] || options[:include_ul].nil?
|
27
|
+
inst.raw('<ul class="dropdown-menu">' + items.join("\n") + '</ul>')
|
28
|
+
else
|
29
|
+
inst.raw(items.join("\n"))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'dispatcher'
|
2
|
+
require_relative 'adapters/dashboard_adapter'
|
3
|
+
require_relative 'adapters/dropdown_adapter'
|
4
|
+
|
5
|
+
module StructuredMenus
|
6
|
+
@config = nil
|
7
|
+
|
8
|
+
def self.config
|
9
|
+
@config
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config=(val)
|
13
|
+
@config = val
|
14
|
+
end
|
15
|
+
|
16
|
+
class Configurator
|
17
|
+
attr_accessor :menus_directory, :adapters
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@menus_directory = Rails.root.join('app/menus')
|
21
|
+
@adapters = [Adapters::DashboardAdapter, Adapters::DropdownAdapter]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure
|
25
|
+
inst = new
|
26
|
+
yield inst
|
27
|
+
StructuredMenus.config = inst
|
28
|
+
|
29
|
+
Rails.module_eval do
|
30
|
+
@menus = StructuredMenus::Dispatcher.new
|
31
|
+
|
32
|
+
def self.menus
|
33
|
+
@menus
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module StructuredMenus
|
2
|
+
class Dispatcher
|
3
|
+
def initialize
|
4
|
+
menus_dir = StructuredMenus.config.menus_directory
|
5
|
+
@menus = Dir.entries(menus_dir).reject { |f| File.directory? f }\
|
6
|
+
.map { |p| [File.basename(p).gsub('.yml', ''), p] }.to_h.with_indifferent_access
|
7
|
+
@adapters = StructuredMenus.config.adapters.map do |an|
|
8
|
+
if an.class == Class
|
9
|
+
an
|
10
|
+
elsif an.class == String
|
11
|
+
require_relative an
|
12
|
+
File.basename(an).gsub('.rb', '').classify.constantize
|
13
|
+
end
|
14
|
+
end.map { |ac| [ac.name.demodulize.gsub('Adapter', '').underscore, ac] }.to_h.with_indifferent_access
|
15
|
+
end
|
16
|
+
|
17
|
+
def show(name, adapter_name, user, **options)
|
18
|
+
menu = YAML.safe_load(File.read(StructuredMenus.config.menus_directory.join(@menus[name])))
|
19
|
+
adapter = @adapters[adapter_name]
|
20
|
+
adapter.show(menu, user, **options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'structured_menus/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'structured_menus'
|
7
|
+
spec.version = StructuredMenus::VERSION
|
8
|
+
spec.authors = ['ArtOfCode-']
|
9
|
+
spec.email = ['hello@artofcode.co.uk']
|
10
|
+
|
11
|
+
spec.summary = 'An easy way to create flexible menus of things for Rails apps.'
|
12
|
+
spec.homepage = 'https://github.com/ArtOfCode-/structured_menus'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
|
24
|
+
spec.add_dependency 'rails', '~> 5'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: structured_menus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ArtOfCode-
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- hello@artofcode.co.uk
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- lib/structured_menus.rb
|
82
|
+
- lib/structured_menus/adapters/dashboard_adapter.rb
|
83
|
+
- lib/structured_menus/adapters/dropdown_adapter.rb
|
84
|
+
- lib/structured_menus/configurator.rb
|
85
|
+
- lib/structured_menus/dispatcher.rb
|
86
|
+
- lib/structured_menus/version.rb
|
87
|
+
- structured_menus.gemspec
|
88
|
+
homepage: https://github.com/ArtOfCode-/structured_menus
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.6.11
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: An easy way to create flexible menus of things for Rails apps.
|
112
|
+
test_files: []
|