nexmo-oas-renderer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +1 -0
  3. data/.gitignore +5 -0
  4. data/CHANGELOG.md +2 -0
  5. data/CONTRIBUTING.md +46 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +183 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +73 -0
  10. data/Rakefile +2 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/exe/nexmo-oas-renderer +5 -0
  14. data/lib/nexmo/oas/engine.rb +9 -0
  15. data/lib/nexmo/oas/renderer.rb +13 -0
  16. data/lib/nexmo/oas/renderer/app.rb +116 -0
  17. data/lib/nexmo/oas/renderer/config.ru +7 -0
  18. data/lib/nexmo/oas/renderer/config/code_languages.yml +138 -0
  19. data/lib/nexmo/oas/renderer/config/dynamic_content.yml +1 -0
  20. data/lib/nexmo/oas/renderer/config/redirects.yml +8 -0
  21. data/lib/nexmo/oas/renderer/constraints/open_api.rb +76 -0
  22. data/lib/nexmo/oas/renderer/constraints/redirector.rb +17 -0
  23. data/lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb +55 -0
  24. data/lib/nexmo/oas/renderer/filters/anchor.rb +17 -0
  25. data/lib/nexmo/oas/renderer/filters/audio.rb +21 -0
  26. data/lib/nexmo/oas/renderer/filters/block_escape.rb +24 -0
  27. data/lib/nexmo/oas/renderer/filters/break.rb +13 -0
  28. data/lib/nexmo/oas/renderer/filters/code.rb +64 -0
  29. data/lib/nexmo/oas/renderer/filters/code_snippet.rb +194 -0
  30. data/lib/nexmo/oas/renderer/filters/code_snippet_list.rb +33 -0
  31. data/lib/nexmo/oas/renderer/filters/code_snippets.rb +158 -0
  32. data/lib/nexmo/oas/renderer/filters/collapsible.rb +27 -0
  33. data/lib/nexmo/oas/renderer/filters/columns.rb +50 -0
  34. data/lib/nexmo/oas/renderer/filters/concept_list.rb +33 -0
  35. data/lib/nexmo/oas/renderer/filters/dynamic_content.rb +30 -0
  36. data/lib/nexmo/oas/renderer/filters/external_link.rb +32 -0
  37. data/lib/nexmo/oas/renderer/filters/frontmatter.rb +14 -0
  38. data/lib/nexmo/oas/renderer/filters/heading.rb +61 -0
  39. data/lib/nexmo/oas/renderer/filters/icon.rb +22 -0
  40. data/lib/nexmo/oas/renderer/filters/indent.rb +20 -0
  41. data/lib/nexmo/oas/renderer/filters/inline_escape.rb +17 -0
  42. data/lib/nexmo/oas/renderer/filters/js_sequence_diagram.rb +21 -0
  43. data/lib/nexmo/oas/renderer/filters/label.rb +32 -0
  44. data/lib/nexmo/oas/renderer/filters/language.rb +15 -0
  45. data/lib/nexmo/oas/renderer/filters/markdown.rb +85 -0
  46. data/lib/nexmo/oas/renderer/filters/modal.rb +41 -0
  47. data/lib/nexmo/oas/renderer/filters/partial.rb +28 -0
  48. data/lib/nexmo/oas/renderer/filters/php_inliner.rb +15 -0
  49. data/lib/nexmo/oas/renderer/filters/screenshot.rb +26 -0
  50. data/lib/nexmo/oas/renderer/filters/tab.rb +250 -0
  51. data/lib/nexmo/oas/renderer/filters/techio.rb +24 -0
  52. data/lib/nexmo/oas/renderer/filters/tooltip.rb +22 -0
  53. data/lib/nexmo/oas/renderer/filters/tutorial_link.rb +27 -0
  54. data/lib/nexmo/oas/renderer/filters/tutorials.rb +28 -0
  55. data/lib/nexmo/oas/renderer/filters/unfreeze.rb +20 -0
  56. data/lib/nexmo/oas/renderer/filters/user_personalization.rb +43 -0
  57. data/lib/nexmo/oas/renderer/helpers/navigation.rb +66 -0
  58. data/lib/nexmo/oas/renderer/helpers/render.rb +24 -0
  59. data/lib/nexmo/oas/renderer/helpers/summary.rb +30 -0
  60. data/lib/nexmo/oas/renderer/helpers/url.rb +17 -0
  61. data/lib/nexmo/oas/renderer/lib/core_ext/string.rb +14 -0
  62. data/lib/nexmo/oas/renderer/lib/redcarpet.rb +14 -0
  63. data/lib/nexmo/oas/renderer/models/code_snippet.rb +75 -0
  64. data/lib/nexmo/oas/renderer/models/tutorial.rb +83 -0
  65. data/lib/nexmo/oas/renderer/pipelines/markdown_pipeline.rb +52 -0
  66. data/lib/nexmo/oas/renderer/presenters/api_specification.rb +42 -0
  67. data/lib/nexmo/oas/renderer/presenters/groups.rb +35 -0
  68. data/lib/nexmo/oas/renderer/presenters/navigation.rb +24 -0
  69. data/lib/nexmo/oas/renderer/presenters/open_api_specification.rb +68 -0
  70. data/lib/nexmo/oas/renderer/presenters/versions.rb +40 -0
  71. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Black.woff +0 -0
  72. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Black.woff2 +0 -0
  73. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Heavy.woff +0 -0
  74. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Heavy.woff2 +0 -0
  75. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Regular.woff +0 -0
  76. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Regular.woff2 +0 -0
  77. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Semibold.woff +0 -0
  78. data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Semibold.woff2 +0 -0
  79. data/lib/nexmo/oas/renderer/public/assets/images/brands/android.svg +1 -0
  80. data/lib/nexmo/oas/renderer/public/assets/images/brands/curl.svg +1 -0
  81. data/lib/nexmo/oas/renderer/public/assets/images/brands/dotnet.svg +1 -0
  82. data/lib/nexmo/oas/renderer/public/assets/images/brands/ios.svg +1 -0
  83. data/lib/nexmo/oas/renderer/public/assets/images/brands/java.svg +1 -0
  84. data/lib/nexmo/oas/renderer/public/assets/images/brands/javascript.svg +1 -0
  85. data/lib/nexmo/oas/renderer/public/assets/images/brands/node.svg +1 -0
  86. data/lib/nexmo/oas/renderer/public/assets/images/brands/php.svg +1 -0
  87. data/lib/nexmo/oas/renderer/public/assets/images/brands/python.svg +11 -0
  88. data/lib/nexmo/oas/renderer/public/assets/images/brands/ruby.svg +1 -0
  89. data/lib/nexmo/oas/renderer/public/assets/images/lost.svg +37 -0
  90. data/lib/nexmo/oas/renderer/public/assets/javascripts/components/format.js +42 -0
  91. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.accordion.js +249 -0
  92. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.core.js +230 -0
  93. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.modal.js +300 -0
  94. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.tabs.js +139 -0
  95. data/lib/nexmo/oas/renderer/public/assets/stylesheets/api.css +95 -0
  96. data/lib/nexmo/oas/renderer/public/assets/stylesheets/buttons.css +80 -0
  97. data/lib/nexmo/oas/renderer/public/assets/stylesheets/core.css +79 -0
  98. data/lib/nexmo/oas/renderer/public/assets/stylesheets/mediaqueries.css +2 -0
  99. data/lib/nexmo/oas/renderer/public/assets/stylesheets/mediaqueries.css.map +7 -0
  100. data/lib/nexmo/oas/renderer/public/assets/stylesheets/navigation.css +79 -0
  101. data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo.css +68 -0
  102. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/api.scss +147 -0
  103. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/core.scss +133 -0
  104. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/mediaqueries.scss +48 -0
  105. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/navigation.scss +106 -0
  106. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/nexmo.scss +61 -0
  107. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/style.scss +10 -0
  108. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/syntax.scss +63 -0
  109. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/typography.scss +248 -0
  110. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/variables.scss +91 -0
  111. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/volta-templates.scss +119 -0
  112. data/lib/nexmo/oas/renderer/public/assets/stylesheets/style.css +2 -0
  113. data/lib/nexmo/oas/renderer/public/assets/stylesheets/style.css.map +7 -0
  114. data/lib/nexmo/oas/renderer/public/assets/stylesheets/syntax.css +79 -0
  115. data/lib/nexmo/oas/renderer/public/assets/stylesheets/typography.css +86 -0
  116. data/lib/nexmo/oas/renderer/public/assets/stylesheets/variables.css +2 -0
  117. data/lib/nexmo/oas/renderer/public/assets/stylesheets/variables.css.map +7 -0
  118. data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta-templates.css +2 -0
  119. data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta-templates.css.map +7 -0
  120. data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta.min.css +1 -0
  121. data/lib/nexmo/oas/renderer/public/assets/symbol/volta-icons.svg +1 -0
  122. data/lib/nexmo/oas/renderer/public/favicon.ico +0 -0
  123. data/lib/nexmo/oas/renderer/services/code_language_api.rb +98 -0
  124. data/lib/nexmo/oas/renderer/services/oas_parser.rb +21 -0
  125. data/lib/nexmo/oas/renderer/services/open_api_definition_resolver.rb +33 -0
  126. data/lib/nexmo/oas/renderer/version.rb +7 -0
  127. data/lib/nexmo/oas/renderer/views/api/show.erb +1 -0
  128. data/lib/nexmo/oas/renderer/views/code_snippets/_application_messages_dispatch.html.erb +9 -0
  129. data/lib/nexmo/oas/renderer/views/code_snippets/_application_rtc.html.erb +41 -0
  130. data/lib/nexmo/oas/renderer/views/code_snippets/_application_voice.html.erb +24 -0
  131. data/lib/nexmo/oas/renderer/views/code_snippets/_code_only.html.erb +6 -0
  132. data/lib/nexmo/oas/renderer/views/code_snippets/_configure_client.html.erb +20 -0
  133. data/lib/nexmo/oas/renderer/views/code_snippets/_dependencies.html.erb +11 -0
  134. data/lib/nexmo/oas/renderer/views/code_snippets/_write_code.html.erb +13 -0
  135. data/lib/nexmo/oas/renderer/views/code_snippets/list/plain.html.erb +10 -0
  136. data/lib/nexmo/oas/renderer/views/concepts/list/plain.html.erb +5 -0
  137. data/lib/nexmo/oas/renderer/views/layouts/_head.erb +4 -0
  138. data/lib/nexmo/oas/renderer/views/layouts/_javascripts.erb +9 -0
  139. data/lib/nexmo/oas/renderer/views/layouts/api.erb +23 -0
  140. data/lib/nexmo/oas/renderer/views/layouts/open_api.erb +10 -0
  141. data/lib/nexmo/oas/renderer/views/open_api/_callback.erb +5 -0
  142. data/lib/nexmo/oas/renderer/views/open_api/_callback_endpoint.erb +48 -0
  143. data/lib/nexmo/oas/renderer/views/open_api/_code_examples.erb +16 -0
  144. data/lib/nexmo/oas/renderer/views/open_api/_endpoint.erb +156 -0
  145. data/lib/nexmo/oas/renderer/views/open_api/_model.erb +38 -0
  146. data/lib/nexmo/oas/renderer/views/open_api/_navigation.erb +80 -0
  147. data/lib/nexmo/oas/renderer/views/open_api/_parameter_groups.erb +50 -0
  148. data/lib/nexmo/oas/renderer/views/open_api/_parameters.erb +165 -0
  149. data/lib/nexmo/oas/renderer/views/open_api/_response_description_parameters.erb +61 -0
  150. data/lib/nexmo/oas/renderer/views/open_api/_response_descriptions.erb +41 -0
  151. data/lib/nexmo/oas/renderer/views/open_api/show.erb +104 -0
  152. data/lib/nexmo/oas/renderer/views/static/404.erb +6 -0
  153. data/lib/nexmo/oas/renderer/views/tutorials/_index.html.erb +32 -0
  154. data/lib/nexmo/oas/renderer/views/tutorials/index.html.erb +7 -0
  155. data/lib/nexmo/oas/renderer/views/tutorials/list/plain.html.erb +5 -0
  156. data/lib/nexmo/oas/renderer/views/tutorials/show.html.erb +8 -0
  157. data/nexmo-oas-renderer.gemspec +49 -0
  158. metadata +399 -0
@@ -0,0 +1,33 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class ConceptList < Banzai::Filter
6
+ def call(input)
7
+ input.gsub(/```concept_list(.+?)```/m) do |_s|
8
+ config = YAML.safe_load($1)
9
+
10
+ raise 'concept_list filter takes a YAML config' if config.nil?
11
+ raise "concept_list filter requires 'product' or 'concepts' key" unless config['product'] || config['concepts']
12
+
13
+ if config['product']
14
+ @product = config['product']
15
+ @concepts = Concept.by_product(@product)
16
+ elsif config['concepts']
17
+ @concepts = Concept.by_name(config['concepts'])
18
+ end
19
+
20
+ @concepts.reject!(&:ignore_in_list)
21
+
22
+ return '' if @concepts.empty?
23
+
24
+ erb = File.read("#{API.root}/views/concepts/list/plain.html.erb")
25
+ html = ERB.new(erb).result(binding)
26
+ "FREEZESTART#{Base64.urlsafe_encode64(html)}FREEZEEND"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class DynamicContent < Banzai::Filter
6
+ def call(input)
7
+ input.gsub(/(\s|^)\[\~(.+?)\~\](\s|$)/) do
8
+ content = environment_value($2) || config_value($2) || "VALUE NOT SET: #{$2}"
9
+ "#{$1}#{content}#{$3}"
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def environment_value(key)
16
+ return nil unless ENV['DYNAMIC_CONTENT']
17
+ @environment_dynamic_content ||= YAML.safe_load(ENV['DYNAMIC_CONTENT'])
18
+ @environment_dynamic_content ||= YAML.safe_load(temp)
19
+ @environment_dynamic_content[key]
20
+ end
21
+
22
+ def config_value(key)
23
+ @config_dynamic_content ||= YAML.load_file("#{API.root}/config/dynamic_content.yml")
24
+ @config_dynamic_content[key]
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,32 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class ExternalLink < Banzai::Filter
6
+ def call(input)
7
+ @input = input
8
+
9
+ document.css('a').each_with_index do |link, _index|
10
+ if link['href']&.start_with?('http') && link['class'] && !link['class'].include?('no-external-marker')
11
+ link['target'] = '_blank'
12
+ if link.css('svg').empty?
13
+ link.add_child <<~HEREDOC
14
+ &nbsp;<svg class="Vlt-icon Vlt-icon--smaller Vlt-icon--text-bottom Vlt-blue-dark"><use xlink:href="/assets/symbol/volta-icons.svg#Vlt-icon-open"></use></svg>
15
+ HEREDOC
16
+ end
17
+ end
18
+ end
19
+
20
+ @document.to_html
21
+ end
22
+
23
+ private
24
+
25
+ def document
26
+ @document ||= Nokogiri::HTML::DocumentFragment.parse(@input)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Frontmatter < Banzai::Filter
6
+ def call(input)
7
+ # Remove frontmatter from the input
8
+ input.gsub(/\A(---.+?---)/mo, '')
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,61 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Heading < Banzai::Filter
6
+ def call(input)
7
+ @input = input
8
+ @headings = []
9
+
10
+ heading_tag_list = %w[h1 h2 h3 h4 h5 h6]
11
+ headings = document.children.select do |child|
12
+ heading_tag_list.include? child.name
13
+ end
14
+
15
+ headings.each do |heading|
16
+ parameterized_heading = parameterized_heading_without_collision(heading)
17
+ heading['id'] = parameterized_heading
18
+ heading['data-id'] = SecureRandom.hex
19
+ heading['class'] = heading[:class]
20
+ heading['class'] += ' Vlt-title--icon'
21
+
22
+ heading.prepend_child <<~HEREDOC
23
+ <a href="##{parameterized_heading}" class="heading-permalink">
24
+ <svg class="Vlt-grey"><use xlink:href=\"/assets/symbol/volta-icons.svg#Vlt-icon-link\" /></svg>
25
+ </a>
26
+ HEREDOC
27
+ end
28
+
29
+ @document.to_html
30
+ end
31
+
32
+ private
33
+
34
+ def document
35
+ @document ||= Nokogiri::HTML::DocumentFragment.parse(@input)
36
+ end
37
+
38
+ def parameterized_heading_without_collision(heading)
39
+ parameterized_heading = nil
40
+ index = nil
41
+
42
+ loop do
43
+ if index
44
+ parameterized_heading = "#{heading.text.parameterize}-#{index}"
45
+ index += 1
46
+ else
47
+ parameterized_heading = heading.text.parameterize
48
+ index = 2
49
+ end
50
+
51
+ break if @headings.exclude? parameterized_heading
52
+ end
53
+
54
+ @headings << parameterized_heading
55
+ parameterized_heading
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Icon < Banzai::Filter
6
+ def call(input)
7
+ input.gsub!('✅', '<svg class="Vlt-green Vlt-icon Vlt-icon--small"><use xlink:href="/assets/symbol/volta-icons.svg#Vlt-icon-check" /></svg>')
8
+ input.gsub!('❌', '<svg class="Vlt-red Vlt-icon Vlt-icon--small"><use xlink:href="/assets/symbol/volta-icons.svg#Vlt-icon-cross" /></svg>')
9
+
10
+ input.gsub!(/\[icon="(.+?)"\]/) do
11
+ <<~HEREDOC
12
+ <svg class="Vlt-green Vlt-icon Vlt-icon--small"><use xlink:href="/assets/symbol/volta-icons.svg#Vlt-icon-#{$1}" /></svg>
13
+ HEREDOC
14
+ end
15
+
16
+ input
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Indent < Banzai::Filter
6
+ def call(input)
7
+ input.gsub(/^^\s{4}\-\>\s(.+?)$/) do
8
+ body = MarkdownPipeline.new.call($1)
9
+ <<~HEREDOC
10
+ <div class="indent">
11
+ #{body}
12
+ </div>
13
+ HEREDOC
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class InlineEscape < Banzai::Filter
6
+ def call(input)
7
+ # Freeze to prevent Markdown formatting
8
+ input.gsub(/``(.+?)``/) do |_s|
9
+ frozen_code = Base64.urlsafe_encode64("<code>#{$1}</code>")
10
+ "FREEZESTART#{frozen_code}FREEZEEND"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class JsSequenceDiagram < Banzai::Filter
6
+ def call(input)
7
+ input.gsub(/```js_sequence_diagram(.+?)```/m) do |_s|
8
+ diagram = <<~HEREDOC
9
+ <div class="js-diagram">
10
+ #{$1}
11
+ </div>
12
+ HEREDOC
13
+
14
+ "FREEZESTART#{Base64.urlsafe_encode64(diagram)}FREEZEEND"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Label < Banzai::Filter
6
+ def call(input)
7
+ input.gsub(/\[(GET|POST|PUT|DELETE|OPTIONS)\]/i) do |_s|
8
+ "<span class='Vlt-badge #{class_name($1)}'>#{$1}</span> "
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def class_name(text)
15
+ case text
16
+ when 'POST'
17
+ 'Vlt-badge--green'
18
+ when 'GET'
19
+ 'Vlt-badge--blue'
20
+ when 'DELETE'
21
+ 'Vlt-badge--red'
22
+ when 'PUT'
23
+ 'Vlt-badge--yellow'
24
+ when 'OPTIONS'
25
+ 'Vlt-badge--grey'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Language < Banzai::Filter
6
+ def call(input)
7
+ input.gsub(/\[(.+?)\]\(lang:.+?(?:'(.+?)'|"(.+?)")\)/) do |_s|
8
+ "<span lang='#{$2}'>#{$1}</span>"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,85 @@
1
+ require_relative '../lib/redcarpet'
2
+
3
+ module Nexmo
4
+ module OAS
5
+ module Renderer
6
+ module Filters
7
+ class Markdown < Banzai::Filter
8
+ def call(input)
9
+ markdown.render(input)
10
+ end
11
+
12
+ private
13
+
14
+ def renderer
15
+ @renderer ||= VoltaRender.new(options)
16
+ end
17
+
18
+ def markdown
19
+ @markdown ||= Redcarpet::Markdown.new(renderer, {
20
+ no_intra_emphasis: true,
21
+ tables: true,
22
+ strikethrough: true,
23
+ superscript: true,
24
+ underline: true,
25
+ highlight: true,
26
+ fenced_code_blocks: true,
27
+ disable_indented_code_blocks: true,
28
+ start_inline: true,
29
+ })
30
+ end
31
+ end
32
+
33
+ class VoltaRender < HTML
34
+ def initialize(options)
35
+ @options = options
36
+ super(options)
37
+ end
38
+
39
+ def paragraph(text)
40
+ return text if @options[:skip_paragraph_surround]
41
+ "<p>#{text}</p>"
42
+ end
43
+
44
+ def table(header, body)
45
+ '<div class="Vlt-table Vlt-table--data Vlt-table--bordered">' \
46
+ '<table>' \
47
+ "<thead>#{header}</thead>" \
48
+ "<tbody>#{body}</tbody>" \
49
+ '</table>' \
50
+ '</div>'
51
+ end
52
+
53
+ def block_quote(quote)
54
+ '<div class="Vlt-callout Vlt-callout--tip">' \
55
+ '<i></i>' \
56
+ '<div class="Vlt-callout__content">' \
57
+ "#{quote}" \
58
+ '</div>' \
59
+ '</div>'
60
+ end
61
+
62
+ def image(link, _title, _alt_text)
63
+ '<figure>' \
64
+ '<img src="'\
65
+ "#{link}"\
66
+ '" alt="#{alt_text}">' \
67
+ '</figure>'
68
+ end
69
+
70
+ def list(contents, list_type)
71
+ if "#{list_type}" == 'unordered'
72
+ '<ul class="Vlt-list Vlt-list--simple">' \
73
+ "#{contents}" \
74
+ '</ul>'
75
+ else
76
+ '<ol class="Vlt-list Vlt-list--simple">' \
77
+ "#{contents}" \
78
+ '</ol>' \
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,41 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Modal < Banzai::Filter
6
+ def call(input)
7
+ modals = []
8
+
9
+ input.gsub!(/@\[(.+?)\]\((.+?)\)/) do |_s|
10
+ id = 'M' + SecureRandom.hex(12)
11
+ modals << { document: $2, id: id }
12
+ "<a data-modal='#{id}' class='Vlt-modal-trigger'>#{$1}</a>"
13
+ end
14
+
15
+ modals = modals.map do |modal|
16
+ filename = modal[:document]
17
+ raise "Could not find modal #{filename}" unless File.exist? filename
18
+
19
+ document = File.read(filename)
20
+ output = MarkdownPipeline.new.call(document)
21
+
22
+ modal = <<~HEREDOC
23
+ <div class="Vlt-modal" id="#{modal[:id]}">
24
+ <div class="Vlt-modal__panel">
25
+ <div class="Vlt-modal__content">
26
+ #{output}
27
+ </div>
28
+ </div>
29
+ </div>
30
+ HEREDOC
31
+
32
+ "FREEZESTART#{Base64.urlsafe_encode64(modal)}FREEZEEND"
33
+ end
34
+
35
+ input + modals.join("\n")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ module Nexmo
2
+ module OAS
3
+ module Renderer
4
+ module Filters
5
+ class Partial < Banzai::Filter
6
+ def call(input)
7
+ input.gsub(/```partial(.+?)```/m) do |_s|
8
+ config = YAML.safe_load($1)
9
+ content = File.read(config['source'])
10
+
11
+ active = options[:code_language] ? options[:code_language].key == config['platform'] : false
12
+
13
+ if config['platform']
14
+ <<~HEREDOC
15
+ <div class="js-platform" data-platform="#{config['platform']}" data-active="#{active}">
16
+ #{content.render_markdown}
17
+ </div>
18
+ HEREDOC
19
+ else
20
+ content
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end