nutmeg 0.0.6 → 0.0.7

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: d46add46ba66cdd0a75ef3f905581a56d19c52a9
4
- data.tar.gz: 0a823d5a6a20be742c214bdf56cbf7ff5ae1e432
3
+ metadata.gz: 328de2b1cddaf483b431b1f3e4fcec10b2c3851b
4
+ data.tar.gz: a9d0d4a3ad323816a03ccaec161c3d6c0afac3f2
5
5
  SHA512:
6
- metadata.gz: 13453f13317042df4e4fdd803ec9377f7f218453b0eba8472958ed5f2008d26834f7fb7c6947bdb9291053c621f040ec1b56118730a2c26d065264840b1578cb
7
- data.tar.gz: ab785e32e4ee8f80e4a111da75d3f8498d21c88a93eab0297dce37668523fb662cf45d6d742637f69db1bf667e948a19c6a458e2f51374dcdcb80b3cf395a448
6
+ metadata.gz: 7243ee36e01fe7eb8328afbb85fc645f7c00aefb3b555009521530c20bc9e39dd7354ef8680eab240dc64286c5fdc3695f44332369417d5a07e13e67dd0c51b6
7
+ data.tar.gz: 6f6fb531f2c4db264440b224a764a2a144ad5eba39b64eaf9f310ff7b231a478973dafadf61ec482058ac4f7e45cfa074aeee9429b238e2a7c7cd9d14effcc6b
@@ -1,17 +1,30 @@
1
1
  module Nutmeg
2
2
  class TagTreeHelper
3
3
  attr_accessor :tree
4
- def initialize(tree)
4
+ def initialize(tree, options = {})
5
5
  raise "No valid data type" unless tree.class == TagTree
6
+ @options = options
6
7
  @tree = tree
7
8
  end
8
9
 
10
+ def prepend_path
11
+ @options[:prepend_path] || ""
12
+ end
13
+
14
+ def append_path
15
+ @options[:append_path] || ""
16
+ end
17
+
18
+ def title(node)
19
+ node.content[:name] || node.content[:slug]
20
+ end
21
+
9
22
  def print_html(tags_given, greedy = false)
10
23
  [print_node(@tree.original, tags_given, greedy)].join("")
11
24
  end
12
25
 
13
26
  def node_html(node, active, leaf, content)
14
- "<li class='level_#{node.level}#{leaf ? ' leaf' : ''}#{active ? ' active' : ''}'> <a #{(leaf) ? "href=\'#{node_path(node)}\'" : ''}>#{content}</a>"
27
+ "<li class='level_#{node.level}#{leaf ? ' leaf' : ''}#{active ? ' active' : ''}'> <a #{(leaf) ? "href=\'#{prepend_path}#{node_path(node)}#{append_path}\'" : ''}>#{content}</a>"
15
28
  end
16
29
 
17
30
  def node_path(node)
@@ -21,7 +34,7 @@ module Nutmeg
21
34
  def print_node(node, tags_given, greedy = false)
22
35
  output = []
23
36
  if render_node?(node,tags_given)
24
- output << node_html(node, (!@tree.get_paths(tags_given).first.nil? && @tree.get_paths(tags_given).first.map(&:name).include?(node.name) || (greedy == true && tags_given.include?(node.content[:slug]))), node.is_leaf?, node.content[:slug])
37
+ output << node_html(node, (!@tree.get_paths(tags_given).first.nil? && @tree.get_paths(tags_given).first.map(&:name).include?(node.name) || (greedy == true && tags_given.include?(node.content[:slug]))), node.is_leaf?, title(node))
25
38
  end
26
39
 
27
40
  if !traverse_node?(node, tags_given)
@@ -0,0 +1,66 @@
1
+ module Nutmeg
2
+ class TreeFromJson
3
+ attr_accessor :base_tree, :tags, :tree_hash, :tree, :tag_tree
4
+
5
+ def initialize(data)
6
+ @data = data
7
+ # @tags = @data["tags"]
8
+ @base_tree = @data
9
+ @tag_tree = Tree::TreeNode.new("ROOT", {:tag => "root",:otag => "root", :level => nil, :slug => "root"})
10
+ base_tree.each do |node|
11
+ node_tree = @tag_tree << Tree::TreeNode.new(node["id"], node_hash(node))
12
+ build_node(node_tree, node)
13
+ end
14
+ @tree = Nutmeg::TagTree.new(@tag_tree)
15
+ nil
16
+ end
17
+
18
+ private
19
+ def node_hash(node)
20
+ {
21
+ :tag_id => node["data"]["id"],
22
+ :tag => node["id"],
23
+ :slug => node["data"]["slug"],
24
+ :name => node["data"]["name"]
25
+ }
26
+ end
27
+
28
+ def build_node(parent, node)
29
+ # puts "Building node #{node['id']}"
30
+ # puts "===="
31
+ #puts node["children"].map{|d| d["id"]}
32
+
33
+ node["children"].each do |child|
34
+ #puts "Adding #{child['id']} to #{node['id']}"
35
+ node_tree = parent << Tree::TreeNode.new(child["id"], node_hash(child))
36
+ build_node(node_tree, child)
37
+ end
38
+ end
39
+
40
+ def get_levels
41
+ @levels = @tree_hash.collect do |tag|
42
+ tag[:level]
43
+ end.uniq.sort
44
+ end
45
+
46
+ def get_children(parent, level)
47
+ @tree_hash.select{|node| node[:parent] == parent && node[:level] > level }
48
+ end
49
+
50
+ def traverse_tree
51
+ base_tree.each do |node|
52
+ walk(node.symbolize_keys!)
53
+ end
54
+ end
55
+
56
+ def walk(array, level = 0, parent = nil)
57
+ array.keys.each do |key|
58
+ @tree_hash << {:tag => [key, level,parent].join("_"), :level => level, :parent => parent, :otag => key, :slug => @tags[key], :tag_id => key}
59
+ return if array[key].nil?
60
+ array[key].compact.each do |child|
61
+ walk(child, level + 1, [key, level,parent].join("_"))
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,3 +1,3 @@
1
1
  module Nutmeg
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/nutmeg.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "nutmeg/version"
2
2
  require "nutmeg/tree_from_yaml"
3
+ require "nutmeg/tree_from_json"
3
4
  require "nutmeg/tag_tree"
4
5
  require "nutmeg/tag_tree_helper"
5
6
  require "yaml"
@@ -0,0 +1,736 @@
1
+ [
2
+ {
3
+ "id": "j1_1",
4
+ "text": "North",
5
+ "icon": true,
6
+ "li_attr": {
7
+ "id": "j1_1"
8
+ },
9
+ "a_attr": {
10
+ "href": "#"
11
+ },
12
+ "data": {
13
+ "deleted": false,
14
+ "description": null,
15
+ "id": 45,
16
+ "name": "North",
17
+ "pressroom_id": 41225,
18
+ "slug": "north",
19
+ "tag_image": {
20
+ "url": null,
21
+ "original": {
22
+ "url": null
23
+ },
24
+ "medium": {
25
+ "url": null
26
+ },
27
+ "small": {
28
+ "url": null
29
+ }
30
+ },
31
+ "tag_image_content_type": null,
32
+ "tag_image_file_name": null,
33
+ "tag_image_file_size": null,
34
+ "tag_image_updated_at": null
35
+ },
36
+ "children": [
37
+ {
38
+ "id": "j1_2",
39
+ "text": "Men",
40
+ "icon": true,
41
+ "li_attr": {
42
+ "id": "j1_2"
43
+ },
44
+ "a_attr": {
45
+ "href": "#"
46
+ },
47
+ "data": {
48
+ "deleted": false,
49
+ "description": null,
50
+ "id": 47,
51
+ "name": "Men",
52
+ "pressroom_id": 41225,
53
+ "slug": "men",
54
+ "tag_image": {
55
+ "url": null,
56
+ "original": {
57
+ "url": null
58
+ },
59
+ "medium": {
60
+ "url": null
61
+ },
62
+ "small": {
63
+ "url": null
64
+ }
65
+ },
66
+ "tag_image_content_type": null,
67
+ "tag_image_file_name": null,
68
+ "tag_image_file_size": null,
69
+ "tag_image_updated_at": null
70
+ },
71
+ "children": [
72
+ {
73
+ "id": "j1_4",
74
+ "text": "Footwear",
75
+ "icon": true,
76
+ "li_attr": {
77
+ "id": "j1_4"
78
+ },
79
+ "a_attr": {
80
+ "href": "#"
81
+ },
82
+ "data": {
83
+ "deleted": false,
84
+ "description": "test\r\n",
85
+ "id": 49,
86
+ "name": "Footwear",
87
+ "pressroom_id": 41225,
88
+ "slug": "footwear",
89
+ "tag_image": {
90
+ "url": null,
91
+ "original": {
92
+ "url": null
93
+ },
94
+ "medium": {
95
+ "url": null
96
+ },
97
+ "small": {
98
+ "url": null
99
+ }
100
+ },
101
+ "tag_image_content_type": null,
102
+ "tag_image_file_name": null,
103
+ "tag_image_file_size": null,
104
+ "tag_image_updated_at": null
105
+ },
106
+ "children": [
107
+
108
+ ],
109
+ "type": "default"
110
+ },
111
+ {
112
+ "id": "j1_5",
113
+ "text": "Eyewear",
114
+ "icon": true,
115
+ "li_attr": {
116
+ "id": "j1_5"
117
+ },
118
+ "a_attr": {
119
+ "href": "#"
120
+ },
121
+ "data": {
122
+ "deleted": false,
123
+ "description": null,
124
+ "id": 50,
125
+ "name": "Eyewear",
126
+ "pressroom_id": 41225,
127
+ "slug": "eyewear",
128
+ "tag_image": {
129
+ "url": null,
130
+ "original": {
131
+ "url": null
132
+ },
133
+ "medium": {
134
+ "url": null
135
+ },
136
+ "small": {
137
+ "url": null
138
+ }
139
+ },
140
+ "tag_image_content_type": null,
141
+ "tag_image_file_name": null,
142
+ "tag_image_file_size": null,
143
+ "tag_image_updated_at": null
144
+ },
145
+ "children": [
146
+
147
+ ],
148
+ "type": "default"
149
+ }
150
+ ],
151
+ "type": "default"
152
+ },
153
+ {
154
+ "id": "j1_6",
155
+ "text": "Women",
156
+ "icon": true,
157
+ "li_attr": {
158
+ "id": "j1_6"
159
+ },
160
+ "a_attr": {
161
+ "href": "#"
162
+ },
163
+ "data": {
164
+ "deleted": false,
165
+ "description": null,
166
+ "id": 51,
167
+ "name": "Women",
168
+ "pressroom_id": 41225,
169
+ "slug": "women",
170
+ "tag_image": {
171
+ "url": null,
172
+ "original": {
173
+ "url": null
174
+ },
175
+ "medium": {
176
+ "url": null
177
+ },
178
+ "small": {
179
+ "url": null
180
+ }
181
+ },
182
+ "tag_image_content_type": null,
183
+ "tag_image_file_name": null,
184
+ "tag_image_file_size": null,
185
+ "tag_image_updated_at": null
186
+ },
187
+ "children": [
188
+ {
189
+ "id": "j1_8",
190
+ "text": "Footwear",
191
+ "icon": true,
192
+ "li_attr": {
193
+ "id": "j1_8"
194
+ },
195
+ "a_attr": {
196
+ "href": "#"
197
+ },
198
+ "data": {
199
+ "deleted": false,
200
+ "description": "test\r\n",
201
+ "id": 49,
202
+ "name": "Footwear",
203
+ "pressroom_id": 41225,
204
+ "slug": "footwear",
205
+ "tag_image": {
206
+ "url": null,
207
+ "original": {
208
+ "url": null
209
+ },
210
+ "medium": {
211
+ "url": null
212
+ },
213
+ "small": {
214
+ "url": null
215
+ }
216
+ },
217
+ "tag_image_content_type": null,
218
+ "tag_image_file_name": null,
219
+ "tag_image_file_size": null,
220
+ "tag_image_updated_at": null
221
+ },
222
+ "children": [
223
+
224
+ ],
225
+ "type": "default"
226
+ },
227
+ {
228
+ "id": "j1_9",
229
+ "text": "Eyewear",
230
+ "icon": true,
231
+ "li_attr": {
232
+ "id": "j1_9"
233
+ },
234
+ "a_attr": {
235
+ "href": "#"
236
+ },
237
+ "data": {
238
+ "deleted": false,
239
+ "description": null,
240
+ "id": 50,
241
+ "name": "Eyewear",
242
+ "pressroom_id": 41225,
243
+ "slug": "eyewear",
244
+ "tag_image": {
245
+ "url": null,
246
+ "original": {
247
+ "url": null
248
+ },
249
+ "medium": {
250
+ "url": null
251
+ },
252
+ "small": {
253
+ "url": null
254
+ }
255
+ },
256
+ "tag_image_content_type": null,
257
+ "tag_image_file_name": null,
258
+ "tag_image_file_size": null,
259
+ "tag_image_updated_at": null
260
+ },
261
+ "children": [
262
+ {
263
+ "id": "j1_23",
264
+ "text": "gfdgdfs",
265
+ "icon": true,
266
+ "li_attr": {
267
+ "id": "j1_23"
268
+ },
269
+ "a_attr": {
270
+ "href": "#"
271
+ },
272
+ "data": {
273
+ "deleted": false,
274
+ "description": null,
275
+ "id": 61,
276
+ "name": "gfdgdfs",
277
+ "pressroom_id": 41225,
278
+ "slug": "gfdgdfs",
279
+ "tag_image": {
280
+ "url": null,
281
+ "original": {
282
+ "url": null
283
+ },
284
+ "medium": {
285
+ "url": null
286
+ },
287
+ "small": {
288
+ "url": null
289
+ }
290
+ },
291
+ "tag_image_content_type": null,
292
+ "tag_image_file_name": null,
293
+ "tag_image_file_size": null,
294
+ "tag_image_updated_at": null
295
+ },
296
+ "children": [
297
+
298
+ ],
299
+ "type": "tag"
300
+ }
301
+ ],
302
+ "type": "default"
303
+ }
304
+ ],
305
+ "type": "default"
306
+ },
307
+ {
308
+ "id": "j1_11",
309
+ "text": "Collaboration",
310
+ "icon": true,
311
+ "li_attr": {
312
+ "id": "j1_11"
313
+ },
314
+ "a_attr": {
315
+ "href": "#"
316
+ },
317
+ "data": {
318
+ "deleted": false,
319
+ "description": null,
320
+ "id": 53,
321
+ "name": "Collaboration",
322
+ "pressroom_id": 41225,
323
+ "slug": "collaboration",
324
+ "tag_image": {
325
+ "url": null,
326
+ "original": {
327
+ "url": null
328
+ },
329
+ "medium": {
330
+ "url": null
331
+ },
332
+ "small": {
333
+ "url": null
334
+ }
335
+ },
336
+ "tag_image_content_type": null,
337
+ "tag_image_file_name": null,
338
+ "tag_image_file_size": null,
339
+ "tag_image_updated_at": null
340
+ },
341
+ "children": [
342
+
343
+ ],
344
+ "type": "default"
345
+ }
346
+ ],
347
+ "type": "default"
348
+ },
349
+ {
350
+ "id": "j1_12",
351
+ "text": "South",
352
+ "icon": true,
353
+ "li_attr": {
354
+ "id": "j1_12"
355
+ },
356
+ "a_attr": {
357
+ "href": "#"
358
+ },
359
+ "data": {
360
+ "deleted": false,
361
+ "description": null,
362
+ "id": 46,
363
+ "name": "South",
364
+ "pressroom_id": 41225,
365
+ "slug": "south",
366
+ "tag_image": {
367
+ "url": null,
368
+ "original": {
369
+ "url": null
370
+ },
371
+ "medium": {
372
+ "url": null
373
+ },
374
+ "small": {
375
+ "url": null
376
+ }
377
+ },
378
+ "tag_image_content_type": null,
379
+ "tag_image_file_name": null,
380
+ "tag_image_file_size": null,
381
+ "tag_image_updated_at": null
382
+ },
383
+ "children": [
384
+ {
385
+ "id": "j1_13",
386
+ "text": "Men",
387
+ "icon": true,
388
+ "li_attr": {
389
+ "id": "j1_13"
390
+ },
391
+ "a_attr": {
392
+ "href": "#"
393
+ },
394
+ "data": {
395
+ "deleted": false,
396
+ "description": null,
397
+ "id": 47,
398
+ "name": "Men",
399
+ "pressroom_id": 41225,
400
+ "slug": "men",
401
+ "tag_image": {
402
+ "url": null,
403
+ "original": {
404
+ "url": null
405
+ },
406
+ "medium": {
407
+ "url": null
408
+ },
409
+ "small": {
410
+ "url": null
411
+ }
412
+ },
413
+ "tag_image_content_type": null,
414
+ "tag_image_file_name": null,
415
+ "tag_image_file_size": null,
416
+ "tag_image_updated_at": null
417
+ },
418
+ "children": [
419
+ {
420
+ "id": "j1_14",
421
+ "text": "Collection",
422
+ "icon": true,
423
+ "li_attr": {
424
+ "id": "j1_14"
425
+ },
426
+ "a_attr": {
427
+ "href": "#"
428
+ },
429
+ "data": {
430
+ "deleted": false,
431
+ "description": null,
432
+ "id": 48,
433
+ "name": "Collection",
434
+ "pressroom_id": 41225,
435
+ "slug": "collection",
436
+ "tag_image": {
437
+ "url": null,
438
+ "original": {
439
+ "url": null
440
+ },
441
+ "medium": {
442
+ "url": null
443
+ },
444
+ "small": {
445
+ "url": null
446
+ }
447
+ },
448
+ "tag_image_content_type": null,
449
+ "tag_image_file_name": null,
450
+ "tag_image_file_size": null,
451
+ "tag_image_updated_at": null
452
+ },
453
+ "children": [
454
+
455
+ ],
456
+ "type": "default"
457
+ },
458
+ {
459
+ "id": "j1_15",
460
+ "text": "Footwear",
461
+ "icon": true,
462
+ "li_attr": {
463
+ "id": "j1_15"
464
+ },
465
+ "a_attr": {
466
+ "href": "#"
467
+ },
468
+ "data": {
469
+ "deleted": false,
470
+ "description": "test\r\n",
471
+ "id": 49,
472
+ "name": "Footwear",
473
+ "pressroom_id": 41225,
474
+ "slug": "footwear",
475
+ "tag_image": {
476
+ "url": null,
477
+ "original": {
478
+ "url": null
479
+ },
480
+ "medium": {
481
+ "url": null
482
+ },
483
+ "small": {
484
+ "url": null
485
+ }
486
+ },
487
+ "tag_image_content_type": null,
488
+ "tag_image_file_name": null,
489
+ "tag_image_file_size": null,
490
+ "tag_image_updated_at": null
491
+ },
492
+ "children": [
493
+
494
+ ],
495
+ "type": "default"
496
+ },
497
+ {
498
+ "id": "j1_16",
499
+ "text": "Eyewear",
500
+ "icon": true,
501
+ "li_attr": {
502
+ "id": "j1_16"
503
+ },
504
+ "a_attr": {
505
+ "href": "#"
506
+ },
507
+ "data": {
508
+ "deleted": false,
509
+ "description": null,
510
+ "id": 50,
511
+ "name": "Eyewear",
512
+ "pressroom_id": 41225,
513
+ "slug": "eyewear",
514
+ "tag_image": {
515
+ "url": null,
516
+ "original": {
517
+ "url": null
518
+ },
519
+ "medium": {
520
+ "url": null
521
+ },
522
+ "small": {
523
+ "url": null
524
+ }
525
+ },
526
+ "tag_image_content_type": null,
527
+ "tag_image_file_name": null,
528
+ "tag_image_file_size": null,
529
+ "tag_image_updated_at": null
530
+ },
531
+ "children": [
532
+
533
+ ],
534
+ "type": "default"
535
+ }
536
+ ],
537
+ "type": "default"
538
+ },
539
+ {
540
+ "id": "j1_17",
541
+ "text": "Women",
542
+ "icon": true,
543
+ "li_attr": {
544
+ "id": "j1_17"
545
+ },
546
+ "a_attr": {
547
+ "href": "#"
548
+ },
549
+ "data": {
550
+ "deleted": false,
551
+ "description": null,
552
+ "id": 51,
553
+ "name": "Women",
554
+ "pressroom_id": 41225,
555
+ "slug": "women",
556
+ "tag_image": {
557
+ "url": null,
558
+ "original": {
559
+ "url": null
560
+ },
561
+ "medium": {
562
+ "url": null
563
+ },
564
+ "small": {
565
+ "url": null
566
+ }
567
+ },
568
+ "tag_image_content_type": null,
569
+ "tag_image_file_name": null,
570
+ "tag_image_file_size": null,
571
+ "tag_image_updated_at": null
572
+ },
573
+ "children": [
574
+ {
575
+ "id": "j1_18",
576
+ "text": "Collection",
577
+ "icon": true,
578
+ "li_attr": {
579
+ "id": "j1_18"
580
+ },
581
+ "a_attr": {
582
+ "href": "#"
583
+ },
584
+ "data": {
585
+ "deleted": false,
586
+ "description": null,
587
+ "id": 48,
588
+ "name": "Collection",
589
+ "pressroom_id": 41225,
590
+ "slug": "collection",
591
+ "tag_image": {
592
+ "url": null,
593
+ "original": {
594
+ "url": null
595
+ },
596
+ "medium": {
597
+ "url": null
598
+ },
599
+ "small": {
600
+ "url": null
601
+ }
602
+ },
603
+ "tag_image_content_type": null,
604
+ "tag_image_file_name": null,
605
+ "tag_image_file_size": null,
606
+ "tag_image_updated_at": null
607
+ },
608
+ "children": [
609
+
610
+ ],
611
+ "type": "default"
612
+ },
613
+ {
614
+ "id": "j1_19",
615
+ "text": "Footwear",
616
+ "icon": true,
617
+ "li_attr": {
618
+ "id": "j1_19"
619
+ },
620
+ "a_attr": {
621
+ "href": "#"
622
+ },
623
+ "data": {
624
+ "deleted": false,
625
+ "description": "test\r\n",
626
+ "id": 49,
627
+ "name": "Footwear",
628
+ "pressroom_id": 41225,
629
+ "slug": "footwear",
630
+ "tag_image": {
631
+ "url": null,
632
+ "original": {
633
+ "url": null
634
+ },
635
+ "medium": {
636
+ "url": null
637
+ },
638
+ "small": {
639
+ "url": null
640
+ }
641
+ },
642
+ "tag_image_content_type": null,
643
+ "tag_image_file_name": null,
644
+ "tag_image_file_size": null,
645
+ "tag_image_updated_at": null
646
+ },
647
+ "children": [
648
+
649
+ ],
650
+ "type": "default"
651
+ },
652
+ {
653
+ "id": "j1_20",
654
+ "text": "Eyewear",
655
+ "icon": true,
656
+ "li_attr": {
657
+ "id": "j1_20"
658
+ },
659
+ "a_attr": {
660
+ "href": "#"
661
+ },
662
+ "data": {
663
+ "deleted": false,
664
+ "description": null,
665
+ "id": 50,
666
+ "name": "Eyewear",
667
+ "pressroom_id": 41225,
668
+ "slug": "eyewear",
669
+ "tag_image": {
670
+ "url": null,
671
+ "original": {
672
+ "url": null
673
+ },
674
+ "medium": {
675
+ "url": null
676
+ },
677
+ "small": {
678
+ "url": null
679
+ }
680
+ },
681
+ "tag_image_content_type": null,
682
+ "tag_image_file_name": null,
683
+ "tag_image_file_size": null,
684
+ "tag_image_updated_at": null
685
+ },
686
+ "children": [
687
+
688
+ ],
689
+ "type": "default"
690
+ }
691
+ ],
692
+ "type": "default"
693
+ },
694
+ {
695
+ "id": "j1_22",
696
+ "text": "Collaboration",
697
+ "icon": true,
698
+ "li_attr": {
699
+ "id": "j1_22"
700
+ },
701
+ "a_attr": {
702
+ "href": "#"
703
+ },
704
+ "data": {
705
+ "deleted": false,
706
+ "description": null,
707
+ "id": 53,
708
+ "name": "Collaboration",
709
+ "pressroom_id": 41225,
710
+ "slug": "collaboration",
711
+ "tag_image": {
712
+ "url": null,
713
+ "original": {
714
+ "url": null
715
+ },
716
+ "medium": {
717
+ "url": null
718
+ },
719
+ "small": {
720
+ "url": null
721
+ }
722
+ },
723
+ "tag_image_content_type": null,
724
+ "tag_image_file_name": null,
725
+ "tag_image_file_size": null,
726
+ "tag_image_updated_at": null
727
+ },
728
+ "children": [
729
+
730
+ ],
731
+ "type": "default"
732
+ }
733
+ ],
734
+ "type": "default"
735
+ }
736
+ ]
@@ -4,6 +4,8 @@ describe Nutmeg::TagTreeHelper do
4
4
 
5
5
  before(:each) do
6
6
  @tree_from_yaml = Nutmeg::TreeFromYaml.new({file: [Dir.pwd, "/spec/files/tree.yml"].join})
7
+ data = JSON.load(File.open([Dir.pwd, "/spec/files/tree.json"].join))
8
+ @tree_from_json = Nutmeg::TreeFromJson.new(data)
7
9
  end
8
10
 
9
11
  describe "#print_html" do
@@ -21,7 +23,11 @@ describe Nutmeg::TagTreeHelper do
21
23
  subtree = @tree_from_yaml.tree.subtree("north")
22
24
  expect(Nutmeg::TagTreeHelper.new(subtree).print_html(["men", "collections"],true)).to eq("<ul><li class='level_1 active'> <a >men</a><ul><li class='level_2 active'> <a >collections</a><ul><li class='level_3 leaf'> <a href='/north/men/collections/winter_2015'>winter_2015</a></li><li class='level_3 leaf'> <a href='/north/men/collections/spring_2015'>spring_2015</a></li><li class='level_3 leaf'> <a href='/north/men/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_1'> <a >women</a><ul><li class='level_2 active'> <a >collections</a><ul><li class='level_3 leaf'> <a href='/north/women/collections/winter_2015'>winter_2015</a></li><li class='level_3 leaf'> <a href='/north/women/collections/spring_2015'>spring_2015</a></li><li class='level_3 leaf'> <a href='/north/women/collections/summer_2015'>summer_2015</a></li></ul></li></ul></li><li class='level_1'> <a >events</a><ul><li class='level_2 leaf'> <a href='/north/events/lowlands_2014'>lowlands_2014</a></li><li class='level_2 leaf'> <a href='/north/events/sinterklaas_2014'>sinterklaas_2014</a></li></ul></li><li class='level_1'> <a >collaborations</a><ul><li class='level_2 leaf'> <a href='/north/collaborations/afro_jack'>afro_jack</a></li><li class='level_2 leaf'> <a href='/north/collaborations/pr_co'>pr_co</a></li></ul></li></ul>")
23
25
  end
24
-
25
-
26
+ context "from json" do
27
+ it "outputs html for subtree" do
28
+ subtree = @tree_from_json.tree
29
+ expect(Nutmeg::TagTreeHelper.new(subtree, {:prepend_path => "/nl/t"}).print_html(["men", "collections"],false)).to eq("<ul><li class='level_1'> <a >North</a><ul><li class='level_2'> <a >Men</a><ul><li class='level_3 leaf'> <a href='/nl/t/north/men/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/north/men/eyewear'>Eyewear</a></li></ul></li><li class='level_2'> <a >Women</a><ul><li class='level_3 leaf'> <a href='/nl/t/north/women/footwear'>Footwear</a></li><li class='level_3'> <a >Eyewear</a><ul><li class='level_4 leaf'> <a href='/nl/t/north/women/eyewear/gfdgdfs'>gfdgdfs</a></li></ul></li></ul></li><li class='level_2 leaf'> <a href='/nl/t/north/collaboration'>Collaboration</a></li></ul></li><li class='level_1'> <a >South</a><ul><li class='level_2'> <a >Men</a><ul><li class='level_3 leaf'> <a href='/nl/t/south/men/collection'>Collection</a></li><li class='level_3 leaf'> <a href='/nl/t/south/men/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/south/men/eyewear'>Eyewear</a></li></ul></li><li class='level_2'> <a >Women</a><ul><li class='level_3 leaf'> <a href='/nl/t/south/women/collection'>Collection</a></li><li class='level_3 leaf'> <a href='/nl/t/south/women/footwear'>Footwear</a></li><li class='level_3 leaf'> <a href='/nl/t/south/women/eyewear'>Eyewear</a></li></ul></li><li class='level_2 leaf'> <a href='/nl/t/south/collaboration'>Collaboration</a></li></ul></li></ul>")
30
+ end
31
+ end
26
32
  end
27
33
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nutmeg::TreeFromJson do
4
+
5
+ before(:each) do
6
+ data = JSON.load(File.open([Dir.pwd, "/spec/files/tree.json"].join))
7
+ @tree_from_json = Nutmeg::TreeFromJson.new(data)
8
+ end
9
+
10
+ describe "#initialize" do
11
+ it "verifies initialize works correctly" do
12
+ expect(@tree_from_json.tree.class).to eq(Nutmeg::TagTree)
13
+ expect(([:tag_id, :tag, :slug, :name] - @tree_from_json.tree.original.each_leaf.first.content.keys).empty?).to eq(true)
14
+ end
15
+ end
16
+ end
@@ -11,6 +11,9 @@ describe Nutmeg::TreeFromYaml do
11
11
  expect(@tree_from_yaml.tree_hash.class).to eq(Array)
12
12
  expect(@tree_from_yaml.tree_hash.first.class).to eq(Hash)
13
13
  expect(@tree_from_yaml.tree.class).to eq(Nutmeg::TagTree)
14
+ expect(@tree_from_yaml.tree.original.each_leaf.first.content[:slug]).to eq("winter_2015")
15
+ expect(@tree_from_yaml.tree.original.each_leaf.first.content[:tag_id]).to eq(8)
16
+ expect(([:tag_id, :tag, :slug] - @tree_from_yaml.tree.original.each_leaf.first.content.keys).empty?).to eq(true)
14
17
  end
15
18
  end
16
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutmeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis van der Vliet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-16 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubytree
@@ -83,14 +83,17 @@ files:
83
83
  - lib/nutmeg.rb
84
84
  - lib/nutmeg/tag_tree.rb
85
85
  - lib/nutmeg/tag_tree_helper.rb
86
+ - lib/nutmeg/tree_from_json.rb
86
87
  - lib/nutmeg/tree_from_yaml.rb
87
88
  - lib/nutmeg/version.rb
88
89
  - nutmeg.gemspec
90
+ - spec/files/tree.json
89
91
  - spec/files/tree.yml
90
92
  - spec/nutmeg_spec.rb
91
93
  - spec/spec_helper.rb
92
94
  - spec/tag_tree_helper_spec.rb
93
95
  - spec/tag_tree_spec.rb
96
+ - spec/tree_from_json_spec.rb
94
97
  - spec/tree_from_yaml_spec.rb
95
98
  - tasks/rspec.rake
96
99
  homepage: ''
@@ -118,9 +121,11 @@ signing_key:
118
121
  specification_version: 4
119
122
  summary: Easy trees in rails
120
123
  test_files:
124
+ - spec/files/tree.json
121
125
  - spec/files/tree.yml
122
126
  - spec/nutmeg_spec.rb
123
127
  - spec/spec_helper.rb
124
128
  - spec/tag_tree_helper_spec.rb
125
129
  - spec/tag_tree_spec.rb
130
+ - spec/tree_from_json_spec.rb
126
131
  - spec/tree_from_yaml_spec.rb