playbook_ui_docs 13.29.0.pre.alpha.removeduplicatekitexampleclass3063 → 13.29.0.pre.alpha.testingcollapsibleissue3052
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dist/app/components/playbook/pb_docs/kit_example.rb +78 -0
- data/dist/playbook-doc.js +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3989a7998287dbfdeb6f70a5350de16e07f58a24a708d7960d90509bde13d460
|
4
|
+
data.tar.gz: 26d31983c514bea9c5c4556ea867235c422ed3c62f12d084a993f8eaff6f3a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d3bddef7c00879f999a9daf00eb7f60122c7cb41ba786457c2c3221a316ce8114990b03f31d9f92554a85d48f44b07eb6434fdc95bf45dae536f69966c1cf8d
|
7
|
+
data.tar.gz: 1eef88d2153999d0601102f50ec09771a16b395f4f10a552643a410fabfd7070cb24ce1bd02a9525d37dad36371613f978dfdc1075bb31a58173a9f6338eb9dc
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Style/CaseLikeIf
|
4
|
+
module Playbook
|
5
|
+
module PbDocs
|
6
|
+
class KitExample < Playbook::KitBase
|
7
|
+
prop :kit, type: Playbook::Props::String, required: true
|
8
|
+
prop :example_title, type: Playbook::Props::String, required: true
|
9
|
+
prop :example_key, type: Playbook::Props::String, required: true
|
10
|
+
prop :show_code, type: Playbook::Props::Boolean, default: true
|
11
|
+
prop :type, type: Playbook::Props::Enum, values: %w[rails react swift], default: "rails"
|
12
|
+
prop :dark, type: Playbook::Props::Boolean, default: false
|
13
|
+
|
14
|
+
include PlaybookWebsite::Markdown::Helper
|
15
|
+
|
16
|
+
def example
|
17
|
+
if type == "rails"
|
18
|
+
render inline: source
|
19
|
+
elsif type == "react"
|
20
|
+
react_component example_key.camelize, { dark: dark }
|
21
|
+
elsif type == "swift"
|
22
|
+
## render the markdown file
|
23
|
+
render inline: source
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def description
|
28
|
+
@description ||= read_kit_file("docs", "_#{example_key}.md")
|
29
|
+
end
|
30
|
+
|
31
|
+
def highlighter
|
32
|
+
type.eql?("rails") ? "erb" : "react"
|
33
|
+
end
|
34
|
+
|
35
|
+
def source
|
36
|
+
@source ||= begin
|
37
|
+
extension = if type == "rails"
|
38
|
+
"html.erb"
|
39
|
+
else
|
40
|
+
type == "swift" ? "swift" : "jsx"
|
41
|
+
end
|
42
|
+
stringified_code = read_kit_file("docs", "_#{example_key}.#{extension}")
|
43
|
+
sanitize_code(stringified_code)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def tsx_source
|
48
|
+
read_kit_file("", "_#{example_key}.tsx")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def sanitize_code(stringified_code)
|
54
|
+
stringified_code = stringified_code.gsub('"../.."', '"playbook-ui"')
|
55
|
+
.gsub('"../../"', '"playbook-ui"')
|
56
|
+
.gsub("'../../'", "'playbook-ui'")
|
57
|
+
.gsub("'../..'", "'playbook-ui'")
|
58
|
+
.gsub(%r{from "../.*}, "from 'playbook-ui'")
|
59
|
+
.gsub(%r{from '../.*}, "from 'playbook-ui'")
|
60
|
+
.gsub("'../../../../../../playbook-website/app/javascript/scripts/custom-icons'", "'your-directory/custom-icons.js'")
|
61
|
+
stringified_code = dark ? stringified_code.gsub("{...props}", "dark") : stringified_code.gsub(/\s*{...props}\s*\n/, "\n")
|
62
|
+
if stringified_code.include?("props: { ")
|
63
|
+
stringified_code = stringified_code.gsub("props: {", "props: {dark: true,") if type == "rails" && dark
|
64
|
+
elsif type == "rails" && dark
|
65
|
+
stringified_code = stringified_code.gsub("props: {", "props: {\n dark: true,")
|
66
|
+
end
|
67
|
+
stringified_code.gsub(" {...props}", "")
|
68
|
+
end
|
69
|
+
|
70
|
+
def read_kit_file(folder, *args)
|
71
|
+
path = ::Playbook.kit_path(kit, folder, *args)
|
72
|
+
path.exist? ? path.read : ""
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# rubocop:enable Style/CaseLikeIf
|