playbook_ui_docs 13.5.0 → 13.6.0.pre.alpha.play845allkitsbytypes1219

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,33 +27,58 @@ module PlaybookWebsite
27
27
 
28
28
  # Deal with lists of kits, used in Playbook doc and Externally
29
29
  # rubocop:disable Style/StringConcatenation
30
- def pb_kits(type: "rails", limit_examples: false, dark_mode: false, method: get_kits)
30
+ def pb_kits(type: "rails", limit_examples: false, dark_mode: false)
31
31
  display_kits = []
32
- kits = method
32
+ kits = get_kits(type)
33
33
  kits.each do |kit|
34
- if kit.is_a?(Hash)
35
- nav_hash_array(kit).each do |sub_kit|
36
- display_kits << render_pb_doc_kit(sub_kit, type, limit_examples, false, dark_mode)
37
- end
38
- else
39
- display_kits << render_pb_doc_kit(kit, type, limit_examples, false, dark_mode)
34
+ nav_array = nav_hash_array(kit)
35
+ next unless nav_array.is_a?(Array)
36
+
37
+ nav_array.each do |sub_kit|
38
+ display_kits << render_pb_doc_kit(sub_kit, type, limit_examples, false, dark_mode)
40
39
  end
41
40
  end
42
41
  raw("<div class='pb--docItem'>" + display_kits.join("</div><div class='pb--docItem'>") + "</div>")
43
42
  end
44
43
  # rubocop:enable Style/StringConcatenation
45
44
 
46
- # rubocop:disable Naming/AccessorMethodName
47
- def get_kits
45
+ def get_kits(type = "rails")
48
46
  menu = YAML.load_file(Playbook::Engine.root.join("dist/menu.yml"))
49
- menu["kits"]
47
+ menu["kits"][type]
50
48
  end
51
49
 
52
- def get_kits_pb_website
53
- menu = YAML.load_file(Rails.root.join("config/menu.yml"))
54
- menu["kits"]
50
+ def aggregate_kits
51
+ menu = YAML.load_file(Playbook::Engine.root.join("dist/menu.yml"))
52
+ all_kits = []
53
+
54
+ # Loop over each type (rails, react, swift, etc.)
55
+ menu["kits"].each do |_type, kits|
56
+ kits.each do |kit|
57
+ case kit
58
+ when Hash
59
+ kit_name = kit.keys.first
60
+ existing_kit = all_kits.find { |k| k.is_a?(Hash) && k.keys.first == kit_name }
61
+
62
+ if existing_kit
63
+ existing_kit[kit_name] += kit[kit_name] unless kit[kit_name].nil?
64
+ existing_kit[kit_name].uniq!
65
+ existing_kit[kit_name].sort!
66
+ else
67
+ all_kits << { kit_name => kit[kit_name] }
68
+ end
69
+ when String
70
+ all_kits << kit unless all_kits.include?(kit)
71
+ end
72
+ end
73
+ end
74
+
75
+ # Sort the top-level entries
76
+ all_kits.sort_by! do |kit|
77
+ kit.is_a?(Hash) ? kit.keys.first : kit
78
+ end
79
+
80
+ all_kits
55
81
  end
56
- # rubocop:enable Naming/AccessorMethodName
57
82
 
58
83
  # rubocop:disable Style/OptionalBooleanParameter
59
84
  def render_pb_doc_kit(kit, type, limit_examples, code = true, dark_mode = false)