structured_menus 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bf8638465b18ff55d7769def7e225ec37d0a3e4
4
- data.tar.gz: 2e7c8564de3bbf3aa00d68a18452197c01700446
3
+ metadata.gz: 35fdf0f4c1a6a53ce6cd0cd7a9321b140b7a3b12
4
+ data.tar.gz: c06806a04da79cd69a6fe72b482429f6a3d64e15
5
5
  SHA512:
6
- metadata.gz: 6c715ac46996d845698dc886904c00c16a8b27dabfc9978a62fa888eb4106885cea33d22be5f77dfdd4df458781448a91c10d805c3b1970564295eae3cd7e08c
7
- data.tar.gz: fc3b254949da858edc0deb1a3e438796f7c144bcf27a2f71688f3799af1dc98f99e9f89493e0a7e1ed1140e7ee4c21f31add909fd459e95ae3f288c630c4b805
6
+ metadata.gz: 3169ec2a454240abfe33b2c2d8f9de7292ee7f583fab6fd7a27dc63f30e3a3d98f96ab3f3258b4dc546d62951d2d3f532775137ae3096e308a06450864946167
7
+ data.tar.gz: bce213b07a67fc149d274e8e3b7f252728fa0ef657c2e012ec2b5498439397047e9a15087cc8aebdad93d7157d4541934a02bb7902f0c6736a2a370f545af1d5
@@ -0,0 +1,142 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ structured_menus (0.0.1)
5
+ rails (~> 5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.0)
11
+ actionpack (= 5.2.0)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.0)
15
+ actionpack (= 5.2.0)
16
+ actionview (= 5.2.0)
17
+ activejob (= 5.2.0)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.0)
21
+ actionview (= 5.2.0)
22
+ activesupport (= 5.2.0)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.0)
28
+ activesupport (= 5.2.0)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.0)
34
+ activesupport (= 5.2.0)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.0)
37
+ activesupport (= 5.2.0)
38
+ activerecord (5.2.0)
39
+ activemodel (= 5.2.0)
40
+ activesupport (= 5.2.0)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.0)
43
+ actionpack (= 5.2.0)
44
+ activerecord (= 5.2.0)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.0)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ arel (9.0.0)
52
+ builder (3.2.3)
53
+ concurrent-ruby (1.0.5)
54
+ crass (1.0.4)
55
+ diff-lcs (1.3)
56
+ erubi (1.7.1)
57
+ globalid (0.4.1)
58
+ activesupport (>= 4.2.0)
59
+ i18n (1.0.1)
60
+ concurrent-ruby (~> 1.0)
61
+ loofah (2.2.2)
62
+ crass (~> 1.0.2)
63
+ nokogiri (>= 1.5.9)
64
+ mail (2.7.0)
65
+ mini_mime (>= 0.1.1)
66
+ marcel (0.3.2)
67
+ mimemagic (~> 0.3.2)
68
+ method_source (0.9.0)
69
+ mimemagic (0.3.2)
70
+ mini_mime (1.0.0)
71
+ mini_portile2 (2.3.0)
72
+ minitest (5.11.3)
73
+ nio4r (2.3.1)
74
+ nokogiri (1.8.3)
75
+ mini_portile2 (~> 2.3.0)
76
+ rack (2.0.5)
77
+ rack-test (1.0.0)
78
+ rack (>= 1.0, < 3)
79
+ rails (5.2.0)
80
+ actioncable (= 5.2.0)
81
+ actionmailer (= 5.2.0)
82
+ actionpack (= 5.2.0)
83
+ actionview (= 5.2.0)
84
+ activejob (= 5.2.0)
85
+ activemodel (= 5.2.0)
86
+ activerecord (= 5.2.0)
87
+ activestorage (= 5.2.0)
88
+ activesupport (= 5.2.0)
89
+ bundler (>= 1.3.0)
90
+ railties (= 5.2.0)
91
+ sprockets-rails (>= 2.0.0)
92
+ rails-dom-testing (2.0.3)
93
+ activesupport (>= 4.2.0)
94
+ nokogiri (>= 1.6)
95
+ rails-html-sanitizer (1.0.4)
96
+ loofah (~> 2.2, >= 2.2.2)
97
+ railties (5.2.0)
98
+ actionpack (= 5.2.0)
99
+ activesupport (= 5.2.0)
100
+ method_source
101
+ rake (>= 0.8.7)
102
+ thor (>= 0.18.1, < 2.0)
103
+ rake (10.5.0)
104
+ rspec (3.7.0)
105
+ rspec-core (~> 3.7.0)
106
+ rspec-expectations (~> 3.7.0)
107
+ rspec-mocks (~> 3.7.0)
108
+ rspec-core (3.7.1)
109
+ rspec-support (~> 3.7.0)
110
+ rspec-expectations (3.7.0)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.7.0)
113
+ rspec-mocks (3.7.0)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.7.0)
116
+ rspec-support (3.7.1)
117
+ sprockets (3.7.2)
118
+ concurrent-ruby (~> 1.0)
119
+ rack (> 1, < 3)
120
+ sprockets-rails (3.2.1)
121
+ actionpack (>= 4.0)
122
+ activesupport (>= 4.0)
123
+ sprockets (>= 3.0.0)
124
+ thor (0.20.0)
125
+ thread_safe (0.3.6)
126
+ tzinfo (1.2.5)
127
+ thread_safe (~> 0.1)
128
+ websocket-driver (0.7.0)
129
+ websocket-extensions (>= 0.1.0)
130
+ websocket-extensions (0.1.3)
131
+
132
+ PLATFORMS
133
+ ruby
134
+
135
+ DEPENDENCIES
136
+ bundler (~> 1.16)
137
+ rake (~> 10.0)
138
+ rspec (~> 3.0)
139
+ structured_menus!
140
+
141
+ BUNDLED WITH
142
+ 1.16.0
data/README.md CHANGED
@@ -2,10 +2,123 @@
2
2
  An easy way to create flexible menus for Rails apps.
3
3
 
4
4
  ## Installation
5
- TBC
5
+ Add this line to your Gemfile and run `bundle install`:
6
+
7
+ gem 'structured_menus'
8
+
9
+ Next, create a configuration file in `config/initializers`, probably called `structured_menus.rb` because convention, and add the following to it:
10
+
11
+ ```ruby
12
+ StructuredMenus::Configurator.configure do |config|
13
+ # You don't have to add anything here, if you like the defaults, but you still need to call `configure`.
14
+ end
15
+ ```
16
+
17
+ ## Quick Start
18
+ Once you've done the above, create `app/menus/menu.yml`, and add the following to it:
19
+
20
+ ```yaml
21
+ - name: FAQ
22
+ icon: question
23
+ link: /faq
24
+ ```
25
+
26
+ In the view in which you want to display the menu, add this code:
27
+
28
+ ```erb
29
+ <%= Rails.menus.show :menu, :dashboard, current_user %>
30
+ ```
31
+
32
+ You can substitute `:dashboard` for `:dropdown` if you want a Bootstrap dropdown menu instead; if you don't have a `current_user` method, use `nil`.
33
+
34
+ Continue reading for more detailed usage options.
6
35
 
7
36
  ## Usage
8
- TBC
37
+ StructuredMenus enables you to create menus for your app by writing YAML files in (by default) `app/menus`. Each file is a menu; each item in the file
38
+ becomes an item on your menu, displayed according to the adapter (more on that later) and options you specify. Such a file might look like this:
39
+
40
+ ```yaml
41
+ - name: Admin
42
+ icon: cogs
43
+ link: /admin
44
+ if: 'lambda { |u| u&.has_role?(:admin) }'
45
+
46
+ - name: CRM
47
+ icon: users
48
+ link: /crm
49
+
50
+ - name: Orders
51
+ icon: money-bill-alt
52
+ link: /orders
53
+ ```
54
+
55
+ Save that as `mymenu.yml`, and you'll be able to call `Rails.menus.show :mymenu, :dashboard, current_user` to pop it up anywhere in your app.
56
+
57
+ ### Adapters
58
+ Adapters are the bits that control how the menu is actually displayed. There are two included by default: `:dashboard` and `:dropdown`. Both are
59
+ designed to work with Bootstrap and FontAwesome (yes, I'm opinionated). Each adapter supports different options - see the definitions in
60
+ `lib/structured_menus/adapters` for details on what they are.
61
+
62
+ - **Dashboard** is designed to be a full-screen main menu type thing, probably for apps with lots of navigation. The example menu YAML shown above
63
+ looks like this when shown (some custom CSS - the topbar is not part of the menu):
64
+
65
+ [![](https://i.stack.imgur.com/n0sbQ.png)](https://i.stack.imgur.com/n0sbQ.png)
66
+
67
+ Use `:dashboard` in your call to `Rails.menus.show` to get this adapter.
68
+
69
+ - **Dropdown** is, well, a Bootstrap dropdown menu. It doesn't include icons by default, but you can make it do so if you want them. The same YAML
70
+ looks like this with the dropdown adapter:
71
+
72
+ [![](https://i.stack.imgur.com/rc1Ww.png)](https://i.stack.imgur.com/rc1Ww.png)
73
+
74
+ Use `:dropdown` in your call to `Rails.menus.show` to get this adapter.
75
+
76
+ #### Custom adapters
77
+ If those two don't suit your needs, you can write your own custom adapter. Essentially, this needs to emulate one of the two stock adapters, in that:
78
+
79
+ - It must respond to `#show`
80
+ - Calls to `#show` must respond with the string of raw HTML that you want to render.
81
+
82
+ For reference, here's what the dashboard adapter looks like:
83
+
84
+ ```ruby
85
+ module StructuredMenus::Adapters
86
+ class DashboardAdapter
87
+ include ActionView::Helpers::UrlHelper
88
+ include ActionView::Helpers::OutputSafetyHelper
89
+
90
+ def self.show(menu, user, **options)
91
+ inst = new
92
+ width = options[:width] || 4
93
+ cards = menu.map do |i|
94
+ next unless !i['if'] || instance_eval(i['if']).call(user)
95
+
96
+ cls = options[:class] || 'dashboard-menu-card'
97
+ inst.raw("<div class=\"#{cls}\">#{inst.link_to inst.raw("<i class=\"fas fa-#{i['icon']}\"></i> #{i['name']}"), i['link']}</div>")
98
+ end.compact
99
+
100
+ inst.raw(cards.in_groups_of(12 / width).map(&:compact).map do |g|
101
+ '<div class="row">' + g.map { |c| "<div class=\"col-md-#{12 / width}\">#{c}</div>" }.join("\n") + '</div>'
102
+ end.join("\n"))
103
+ end
104
+ end
105
+ end
106
+ ```
107
+
108
+ The parameters that will be passed to `#show` are as follows:
109
+
110
+ - `menu` - a parsed YAML file, in the form of an array. Each element is a hash representing a single menu item as specified in the file.
111
+ - `user` is the value passed to `Rails.menus.show`, which should be a reference to the current user. This can be `nil`.
112
+ - `**options` is a hash of additional options - it's up to you what you want to support. Look at the adapter files in `lib/structured_menus/adapters`
113
+ to see the options that the stock adapters support.
114
+
115
+ Once you've written your adapter, tell structured_menus about it by adding it to the configuration file:
116
+
117
+ ```ruby
118
+ StructuredMenus::Configurator.configure do |config|
119
+ config.adapters << YourCustomAdapterClass
120
+ end
121
+ ```
9
122
 
10
123
  ## Contributions
11
124
  Welcome. Ping me a PR. For large changes you should probably open an issue first to discuss.
@@ -20,7 +20,7 @@ module StructuredMenus::Adapters
20
20
  inst.raw("<div class=\"#{cls}\">#{inst.link_to inst.raw("<i class=\"fas fa-#{i['icon']}\"></i> #{i['name']}"), i['link']}</div>")
21
21
  end.compact
22
22
 
23
- inst.raw(cards.in_groups_of(12 / width).map(&:compact).map do |g|
23
+ inst.raw(cards.in_groups_of(width).map(&:compact).map do |g|
24
24
  '<div class="row">' + g.map { |c| "<div class=\"col-md-#{12 / width}\">#{c}</div>" }.join("\n") + '</div>'
25
25
  end.join("\n"))
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module StructuredMenus
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structured_menus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ArtOfCode-
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-29 00:00:00.000000000 Z
11
+ date: 2018-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -76,6 +76,7 @@ files:
76
76
  - ".gitignore"
77
77
  - ".rubocop.yml"
78
78
  - Gemfile
79
+ - Gemfile.lock
79
80
  - LICENSE.txt
80
81
  - README.md
81
82
  - lib/structured_menus.rb