playbook-ui 12.24.0 → 12.25.0
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.
- package/CHANGELOG.md +28 -6
- package/dist/app/components/playbook/pb_docs/kit_api.html.erb +321 -0
- package/dist/app/components/playbook/pb_docs/kit_api.rb +150 -0
- package/dist/app/components/playbook/pb_docs/kit_example.html.erb +74 -0
- package/dist/app/components/playbook/pb_docs/kit_example.rb +70 -0
- package/dist/pb_doc_helper.rb +100 -0
- package/dist/playbook-doc.js +61 -61
- package/dist/playbook-rails.js +5 -5
- package/dist/playbook.css +1 -1
- package/dist/playbook.js +5 -5
- package/package.json +1 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PlaybookWebsite
|
|
4
|
+
module PbDocHelper
|
|
5
|
+
def pb_kit_title(title)
|
|
6
|
+
title.remove("pb_").titleize.tr("_", " ")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def pb_kit(kit: "", type: "rails", show_code: true, limit_examples: false, dark_mode: false)
|
|
10
|
+
examples = pb_doc_kit_examples(kit, type)
|
|
11
|
+
examples = examples.first(1) if limit_examples
|
|
12
|
+
examples.map do |example|
|
|
13
|
+
pb_rails "docs/kit_example", props: {
|
|
14
|
+
kit: kit,
|
|
15
|
+
example_title: example.values.first,
|
|
16
|
+
example_key: example.keys.first,
|
|
17
|
+
show_code: show_code,
|
|
18
|
+
type: type,
|
|
19
|
+
dark: dark_mode,
|
|
20
|
+
}
|
|
21
|
+
end.join.yield_self(&method(:raw))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def nav_hash_array(link)
|
|
25
|
+
link.first.last
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Deal with lists of kits, used in Playbook doc and Externally
|
|
29
|
+
# rubocop:disable Style/StringConcatenation
|
|
30
|
+
def pb_kits(type: "rails", limit_examples: false, dark_mode: false, method: get_kits)
|
|
31
|
+
display_kits = []
|
|
32
|
+
kits = method
|
|
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)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
raw("<div class='pb--docItem'>" + display_kits.join("</div><div class='pb--docItem'>") + "</div>")
|
|
43
|
+
end
|
|
44
|
+
# rubocop:enable Style/StringConcatenation
|
|
45
|
+
|
|
46
|
+
# rubocop:disable Naming/AccessorMethodName
|
|
47
|
+
def get_kits
|
|
48
|
+
menu = YAML.load_file(Playbook::Engine.root.join("dist/menu.yml"))
|
|
49
|
+
menu["kits"]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def get_kits_pb_website
|
|
53
|
+
menu = YAML.load_file(Rails.root.join("config/menu.yml"))
|
|
54
|
+
menu["kits"]
|
|
55
|
+
end
|
|
56
|
+
# rubocop:enable Naming/AccessorMethodName
|
|
57
|
+
|
|
58
|
+
# rubocop:disable Style/OptionalBooleanParameter
|
|
59
|
+
def render_pb_doc_kit(kit, type, limit_examples, code = true, dark_mode = false)
|
|
60
|
+
title = pb_doc_render_clickable_title(kit, type)
|
|
61
|
+
ui = raw("<div class='pb--docItem-ui'>
|
|
62
|
+
#{pb_kit(kit: kit, type: type, show_code: code, limit_examples: limit_examples, dark_mode: dark_mode)}</div>")
|
|
63
|
+
title + ui
|
|
64
|
+
end
|
|
65
|
+
# rubocop:enable Style/OptionalBooleanParameter
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def pb_doc_kit_path(kit, *args)
|
|
70
|
+
Playbook.kit_path(kit, "docs", *args)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def pb_doc_kit_examples(kit, type)
|
|
74
|
+
example_file = pb_doc_kit_path(kit, "example.yml")
|
|
75
|
+
if File.exist?(example_file)
|
|
76
|
+
examples_list = YAML.load_file(example_file)
|
|
77
|
+
.inject({}) { |item, (k, v)| item[k.to_sym] = v; item }
|
|
78
|
+
examples_list.dig(:examples, type) || []
|
|
79
|
+
else
|
|
80
|
+
[]
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def pb_doc_render_clickable_title(kit, type)
|
|
85
|
+
url = "#"
|
|
86
|
+
begin
|
|
87
|
+
url = if type == "react"
|
|
88
|
+
kit_show_reacts_path(kit)
|
|
89
|
+
else
|
|
90
|
+
kit_show_path(kit)
|
|
91
|
+
end
|
|
92
|
+
# FIXME: this is here because this helper generates a link for playbook website,
|
|
93
|
+
# but shouldn't do anything when used elsewhere
|
|
94
|
+
rescue
|
|
95
|
+
puts "Kit Path Not Avaliable"
|
|
96
|
+
end
|
|
97
|
+
render inline: "<a href='#{url}'>#{pb_rails(:title, props: { text: pb_kit_title(kit), tag: 'h3', size: 2 })}</a>"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|