menuizer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTFkZWI1NDljM2M1MmE2ZjZkODRmMGU1NzM1NzYzMmZiYTc4NjE4NA==
4
+ YjkzYmM0MGQ2YWIxMDQ1MTU2ZjFjMDNkZDZmNjNlYjllODVhMjAxYw==
5
5
  data.tar.gz: !binary |-
6
- NWM3YTUxZjFlMGRlYTRlNmY1MTA5Zjg3ODM3MTg5Y2VjNzIxMmQ1ZQ==
6
+ ZmQxNTBmY2EwNDAyZjE5MTRmMmQ1ZDliNzMxOWNkMjk5Y2QwNTZlZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2UxOTUzNmNlNzViOTk1YzA4YmEwNmJkNjFjOGRkYjNiN2NiNmJkN2Q5YjRk
10
- Y2ZiOTY4MzkzOWRhNDA2M2YwNWMwOWJmOTQzYzc1YTRkNDVkYmMzOGQ4MjU4
11
- ZDNjYmU0OTFmMGIwMzc5NjdiMjNlMDY4MmMwZjNjZTg2YTM1ZmM=
9
+ ODI4ZTkzMTZiM2ZjODYzNDQ1Y2VlMmZlNzJlOWI3YTJjMjE2YjM5M2VlZWI2
10
+ N2EyNDcyNTgzMGRjNDg4ZmVkZmJjOWYzNTAzMmQxMjMyYjRkMDlkZDA0YzVm
11
+ Yzg2MTUxNzM5MjM5M2ZhMDQ2MDU3YjM2N2U3OTdhNjAyYjA5OGY=
12
12
  data.tar.gz: !binary |-
13
- NDY1NWNkNjEyZjE1YTNiZjI3NjNjMWJjNTI1Y2IxN2EyMjc3MTQyZjJmZWNi
14
- ZjlkNmIyMDMwOWI2YWU0ZWQyNzkzMzU3NGYwNWU2MzliOGI2NGY4Y2Q5ZDA2
15
- MDQ5NzA2ZGIyYjAzNzg4NDUwZGRkZjIwZmQyMGVmMDAzYjNkYjU=
13
+ MjgzODQwNTQ2NDVmMGM4ZjZlN2RiNjFkZjUwMmU2ZDAzODIwODQ0OTA3OWRi
14
+ YzMwYzU2YTQ0MGZkMTBiOGM1YzVlOGMxOGI3ZGM1NzhmOWM2NzBiYzEzOWY4
15
+ MGRhMTNkM2EyZjhiYzgyMjY2YzU2Y2NhMjY1NDc2M2VkYWE0YjQ=
data/README.md CHANGED
@@ -54,9 +54,9 @@ end
54
54
  - item: Settings
55
55
  icon: fa fa-cog
56
56
  children:
57
- - item: :admins
57
+ - item: :admin
58
58
  icon: fa fa-circle-o
59
- - item: :users
59
+ - item: :user
60
60
  icon: fa fa-circle-o
61
61
 
62
62
  - item: nested
@@ -74,7 +74,7 @@ class ApplicationController < ActionController::Base
74
74
 
75
75
  def set_menuizer
76
76
  @menuizer = Menuizer.menu
77
- # or, pass data
77
+ # or
78
78
  # @menuizer = Menuizer.menu(request: request)
79
79
  # @menuizer.data[:request] #=> request
80
80
  end
@@ -86,7 +86,7 @@ end
86
86
 
87
87
  ```erb
88
88
  <%# app/views/admins/index.html.erb %>
89
- <% menuizer.activate :admins # item's value %>
89
+ <% menuizer.activate :admin # item's value %>
90
90
  <% content_for :title do %><%= menuizer.active_item.try(:title) %><% end %>
91
91
 
92
92
  ...
@@ -142,7 +142,30 @@ end
142
142
  ### get item
143
143
 
144
144
  ```ruby
145
- menuizer.item(:widgets) #=> menu item
145
+ menuizer.item(:admin) #=> menu item
146
+ ```
147
+
148
+ ### short cut
149
+
150
+ ```yaml
151
+ - item: :admin
152
+ # =>
153
+ # path:
154
+ # - :admins
155
+ ```
156
+
157
+ (auto convert path)
158
+
159
+ ## i18n
160
+
161
+ ```yaml
162
+ ja:
163
+ menuizer:
164
+ admin: Admin Title
165
+ # or
166
+ activerecord:
167
+ models:
168
+ admin: Admin Title
146
169
  ```
147
170
 
148
171
  ## Generators
@@ -181,10 +204,12 @@ Convert menu item's property:
181
204
  # config/initializers/menuizer.rb
182
205
  Menuizer.configure do |config|
183
206
  config.converter = {
184
- icon: ->(icon,opts){
207
+ icon: ->(value,opts){
208
+ # value : item.#{key} value
209
+ # opts : item yml data
185
210
  case
186
- when icon.blank? || icon.starts_with?("fa") then icon
187
- when icon then "fa fa-#{icon}"
211
+ when value.blank? || value.starts_with?("fa") then value
212
+ when value then "fa fa-#{value}"
188
213
  else
189
214
  "fa fa-circle-o"
190
215
  end
@@ -193,15 +218,16 @@ Menuizer.configure do |config|
193
218
  end
194
219
  ```
195
220
 
196
- ```ruby
197
- menuizer.items.each do |item|
198
- item.icon #=> "fa fa-circle-o" <= converter[:icon].call(icon,opts)
199
- end
221
+ ```yaml
222
+ - item: no icon
223
+ - item: enverope
224
+ icon: enverope
200
225
  ```
201
226
 
202
- icon, opts is yaml's original value
203
- opts: all key-value hash
204
-
227
+ ```ruby
228
+ menuizer.item("no icon").icon # => "fa fa-circle-o"
229
+ menuizer.item("envelope").icon # => "fa fa-envelope"
230
+ ```
205
231
 
206
232
  ### auto converters
207
233
 
@@ -215,7 +241,7 @@ I18n.translate "menuizer.#{item}", defaults: ["activerecord.models.#{item}","#{i
215
241
 
216
242
  **path**
217
243
 
218
- if not specified, and item is symbol: `[namespace,item]`
244
+ if not specified, and item is symbol: `[namespace,item.to_s.pluralize.to_sym]`
219
245
 
220
246
  **what is namespace?**
221
247
 
@@ -235,7 +261,7 @@ end
235
261
  ```yaml
236
262
  # config/menuizer/namespace.yml
237
263
  - header: NAMESPACE MENU
238
- - item: :admins
264
+ - item: :admin
239
265
  ```
240
266
 
241
267
  ```ruby
@@ -12,21 +12,19 @@ class Menuizer::Menu::Item < OpenStruct
12
12
  end
13
13
  end
14
14
  def path
15
- if path = @opts[:path]
15
+ unless path = @opts[:path]
16
+ case item
17
+ when Symbol
18
+ path = [item.to_s.pluralize.to_sym]
19
+ end
20
+ end
21
+
22
+ if path
16
23
  if namespace
17
24
  [namespace[0..-2].to_sym,*path]
18
25
  else
19
26
  path
20
27
  end
21
- else
22
- case item
23
- when Symbol
24
- if namespace
25
- [namespace[0..-2].to_sym,item]
26
- else
27
- [item]
28
- end
29
- end
30
28
  end
31
29
  end
32
30
  end
data/lib/menuizer.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "i18n"
2
+ require "active_support/inflector"
2
3
 
3
4
  require "menuizer/version"
4
5
  require "menuizer/menu"
data/menuizer.gemspec CHANGED
@@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "travis"
37
37
 
38
38
  spec.add_dependency "i18n"
39
+ spec.add_dependency "activesupport"
39
40
  end
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: menuizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - shun
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: build menu items for admin page ( like AdminLTE )
84
98
  email:
85
99
  - shun@getto.systems