nexmo-oas-renderer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/.gitignore +5 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +183 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/nexmo-oas-renderer +5 -0
- data/lib/nexmo/oas/engine.rb +9 -0
- data/lib/nexmo/oas/renderer.rb +13 -0
- data/lib/nexmo/oas/renderer/app.rb +116 -0
- data/lib/nexmo/oas/renderer/config.ru +7 -0
- data/lib/nexmo/oas/renderer/config/code_languages.yml +138 -0
- data/lib/nexmo/oas/renderer/config/dynamic_content.yml +1 -0
- data/lib/nexmo/oas/renderer/config/redirects.yml +8 -0
- data/lib/nexmo/oas/renderer/constraints/open_api.rb +76 -0
- data/lib/nexmo/oas/renderer/constraints/redirector.rb +17 -0
- data/lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb +55 -0
- data/lib/nexmo/oas/renderer/filters/anchor.rb +17 -0
- data/lib/nexmo/oas/renderer/filters/audio.rb +21 -0
- data/lib/nexmo/oas/renderer/filters/block_escape.rb +24 -0
- data/lib/nexmo/oas/renderer/filters/break.rb +13 -0
- data/lib/nexmo/oas/renderer/filters/code.rb +64 -0
- data/lib/nexmo/oas/renderer/filters/code_snippet.rb +194 -0
- data/lib/nexmo/oas/renderer/filters/code_snippet_list.rb +33 -0
- data/lib/nexmo/oas/renderer/filters/code_snippets.rb +158 -0
- data/lib/nexmo/oas/renderer/filters/collapsible.rb +27 -0
- data/lib/nexmo/oas/renderer/filters/columns.rb +50 -0
- data/lib/nexmo/oas/renderer/filters/concept_list.rb +33 -0
- data/lib/nexmo/oas/renderer/filters/dynamic_content.rb +30 -0
- data/lib/nexmo/oas/renderer/filters/external_link.rb +32 -0
- data/lib/nexmo/oas/renderer/filters/frontmatter.rb +14 -0
- data/lib/nexmo/oas/renderer/filters/heading.rb +61 -0
- data/lib/nexmo/oas/renderer/filters/icon.rb +22 -0
- data/lib/nexmo/oas/renderer/filters/indent.rb +20 -0
- data/lib/nexmo/oas/renderer/filters/inline_escape.rb +17 -0
- data/lib/nexmo/oas/renderer/filters/js_sequence_diagram.rb +21 -0
- data/lib/nexmo/oas/renderer/filters/label.rb +32 -0
- data/lib/nexmo/oas/renderer/filters/language.rb +15 -0
- data/lib/nexmo/oas/renderer/filters/markdown.rb +85 -0
- data/lib/nexmo/oas/renderer/filters/modal.rb +41 -0
- data/lib/nexmo/oas/renderer/filters/partial.rb +28 -0
- data/lib/nexmo/oas/renderer/filters/php_inliner.rb +15 -0
- data/lib/nexmo/oas/renderer/filters/screenshot.rb +26 -0
- data/lib/nexmo/oas/renderer/filters/tab.rb +250 -0
- data/lib/nexmo/oas/renderer/filters/techio.rb +24 -0
- data/lib/nexmo/oas/renderer/filters/tooltip.rb +22 -0
- data/lib/nexmo/oas/renderer/filters/tutorial_link.rb +27 -0
- data/lib/nexmo/oas/renderer/filters/tutorials.rb +28 -0
- data/lib/nexmo/oas/renderer/filters/unfreeze.rb +20 -0
- data/lib/nexmo/oas/renderer/filters/user_personalization.rb +43 -0
- data/lib/nexmo/oas/renderer/helpers/navigation.rb +66 -0
- data/lib/nexmo/oas/renderer/helpers/render.rb +24 -0
- data/lib/nexmo/oas/renderer/helpers/summary.rb +30 -0
- data/lib/nexmo/oas/renderer/helpers/url.rb +17 -0
- data/lib/nexmo/oas/renderer/lib/core_ext/string.rb +14 -0
- data/lib/nexmo/oas/renderer/lib/redcarpet.rb +14 -0
- data/lib/nexmo/oas/renderer/models/code_snippet.rb +75 -0
- data/lib/nexmo/oas/renderer/models/tutorial.rb +83 -0
- data/lib/nexmo/oas/renderer/pipelines/markdown_pipeline.rb +52 -0
- data/lib/nexmo/oas/renderer/presenters/api_specification.rb +42 -0
- data/lib/nexmo/oas/renderer/presenters/groups.rb +35 -0
- data/lib/nexmo/oas/renderer/presenters/navigation.rb +24 -0
- data/lib/nexmo/oas/renderer/presenters/open_api_specification.rb +68 -0
- data/lib/nexmo/oas/renderer/presenters/versions.rb +40 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Black.woff +0 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Black.woff2 +0 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Heavy.woff +0 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Heavy.woff2 +0 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Regular.woff +0 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Regular.woff2 +0 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Semibold.woff +0 -0
- data/lib/nexmo/oas/renderer/public/assets/fonts/Lato-Semibold.woff2 +0 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/android.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/curl.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/dotnet.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/ios.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/java.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/javascript.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/node.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/php.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/python.svg +11 -0
- data/lib/nexmo/oas/renderer/public/assets/images/brands/ruby.svg +1 -0
- data/lib/nexmo/oas/renderer/public/assets/images/lost.svg +37 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/components/format.js +42 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.accordion.js +249 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.core.js +230 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.modal.js +300 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.tabs.js +139 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/api.css +95 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/buttons.css +80 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/core.css +79 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/mediaqueries.css +2 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/mediaqueries.css.map +7 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/navigation.css +79 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo.css +68 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/api.scss +147 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/core.scss +133 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/mediaqueries.scss +48 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/navigation.scss +106 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/nexmo.scss +61 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/style.scss +10 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/syntax.scss +63 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/typography.scss +248 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/variables.scss +91 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/volta-templates.scss +119 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/style.css +2 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/style.css.map +7 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/syntax.css +79 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/typography.css +86 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/variables.css +2 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/variables.css.map +7 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta-templates.css +2 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta-templates.css.map +7 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta.min.css +1 -0
- data/lib/nexmo/oas/renderer/public/assets/symbol/volta-icons.svg +1 -0
- data/lib/nexmo/oas/renderer/public/favicon.ico +0 -0
- data/lib/nexmo/oas/renderer/services/code_language_api.rb +98 -0
- data/lib/nexmo/oas/renderer/services/oas_parser.rb +21 -0
- data/lib/nexmo/oas/renderer/services/open_api_definition_resolver.rb +33 -0
- data/lib/nexmo/oas/renderer/version.rb +7 -0
- data/lib/nexmo/oas/renderer/views/api/show.erb +1 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/_application_messages_dispatch.html.erb +9 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/_application_rtc.html.erb +41 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/_application_voice.html.erb +24 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/_code_only.html.erb +6 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/_configure_client.html.erb +20 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/_dependencies.html.erb +11 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/_write_code.html.erb +13 -0
- data/lib/nexmo/oas/renderer/views/code_snippets/list/plain.html.erb +10 -0
- data/lib/nexmo/oas/renderer/views/concepts/list/plain.html.erb +5 -0
- data/lib/nexmo/oas/renderer/views/layouts/_head.erb +4 -0
- data/lib/nexmo/oas/renderer/views/layouts/_javascripts.erb +9 -0
- data/lib/nexmo/oas/renderer/views/layouts/api.erb +23 -0
- data/lib/nexmo/oas/renderer/views/layouts/open_api.erb +10 -0
- data/lib/nexmo/oas/renderer/views/open_api/_callback.erb +5 -0
- data/lib/nexmo/oas/renderer/views/open_api/_callback_endpoint.erb +48 -0
- data/lib/nexmo/oas/renderer/views/open_api/_code_examples.erb +16 -0
- data/lib/nexmo/oas/renderer/views/open_api/_endpoint.erb +156 -0
- data/lib/nexmo/oas/renderer/views/open_api/_model.erb +38 -0
- data/lib/nexmo/oas/renderer/views/open_api/_navigation.erb +80 -0
- data/lib/nexmo/oas/renderer/views/open_api/_parameter_groups.erb +50 -0
- data/lib/nexmo/oas/renderer/views/open_api/_parameters.erb +165 -0
- data/lib/nexmo/oas/renderer/views/open_api/_response_description_parameters.erb +61 -0
- data/lib/nexmo/oas/renderer/views/open_api/_response_descriptions.erb +41 -0
- data/lib/nexmo/oas/renderer/views/open_api/show.erb +104 -0
- data/lib/nexmo/oas/renderer/views/static/404.erb +6 -0
- data/lib/nexmo/oas/renderer/views/tutorials/_index.html.erb +32 -0
- data/lib/nexmo/oas/renderer/views/tutorials/index.html.erb +7 -0
- data/lib/nexmo/oas/renderer/views/tutorials/list/plain.html.erb +5 -0
- data/lib/nexmo/oas/renderer/views/tutorials/show.html.erb +8 -0
- data/nexmo-oas-renderer.gemspec +49 -0
- 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
|
+
<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,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
|