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,138 @@
|
|
1
|
+
terminal_programs:
|
2
|
+
curl:
|
3
|
+
weight: 1
|
4
|
+
label: cURL
|
5
|
+
lexer: sh
|
6
|
+
icon: curl
|
7
|
+
run_command: 'sh {filename}'
|
8
|
+
cli:
|
9
|
+
label: CLI
|
10
|
+
lexer: sh
|
11
|
+
linkable: false
|
12
|
+
|
13
|
+
languages:
|
14
|
+
javascript:
|
15
|
+
weight: 2
|
16
|
+
label: JavaScript
|
17
|
+
lexer: javascript
|
18
|
+
icon: javascript
|
19
|
+
dependencies:
|
20
|
+
- 'nexmo'
|
21
|
+
|
22
|
+
node:
|
23
|
+
weight: 2
|
24
|
+
label: Node.js
|
25
|
+
lexer: javascript
|
26
|
+
icon: node
|
27
|
+
dependencies:
|
28
|
+
- 'nexmo'
|
29
|
+
run_command: 'node {filename}'
|
30
|
+
|
31
|
+
java:
|
32
|
+
weight: 3
|
33
|
+
label: Java
|
34
|
+
lexer: java
|
35
|
+
unindent: true
|
36
|
+
icon: java
|
37
|
+
dependencies:
|
38
|
+
- 'com.nexmo:client:@latest'
|
39
|
+
|
40
|
+
dotnet:
|
41
|
+
weight: 4
|
42
|
+
label: .NET
|
43
|
+
lexer: c#
|
44
|
+
unindent: true
|
45
|
+
icon: dotnet
|
46
|
+
dependencies:
|
47
|
+
- 'Nexmo.Csharp.Client'
|
48
|
+
csharp:
|
49
|
+
weight: 4
|
50
|
+
label: .NET
|
51
|
+
lexer: c#
|
52
|
+
unindent: true
|
53
|
+
icon: dotnet
|
54
|
+
dependencies:
|
55
|
+
- 'Nexmo.Csharp.Client'
|
56
|
+
|
57
|
+
php:
|
58
|
+
weight: 5
|
59
|
+
label: PHP
|
60
|
+
lexer: php
|
61
|
+
icon: php
|
62
|
+
dependencies:
|
63
|
+
- 'nexmo/client'
|
64
|
+
run_command: 'php {filename}'
|
65
|
+
|
66
|
+
python:
|
67
|
+
weight: 6
|
68
|
+
label: Python
|
69
|
+
lexer: python
|
70
|
+
icon: python
|
71
|
+
dependencies:
|
72
|
+
- 'nexmo'
|
73
|
+
run_command: 'python {filename}'
|
74
|
+
|
75
|
+
ruby:
|
76
|
+
weight: 7
|
77
|
+
label: Ruby
|
78
|
+
lexer: ruby
|
79
|
+
icon: ruby
|
80
|
+
dependencies:
|
81
|
+
- 'nexmo'
|
82
|
+
run_command: 'ruby {filename}'
|
83
|
+
|
84
|
+
kotlin:
|
85
|
+
weight: 8
|
86
|
+
label: Kotlin
|
87
|
+
lexer: java
|
88
|
+
icon: android
|
89
|
+
dependencies: []
|
90
|
+
|
91
|
+
android:
|
92
|
+
weight: 9
|
93
|
+
label: Java
|
94
|
+
lexer: java
|
95
|
+
icon: android
|
96
|
+
dependencies: []
|
97
|
+
|
98
|
+
swift:
|
99
|
+
weight: 10
|
100
|
+
label: Swift
|
101
|
+
lexer: swift
|
102
|
+
icon: ios
|
103
|
+
dependencies: []
|
104
|
+
|
105
|
+
objective_c:
|
106
|
+
weight: 11
|
107
|
+
label: Objective-C
|
108
|
+
lexer: objective_c
|
109
|
+
icon: ios
|
110
|
+
dependencies: []
|
111
|
+
|
112
|
+
platforms:
|
113
|
+
ios:
|
114
|
+
languages:
|
115
|
+
- swift
|
116
|
+
- objective_c
|
117
|
+
android:
|
118
|
+
languages:
|
119
|
+
- java
|
120
|
+
web:
|
121
|
+
languages:
|
122
|
+
- javascript
|
123
|
+
|
124
|
+
data:
|
125
|
+
ncco:
|
126
|
+
label: NCCO
|
127
|
+
lexer: json
|
128
|
+
linkable: false
|
129
|
+
json:
|
130
|
+
weight: 1
|
131
|
+
label: JSON
|
132
|
+
lexer: json
|
133
|
+
linkable: false
|
134
|
+
xml:
|
135
|
+
weight: 2
|
136
|
+
label: XML
|
137
|
+
lexer: xml
|
138
|
+
linkable: false
|
@@ -0,0 +1 @@
|
|
1
|
+
dynamic_content_example: the future
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"/api/voice/ncco": "/voice/voice-api/ncco-reference"
|
2
|
+
"/api/account/secret-management": "/api/account#secret-management"
|
3
|
+
"/api/developer": "/api/numbers"
|
4
|
+
"/api/developer/numbers": "/api/numbers"
|
5
|
+
"/api/developer/account": "/api/account"
|
6
|
+
"/api/messages": "/api/developer/messages"
|
7
|
+
|
8
|
+
"/api/stitch": "/api/conversation"
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative '../services/code_language_api'
|
2
|
+
|
3
|
+
module Nexmo
|
4
|
+
module OAS
|
5
|
+
module Renderer
|
6
|
+
module Constraints
|
7
|
+
class OpenApi
|
8
|
+
|
9
|
+
OPEN_API_PRODUCTS = %w[
|
10
|
+
sms
|
11
|
+
media
|
12
|
+
number-insight
|
13
|
+
conversation
|
14
|
+
messages-olympus
|
15
|
+
dispatch
|
16
|
+
redact
|
17
|
+
audit
|
18
|
+
voice.v2
|
19
|
+
voice
|
20
|
+
account
|
21
|
+
external-accounts
|
22
|
+
numbers
|
23
|
+
verify
|
24
|
+
vonage-business-cloud/account
|
25
|
+
vonage-business-cloud/extension
|
26
|
+
vonage-business-cloud/user
|
27
|
+
application.v2
|
28
|
+
].freeze
|
29
|
+
|
30
|
+
def self.match?(definition, code_language = nil)
|
31
|
+
if code_language.nil?
|
32
|
+
products_with_code_language[:definition].match?(definition)
|
33
|
+
else
|
34
|
+
products_with_code_language[:definition].match?(definition) &&
|
35
|
+
products_with_code_language[:code_language].match?(code_language)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.list
|
40
|
+
OPEN_API_PRODUCTS
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.products
|
44
|
+
{ definition: Regexp.new("^(#{OPEN_API_PRODUCTS.join('|')})$") }
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.errors_available
|
48
|
+
all = OPEN_API_PRODUCTS.dup.concat(['application'])
|
49
|
+
{ definition: Regexp.new(all.join('|')) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.products_with_code_language
|
53
|
+
products.merge(CodeLanguageAPI.route_constraint)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.find_all_versions(name)
|
57
|
+
# Remove the .v2 etc if needed
|
58
|
+
name = name.gsub(/(\.v\d+)/, '')
|
59
|
+
|
60
|
+
matches = OPEN_API_PRODUCTS.select do |s|
|
61
|
+
s.start_with?(name) && !s.include?("#{name}/")
|
62
|
+
end
|
63
|
+
|
64
|
+
matches = matches.map do |s|
|
65
|
+
m = /\.v(\d+)/.match(s)
|
66
|
+
next { 'version' => '1', 'name' => s } unless m
|
67
|
+
{ 'version' => m[1], 'name' => s }
|
68
|
+
end
|
69
|
+
|
70
|
+
matches.sort_by { |v| v['version'] }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Nexmo
|
4
|
+
module OAS
|
5
|
+
module Renderer
|
6
|
+
module Constraints
|
7
|
+
class Redirector
|
8
|
+
REDIRECTS = YAML.load_file(File.expand_path("../config/redirects.yml", __dir__)) || {}
|
9
|
+
|
10
|
+
def self.find(request)
|
11
|
+
REDIRECTS[request.path] || false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rouge'
|
2
|
+
require 'neatjson'
|
3
|
+
require_relative '../services/oas_parser'
|
4
|
+
|
5
|
+
module Nexmo
|
6
|
+
module OAS
|
7
|
+
module Renderer
|
8
|
+
class ResponseParserDecorator < ::OasParser::ResponseParser
|
9
|
+
def formatted_json
|
10
|
+
JSON.neat_generate(parse, {
|
11
|
+
wrap: true,
|
12
|
+
after_colon: 1,
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
def formatted_xml(xml_options = {})
|
17
|
+
xml_options[:root] = xml_options['name'] if xml_options
|
18
|
+
xml_string = xml(xml_options)
|
19
|
+
xml_string.gsub!(%r{^(\s+?)(<(?:\w|\=|\"|\_|\s)+?\>)(.+?)(</.+?>)}).each do |s|
|
20
|
+
indentation = $1
|
21
|
+
indentation_plus_one = "#{$1} "
|
22
|
+
opening_tag = $2
|
23
|
+
content = $3
|
24
|
+
closing_tag = $4
|
25
|
+
|
26
|
+
next(s) if (indentation.size + opening_tag.size + content.size) < 60
|
27
|
+
|
28
|
+
next "#{indentation}#{opening_tag}\n#{indentation_plus_one}#{content}\n#{indentation}#{closing_tag}"
|
29
|
+
end
|
30
|
+
|
31
|
+
xml_string
|
32
|
+
end
|
33
|
+
|
34
|
+
def html(format = 'application/json', xml_options: nil)
|
35
|
+
formatter = Rouge::Formatters::HTML.new
|
36
|
+
|
37
|
+
case format
|
38
|
+
when 'application/json'
|
39
|
+
lexer = Rouge::Lexer.find('json')
|
40
|
+
highlighted_response = formatter.format(lexer.lex(formatted_json))
|
41
|
+
when 'text/xml', 'application/xml'
|
42
|
+
lexer = Rouge::Lexer.find('xml')
|
43
|
+
highlighted_response = formatter.format(lexer.lex(formatted_xml(xml_options)))
|
44
|
+
end
|
45
|
+
|
46
|
+
output = <<~HEREDOC
|
47
|
+
<pre class="highlight json"><code>#{highlighted_response}</code></pre>
|
48
|
+
HEREDOC
|
49
|
+
|
50
|
+
output
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module OAS
|
3
|
+
module Renderer
|
4
|
+
module Filters
|
5
|
+
class Anchor < Banzai::Filter
|
6
|
+
def call(input)
|
7
|
+
input.gsub(/^[\u{2693}](.+?)\n/) do
|
8
|
+
<<~HEREDOC
|
9
|
+
<a name="#{$1.parameterize}"></a>
|
10
|
+
HEREDOC
|
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 Audio < Banzai::Filter
|
6
|
+
def call(input)
|
7
|
+
input.gsub(/[u{🔈}]\[(.+?)\]/) do
|
8
|
+
audio = <<~HEREDOC
|
9
|
+
<audio controls>
|
10
|
+
<source src="#{$1}" type="audio/mpeg">
|
11
|
+
</audio>
|
12
|
+
HEREDOC
|
13
|
+
|
14
|
+
"FREEZESTART#{Base64.urlsafe_encode64(audio)}FREEZEEND"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module OAS
|
3
|
+
module Renderer
|
4
|
+
module Filters
|
5
|
+
class BlockEscape < Banzai::Filter
|
6
|
+
def call(input)
|
7
|
+
# Freeze to prevent Markdown formatting
|
8
|
+
input.gsub(/````\n(.+?)````/m) do |_s|
|
9
|
+
lexer = Rouge::Lexer.find('text')
|
10
|
+
formatter = Rouge::Formatters::HTML.new
|
11
|
+
highlighted_source = formatter.format(lexer.lex($1))
|
12
|
+
|
13
|
+
output = <<~HEREDOC
|
14
|
+
<pre class="highlight #{lexer.tag}"><code>#{highlighted_source}</code></pre>
|
15
|
+
HEREDOC
|
16
|
+
|
17
|
+
"FREEZESTART#{Base64.urlsafe_encode64(output)}FREEZEEND"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module OAS
|
3
|
+
module Renderer
|
4
|
+
module Filters
|
5
|
+
class Code < Banzai::Filter
|
6
|
+
def call(input)
|
7
|
+
input.gsub(/(?!.*snippet)```code(.+?)```/m) do |_s|
|
8
|
+
config = YAML.safe_load($1)
|
9
|
+
|
10
|
+
if config['config']
|
11
|
+
configs = YAML.load_file("#{API.root}/config/code_examples.yml")
|
12
|
+
config = config['config'].split('.').inject(configs) { |h, k| h[k] }
|
13
|
+
end
|
14
|
+
|
15
|
+
code = File.read("#{API.root}/#{config['source']}")
|
16
|
+
language = File.extname("#{API.root}/#{config['source']}")[1..-1]
|
17
|
+
lexer = language_to_lexer(language)
|
18
|
+
|
19
|
+
total_lines = code.lines.count
|
20
|
+
|
21
|
+
# Minus one since lines are not zero-indexed
|
22
|
+
from_line = (config['from_line'] || 1) - 1
|
23
|
+
to_line = (config['to_line'] || total_lines) - 1
|
24
|
+
|
25
|
+
code = code.lines[from_line..to_line].join
|
26
|
+
code.unindent! if config['unindent']
|
27
|
+
|
28
|
+
highlighted_source = highlight(code, lexer)
|
29
|
+
|
30
|
+
<<~HEREDOC
|
31
|
+
<pre class="highlight #{lexer.tag}"><code>#{highlighted_source}</code></pre>
|
32
|
+
HEREDOC
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def highlight(source, lexer)
|
39
|
+
formatter = Rouge::Formatters::HTML.new
|
40
|
+
formatter.format(lexer.lex(source))
|
41
|
+
end
|
42
|
+
|
43
|
+
def language_to_lexer_name(language)
|
44
|
+
if language_configuration[language]
|
45
|
+
language_configuration[language]['lexer']
|
46
|
+
else
|
47
|
+
language
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def language_to_lexer(language)
|
52
|
+
language = language_to_lexer_name(language)
|
53
|
+
return Rouge::Lexers::PHP.new({ start_inline: true }) if language == 'php'
|
54
|
+
Rouge::Lexer.find(language.downcase) || Rouge::Lexer.find('text')
|
55
|
+
end
|
56
|
+
|
57
|
+
def language_configuration
|
58
|
+
@language_configuration ||= YAML.load_file("#{API.root}/config/code_languages.yml")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|