playbook_ui 12.22.0.pre.alpha.play698responsivespacingglobalprop690 → 12.23.0.pre.alpha.movemarkdown708

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,74 +0,0 @@
1
- <% example_html = ERB.new(example).result %>
2
-
3
- <%= pb_rails("card", props: { classname: "pb--doc", padding: "none", dark: dark }) do %>
4
- <div class="pb--kit-example">
5
- <%= pb_rails("caption", props: { text: example_title, dark: dark }) %>
6
- <br />
7
- <%= example %>
8
- <br>
9
- </div>
10
-
11
- <% if show_code %>
12
- <div class="markdown pb--kit-example-markdown <%= dark ? "dark" : "" %>">
13
- <%= render_markdown(description) %>
14
- </div>
15
- <div id="code-wrapper">
16
- <div class="pb--codeControls">
17
- <ul>
18
- <% hide_button = type == "rails" ? 'flex' : 'none' %>
19
- <li>
20
- <%= pb_rails("button", props: { id:"copy-html-#{example_key}", icon: "copy", text: "Copy HTML", variant: "link", size: "sm", display: hide_button }) %>
21
- </li>
22
- <li>
23
- <%= pb_rails("button", props: { icon: "code", id:"toggle-open-opened", text: "Close Code", variant: "link", size: "sm", display: "none" }) %>
24
- <%= pb_rails("button", props: { icon: "code", id:"toggle-open-closed", text: "Show Code", variant: "link", size: "sm" }) %>
25
- </li>
26
- </ul>
27
- </div>
28
- <div class="pb--codeCopy" data-action="toggle" data-togglable="code_example" style="display: none" >
29
- <%= pb_rails("section_separator", props: { dark: dark })%>
30
- <a href="#" style="padding: 16px 0px 22px 0px;" id="copy-code-<%= example_key %>" class="pb--copy-code" onclick="copyOnClick(`<%= source %>`, `copy-code-<%= example_key %>`)">
31
- <%= pb_rails("button", props: { id: "copy-button-#{example_key}", text: "Copy Code", size: "sm", icon: "copy" }) %>
32
- </a>
33
- <pre class="highlight"><%= raw rouge(source, highlighter) %></pre>
34
- </div>
35
- <%= pb_rails("popover", props: {
36
- trigger_element_id: "copy-button-#{example_key}",
37
- tooltip_id: "tooltip-#{example_key}",
38
- offset: true,
39
- position: "bottom"
40
- }) do %>
41
- Code Copied
42
- <% end %>
43
- </div>
44
- <% end %>
45
- <% end %>
46
-
47
- <script>
48
- var htmlButton = document.getElementById('<%= "copy-html-#{example_key}" %>')
49
- if (htmlButton) {
50
- htmlButton.addEventListener('click', function() {
51
- var tempElement = document.createElement('div')
52
- tempElement.innerHTML = `<%= example_html %>`
53
- var decodedString = tempElement.textContent || tempElement.innerText;
54
- copyContent(decodedString)
55
- })
56
- }
57
-
58
- var button = document.getElementById('<%= "copy-button-#{example_key}" %>')
59
- if (button) {
60
- button.addEventListener('click', function() {
61
- var tempElement = document.createElement('div')
62
- tempElement.innerHTML = `<%= source %>`
63
- var decodedString = tempElement.textContent || tempElement.innerText;
64
- copyContent(decodedString)
65
- var fadeAwayDiv = document.getElementById("<%= "tooltip-#{example_key}" %>")
66
- setTimeout(function() {
67
- fadeAwayDiv.classList.remove('show')
68
- }, 3000)
69
- setTimeout(function() {
70
- fadeAwayDiv.classList.add('hide')
71
- }, 3001)
72
- })
73
- }
74
- </script>
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # rubocop:disable Style/CaseLikeIf
4
-
5
- module Playbook
6
- module PbDocs
7
- class KitExample < Playbook::KitBase
8
- include Playbook::Markdown::Helper
9
-
10
- prop :kit, type: Playbook::Props::String, required: true
11
- prop :example_title, type: Playbook::Props::String, required: true
12
- prop :example_key, type: Playbook::Props::String, required: true
13
- prop :show_code, type: Playbook::Props::Boolean, default: true
14
- prop :type, type: Playbook::Props::Enum, values: %w[rails react], default: "rails"
15
- prop :dark, type: Playbook::Props::Boolean, default: false
16
-
17
- def example
18
- if type == "rails"
19
- render inline: source
20
- elsif type == "react"
21
- react_component example_key.camelize, { dark: dark }
22
- end
23
- end
24
-
25
- def description
26
- @description ||= read_kit_file("docs", "_#{example_key}.md")
27
- end
28
-
29
- def highlighter
30
- type.eql?("rails") ? "erb" : "react"
31
- end
32
-
33
- def source
34
- @source ||= begin
35
- extension = type == "react" ? "jsx" : "html.erb"
36
- stringified_code = read_kit_file("docs", "_#{example_key}.#{extension}")
37
- sanitize_code(stringified_code)
38
- end
39
- end
40
-
41
- def tsx_source
42
- read_kit_file("", "_#{example_key}.tsx")
43
- end
44
-
45
- private
46
-
47
- def sanitize_code(stringified_code)
48
- stringified_code = stringified_code.gsub('"../.."', '"playbook-ui"')
49
- .gsub('"../../"', '"playbook-ui"')
50
- .gsub("'../../'", "'playbook-ui'")
51
- .gsub("'../..'", "'playbook-ui'")
52
- .gsub(%r{from "../.*}, "from 'playbook-ui'")
53
- .gsub(%r{from '../.*}, "from 'playbook-ui'")
54
- stringified_code = dark ? stringified_code.gsub("{...props}", "dark") : stringified_code.gsub(/\s*{...props}\s*\n/, "\n")
55
- if stringified_code.include?("props: { ")
56
- stringified_code = stringified_code.gsub("props: {", "props: {dark: true,") if type == "rails" && dark
57
- elsif type == "rails" && dark
58
- stringified_code = stringified_code.gsub("props: {", "props: {\n dark: true,")
59
- end
60
- stringified_code.gsub(" {...props}", "")
61
- end
62
-
63
- def read_kit_file(folder, *args)
64
- path = ::Playbook.kit_path(kit, folder, *args)
65
- path.exist? ? path.read : ""
66
- end
67
- end
68
- end
69
- end
70
-
71
- # rubocop:enable Style/CaseLikeIf
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "redcarpet"
4
- require "rouge"
5
- require "rouge/plugins/redcarpet"
6
- require "action_view"
7
-
8
- module Playbook
9
- module Markdown
10
- module Helper
11
- def self.call(template, _source)
12
- markdown(template.source)
13
- end
14
-
15
- def render_markdown(text)
16
- # rubocop:disable Security/Eval
17
- eval(Playbook::Markdown::Helper.markdown(text))
18
- # rubocop:enable Security/Eval
19
- end
20
-
21
- def self.markdown(text)
22
- options = {
23
- filter_html: false,
24
- hard_wrap: true,
25
- link_attributes: { rel: "nofollow", target: "_blank" },
26
- space_after_headers: true,
27
- fenced_code_blocks: true,
28
- no_styles: false,
29
- safe_links_only: true,
30
- }
31
-
32
- extensions = {
33
- lax_spacing: true,
34
- no_intra_emphasis: true,
35
- autolink: true,
36
- superscript: true,
37
- fenced_code_blocks: true,
38
- tables: true,
39
- disable_indented_code_blocks: false,
40
- strikethrough: true,
41
- underline: true,
42
- highlight: true,
43
- footnotes: true,
44
- with_toc_data: true,
45
- }
46
-
47
- renderer = HTMLBlockCode.new(options)
48
- # toc_renderer = Redcarpet::Render::HTML_TOC.new(with_toc_data: true)
49
- # @TOC = Redcarpet::Markdown.new(toc_renderer)
50
- # puts "TOC: #{@TOC.inspect}"
51
- markdown = Redcarpet::Markdown.new(renderer, extensions)
52
- "#{markdown.render(text).inspect}.html_safe;"
53
- end
54
-
55
- def rouge(text, language)
56
- formatter = Rouge::Formatters::HTML.new(scope: ".highlight")
57
- lexer = Rouge::Lexer.find(language)
58
- formatter.format(lexer.lex(text))
59
- end
60
-
61
- class HTML < Redcarpet::Render::HTML
62
- include Rouge::Plugins::Redcarpet
63
- end
64
-
65
- def rouge_markdown(text)
66
- render_options = {
67
- filter_html: true,
68
- hard_wrap: true,
69
- link_attributes: { rel: "nofollow" },
70
- }
71
- renderer = HTML.new(render_options)
72
-
73
- extensions = {
74
- autolink: true,
75
- fenced_code_blocks: true,
76
- lax_spacing: true,
77
- no_intra_emphasis: true,
78
- strikethrough: true,
79
- superscript: true,
80
- }
81
- markdown = Redcarpet::Markdown.new(renderer, extensions)
82
- markdown.render(text)
83
- end
84
- end
85
-
86
- class HTMLWithPants < Redcarpet::Render::HTML
87
- include Redcarpet::Render::SmartyPants
88
- end
89
-
90
- class HTML < Redcarpet::Render::HTML
91
- include Rouge::Plugins::Redcarpet
92
- end
93
-
94
- class HTMLBlockCode < Redcarpet::Render::HTML
95
- include ActionView::Helpers::AssetTagHelper
96
-
97
- # def block_code(code, language)
98
- # "\n.nf\n#{normal_text(rouge(code, language))}\n.fi\n"
99
- # end
100
-
101
- def table(header, body)
102
- "<table class='pb_table table-sm table-responsive-collapse table-card table-collapse-sm'>" \
103
- "<thead>#{header}</thead>" \
104
- "<tbody>#{body}</tbody>" \
105
- "</table>"
106
- end
107
-
108
- def header(title, level)
109
- @headers ||= []
110
- permalink = title.gsub(/\W+/, "-")
111
- if @headers.include?(permalink)
112
- permalink += "_1"
113
- loop do
114
- break unless @headers.include?(permalink)
115
-
116
- permalink.gsub!(/_(\d+)$/, "_#{Regexp.last_match(1).to_i + 1}")
117
- end
118
- end
119
- @headers << permalink
120
- permalink_markup = %(<a name="#{permalink}" class="markdown-header-anchor" )
121
- permalink_markup += %(href="##{permalink}"><span class="far fa-link markdown-header-anchor-icon"></span></a>)
122
- %(\n<h#{level} id="#{permalink}">#{title} #{permalink_markup}</h#{level}>\n)
123
- end
124
-
125
- def image(link, title, alt_text)
126
- return nil if link.nil?
127
-
128
- %(<a href="#{link}" target="_blank">#{image_tag(link, title: title, alt: alt_text, class: 'imageloader lazyload')}</a>)
129
- end
130
- end
131
- end
132
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "playbook/markdown/helper"