menuizer 0.1.8 → 0.1.9

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmJkMTdhZjY0YmI0N2E1NjU4MjNmYzNlODIzY2I2MTU3YzE4NDQxZg==
4
+ NGFkZjNiZjMxOGE4NTEzMDZkYjA4ZjNhMmU4MmZkZWJiNDM5Y2QyOA==
5
5
  data.tar.gz: !binary |-
6
- ZThjNDAxYzBjODU1ZTliZGZlMzgxNTMzYzZiZmMyMzU2M2MyMWQ1MQ==
6
+ NDA4MjA2MTg3MTY2ZDZlZjhkYTlkN2Y5NDFjN2UxNjE0ZWRhM2YxMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmU0MjkwYmY5ODliMjY4OWUyM2JlNWYyYTFlYTRkZDA4ZDhiNTlmNWQ5ZDE0
10
- OGZhZGU5Y2E3NTFmODYzNWI5ZGI1MTZmODFlMzVlMjc3YzQwOTMxODdjZmU3
11
- ODExYmVkMmY0NmQ0YjRiNGUxY2M1MzEyZjNlNmJkOWY3M2QxODI=
9
+ NTU1ZjRkODFhMWMxYTE4ODljZmQ5YTAwZjZmYjA4ZDk3ODAzMTEzZTFlOWRm
10
+ ZmM2NmY5YTgxMzk1NDllNDZhYjg3MzAzYTQwODc5ZTBjYTVkMThkZGU3NmUz
11
+ Nzc5NDlkOTMyOGRjMDQ4YTYxMmJmYzE0MjAyNDIzNWMyNTJhMjc=
12
12
  data.tar.gz: !binary |-
13
- Mzk5MWI3ZGVhY2VlM2VkNmNkYjM1M2QwZjIzZTU5N2RiZTQwYjA4ZDRiMTM5
14
- NGIyNTRkOThlNTg5ZWQ4MmU1NzI1Y2NjMzAyNmY5MTdhY2FhZTYzNzUxYWZj
15
- ZDJlNjM4NWYxY2JhNzgyMTllMzk3OWZjZDE0ZDYwODQ0YWY2MGU=
13
+ NTU1M2MzNzIxNTNiN2MwOTE4MzZmYjIyYzRmOGE4NWZlMzYwMDhmYTc4OTQ4
14
+ ZGY1MTE4MjMyYjhjMmE1ZmFjYzg5NDdjM2EzYzRkZmY2OGViMThjZDQ5NzUw
15
+ M2QwNzE5NDAxN2U4MTRlMzEwMDI5YjFkMzk2NjdmZTYzODc3MDg=
data/README.md CHANGED
@@ -183,6 +183,24 @@ end
183
183
  </ul>
184
184
  ```
185
185
 
186
+ ## set converter methods
187
+
188
+ ```ruby
189
+ # config/initializers/menuizer.rb
190
+ Menuizer.configure(:namespace) do |menu|
191
+ menu.set_converter :icon do |icon,opts|
192
+ case
193
+ when icon.blank? || icon.starts_with?("fa") then icon
194
+ when icon then "fa fa-#{icon.to_s.gsub("_","-")}"
195
+ else
196
+ "fa fa-circle-o"
197
+ end
198
+ end
199
+ end
200
+ ```
201
+
202
+ second argument `opts` : original key-value hash
203
+
186
204
  ## Development
187
205
 
188
206
  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.
@@ -1,22 +1,24 @@
1
1
  class Menuizer::Menu::Item < OpenStruct
2
- def initialize(public_hash,opts)
3
- super(public_hash)
2
+ def initialize(opts)
3
+ super
4
4
  @opts = opts
5
5
  end
6
6
 
7
7
  def title
8
- if @opts[:title].respond_to?(:model_name) && @opts[:title].model_name.respond_to?(:human)
9
- @opts[:title].model_name.human
8
+ title = @opts[:title]
9
+ if title.respond_to?(:model_name) && title.model_name.respond_to?(:human)
10
+ title.model_name.human
10
11
  else
11
- @opts[:title]
12
+ title
12
13
  end
13
14
  end
14
15
  def path
15
- if @opts[:path]
16
- @opts[:path]
16
+ if path = @opts[:path]
17
+ path
17
18
  else
18
- if @opts[:title].respond_to?(:model_name) && @opts[:title].model_name.respond_to?(:plural)
19
- :"#{@opts[:namespace]}#{@opts[:title].model_name.plural}"
19
+ title = @opts[:title]
20
+ if title.respond_to?(:model_name) && title.model_name.respond_to?(:plural)
21
+ :"#{namespace}#{title.model_name.plural}"
20
22
  end
21
23
  end
22
24
  end
data/lib/menuizer/menu.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  class Menuizer::Menu
2
2
  def initialize(namespace)
3
- @namespace = namespace ? "#{namespace}_" : nil
3
+ if namespace
4
+ @namespace = "#{namespace}_"
5
+ @item_class = self.class.const_set(:"Item_#{namespace}", Class.new(Item))
6
+ else
7
+ @namespace = nil
8
+ @item_class = Item
9
+ end
4
10
  end
5
11
 
6
12
  def activate(key)
@@ -24,43 +30,48 @@ class Menuizer::Menu
24
30
  result << item
25
31
  item = item.parent
26
32
  end
27
- result
33
+ result.reverse
34
+ end
35
+
36
+ def set_converter(key,&block)
37
+ @item_class.class_eval do
38
+ define_method key do
39
+ block.call @opts[key], @opts
40
+ end
41
+ end
28
42
  end
29
43
 
30
44
 
31
45
  def header(title)
32
- current << Item.new({
46
+ current << @item_class.new(
33
47
  type: :header,
34
- },{
35
48
  namespace: @namespace,
36
49
  title: title,
37
- })
50
+ )
38
51
  end
39
52
  def item(title, path: nil, **opts)
40
53
  unless block_given?
41
- item = Item.new({
54
+ item = @item_class.new(
42
55
  type: :item,
43
56
  parent: @parent,
44
- **opts,
45
- },{
46
57
  namespace: @namespace,
47
58
  title: title,
48
59
  path: path,
49
- })
60
+ **opts,
61
+ )
50
62
  map[title] = item
51
63
  current << item
52
64
  else
53
65
  owner = @parent
54
66
  parents = @current
55
- item = @parent = Item.new({
67
+ item = @parent = @item_class.new(
56
68
  type: :tree,
57
69
  children: [],
58
70
  parent: owner,
59
- **opts,
60
- },{
61
71
  namespace: @namespace,
62
72
  title: title,
63
- })
73
+ **opts,
74
+ )
64
75
  @current = item.children
65
76
  yield
66
77
  children, @current, @parent = @current, parents, owner
@@ -80,21 +91,4 @@ class Menuizer::Menu
80
91
  def map
81
92
  @map ||= {}
82
93
  end
83
-
84
- def to_title(title)
85
- if title.respond_to?(:model_name)
86
- title.model_name.human
87
- else
88
- title
89
- end
90
- end
91
- def to_path(path:, title:)
92
- if path
93
- path
94
- else
95
- if title.respond_to?(:model_name)
96
- :"#{@namespace}#{title.model_name.plural}_path"
97
- end
98
- end
99
- end
100
94
  end
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.9
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: menuizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - shun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-04 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler