nexmo_markdown_renderer 0.4.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nexmo_markdown_renderer.rb +2 -0
- data/lib/nexmo_markdown_renderer/filters/i18n/frontmatter_filter.rb +1 -2
- data/lib/nexmo_markdown_renderer/filters/i18n/smartling/code_block_filter.rb +20 -0
- data/lib/nexmo_markdown_renderer/filters/i18n/smartling/escape_filter.rb +13 -0
- data/lib/nexmo_markdown_renderer/filters/i18n/smartling/frontmatter_filter.rb +22 -0
- data/lib/nexmo_markdown_renderer/filters/snippet_variables_filter.rb +34 -0
- data/lib/nexmo_markdown_renderer/filters/tooltip_filter.rb +1 -1
- data/lib/nexmo_markdown_renderer/markdown_renderer.rb +1 -0
- data/lib/nexmo_markdown_renderer/models/code_snippet.rb +21 -18
- data/lib/nexmo_markdown_renderer/pipelines/smartling/download.rb +17 -0
- data/lib/nexmo_markdown_renderer/pipelines/smartling/preprocessor.rb +15 -0
- data/lib/nexmo_markdown_renderer/views/code_snippets/_application_messages_dispatch.html.erb +4 -4
- data/lib/nexmo_markdown_renderer/views/code_snippets/_application_rtc.html.erb +4 -4
- data/lib/nexmo_markdown_renderer/views/code_snippets/_application_voice.html.erb +4 -4
- data/lib/nexmo_markdown_renderer/views/code_snippets/_configure_client.html.erb +5 -5
- data/lib/nexmo_markdown_renderer/views/code_snippets/_dependencies.html.erb +3 -3
- data/lib/nexmo_markdown_renderer/views/code_snippets/_import_dependencies.html.erb +4 -4
- data/lib/version.rb +1 -1
- metadata +8 -3
- data/lib/nexmo_markdown_renderer/filters/i18n/smartling_converter_filter.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41ef7bc208bcb98d22e13d771819af665bedfd65c2c5b8b1516b50bdcd0f0ed7
|
4
|
+
data.tar.gz: 5e6507ad1e17a66325a07b45397654798dbe0ae556a1633989ec4615a6f0569a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca682dbe30887f444fe7d858ab5090e3f1f3b07da8fdfd2b015adfff08a03dace1dd4f72d1d72266b8a787f4529e235839511237a5f0fd96966eaa7c51f5a453
|
7
|
+
data.tar.gz: 0df50b173c98b7b3e70c8f46790e224a3eabef5220edf0cd5c11909923c2ce1bfa018e065a4b971d49af84174dc26940d2cbc9e2e51cae20ecc6da410b7ff75b
|
@@ -51,4 +51,6 @@ require_relative 'nexmo_markdown_renderer/filters/code_snippet/run'
|
|
51
51
|
Dir[File.join(__dir__, 'nexmo_markdown_renderer/filters/concerns', '*.rb')].each { |file| require_relative file }
|
52
52
|
Dir[File.join(__dir__, 'nexmo_markdown_renderer/filters', '*.rb')].each { |file| require_relative file }
|
53
53
|
Dir[File.join(__dir__, 'nexmo_markdown_renderer/filters/i18n', '*.rb')].each { |file| require_relative file }
|
54
|
+
Dir[File.join(__dir__, 'nexmo_markdown_renderer/filters/i18n/smartling', '*.rb')].each { |file| require_relative file }
|
55
|
+
Dir[File.join(__dir__, 'nexmo_markdown_renderer/pipelines/smartling', '*.rb')].each { |file| require_relative file }
|
54
56
|
require_relative 'nexmo_markdown_renderer/markdown_renderer'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module Markdown
|
3
|
+
module I18n
|
4
|
+
module Smartling
|
5
|
+
class CodeBlockFilter < Banzai::Filter
|
6
|
+
def call(input)
|
7
|
+
input.gsub(/\n\n\s{4}(.*?)\n\n/m) do
|
8
|
+
<<~CODE_BLOCK
|
9
|
+
|
10
|
+
````
|
11
|
+
#{$1.split(/\n\s{4}/).join("\n")}
|
12
|
+
````
|
13
|
+
CODE_BLOCK
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module Markdown
|
3
|
+
module I18n
|
4
|
+
module Smartling
|
5
|
+
class EscapeFilter < Banzai::Filter
|
6
|
+
def call(input)
|
7
|
+
input.gsub('\-', '-').gsub('\|', '|').gsub('\[', '[').gsub('\]', ']').gsub('\(', '(').gsub('\)', ')').gsub(/^>\s\n+/, "\n")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module Markdown
|
3
|
+
module I18n
|
4
|
+
module Smartling
|
5
|
+
class FrontmatterFilter < Banzai::Filter
|
6
|
+
def call(input)
|
7
|
+
input.gsub(/\A\*\*\* \*\* \* \*\* \*\*\*\n*([^-]*)\n*-+/m) do |_frontmatter|
|
8
|
+
front = $1.gsub(/`(.*):`(.*)/) do |_config|
|
9
|
+
"#{$1}: #{$2}"
|
10
|
+
end
|
11
|
+
<<~FRONTMATTER
|
12
|
+
---
|
13
|
+
#{front}
|
14
|
+
---
|
15
|
+
FRONTMATTER
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module Markdown
|
3
|
+
class SnippetVariablesFilter < Banzai::Filter
|
4
|
+
def call(input)
|
5
|
+
input.gsub(/```snippet_variables(.+?)```/m) do |_s|
|
6
|
+
config = YAML.safe_load(Regexp.last_match(1))
|
7
|
+
|
8
|
+
raise 'No variables provided' unless config
|
9
|
+
raise 'Must provide an array' unless config.is_a?(Array)
|
10
|
+
|
11
|
+
output = <<~HEREDOC
|
12
|
+
Key | Description
|
13
|
+
-- | --
|
14
|
+
HEREDOC
|
15
|
+
config.each do |key|
|
16
|
+
details = variables[key]
|
17
|
+
raise "#{key} is not a valid snippet variable" unless details
|
18
|
+
raise "#{key} does not have a description" unless details['description']
|
19
|
+
|
20
|
+
output += <<~HEREDOC
|
21
|
+
`#{key}` | #{details['description']}
|
22
|
+
HEREDOC
|
23
|
+
end
|
24
|
+
|
25
|
+
output
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def variables
|
30
|
+
@variables ||= YAML.safe_load(File.read("#{Nexmo::Markdown::Config.docs_base_path}/config/code_snippet_variables.yml"))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -2,7 +2,7 @@ module Nexmo
|
|
2
2
|
module Markdown
|
3
3
|
class TooltipFilter < Banzai::Filter
|
4
4
|
def call(input)
|
5
|
-
input.gsub(/\^\[([a-zA-Z0-9\s:\-]+)\]\((.+?)\)/) do
|
5
|
+
input.gsub(/\^\[([\p{Han}a-zA-Z0-9\s:\-]+)\]\((.+?)\)/) do
|
6
6
|
tooltip = <<~HEREDOC
|
7
7
|
<span class="Vlt-tooltip Vlt-tooltip--top" title="#{$2}" tabindex="0">
|
8
8
|
#{$1}
|
@@ -3,20 +3,20 @@ module Nexmo
|
|
3
3
|
class CodeSnippet
|
4
4
|
include ActiveModel::Model
|
5
5
|
attr_accessor :title, :product, :category, :navigation_weight, :document_path, :url
|
6
|
-
|
6
|
+
|
7
7
|
def self.by_product(product)
|
8
8
|
all.select do |block|
|
9
9
|
block.product == product
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
def self.all
|
14
14
|
blocks = files.map do |document_path|
|
15
15
|
document = File.read(document_path)
|
16
16
|
product = extract_product(document_path)
|
17
|
-
|
17
|
+
|
18
18
|
frontmatter = YAML.safe_load(document)
|
19
|
-
|
19
|
+
|
20
20
|
Nexmo::Markdown::CodeSnippet.new({
|
21
21
|
title: frontmatter['title'],
|
22
22
|
navigation_weight: frontmatter['navigation_weight'] || 999,
|
@@ -26,47 +26,50 @@ module Nexmo
|
|
26
26
|
url: generate_url(document_path),
|
27
27
|
})
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
blocks.sort_by(&:navigation_weight)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def self.generate_url(path)
|
34
34
|
'/' + path.gsub(%r{#{origin}/\w{2}/}, '').gsub('.md', '')
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def self.extract_product(path)
|
38
38
|
# Remove the prefix
|
39
39
|
path = path.gsub!(%r{#{origin}/\w{2}/}, '')
|
40
|
-
|
40
|
+
|
41
41
|
# Each file is in the form code-snippets/<title>.md, so let's remove everything after code-snippets
|
42
42
|
path = path.gsub(%r{/code-snippets/.*}, '')
|
43
|
-
|
43
|
+
|
44
44
|
path
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def self.extract_category(path)
|
48
48
|
# Remove the prefix
|
49
49
|
path = path.gsub(%r{#{origin}/\w{2}/}, '')
|
50
|
-
|
50
|
+
|
51
51
|
# Each file is in the form code-snippets/<title>.md, so let's capture everything after code-snippets
|
52
52
|
path = path.gsub(%r{.*/code-snippets/(.*)$}, '\1')
|
53
|
-
|
53
|
+
|
54
54
|
parts = path.split('/')
|
55
55
|
parts = parts[0...-1]
|
56
|
-
|
56
|
+
|
57
57
|
return nil if parts.empty?
|
58
|
-
|
58
|
+
|
59
59
|
parts.join('/').tr('-', ' ').humanize
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def self.files
|
63
|
-
|
63
|
+
root = "#{origin}/#{::I18n.default_locale}"
|
64
|
+
Dir.glob("#{root}/**/code-snippets/**/*.md").map do |path|
|
65
|
+
DocFinder.find(root: origin, document: path.gsub(root, ''), language: ::I18n.locale).path
|
66
|
+
end
|
64
67
|
end
|
65
|
-
|
68
|
+
|
66
69
|
def self.origin
|
67
70
|
"#{Nexmo::Markdown::Config.docs_base_path}/_documentation"
|
68
71
|
end
|
69
72
|
end
|
70
|
-
|
73
|
+
|
71
74
|
end
|
72
75
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nexmo
|
2
|
+
module Markdown
|
3
|
+
module Pipelines
|
4
|
+
module Smartling
|
5
|
+
class Download < Banzai::Pipeline
|
6
|
+
def initialize(_options = {})
|
7
|
+
super(
|
8
|
+
I18n::Smartling::FrontmatterFilter,
|
9
|
+
I18n::Smartling::EscapeFilter,
|
10
|
+
I18n::Smartling::CodeBlockFilter
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/nexmo_markdown_renderer/views/code_snippets/_application_messages_dispatch.html.erb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
|
2
|
-
<
|
1
|
+
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis Vlt-accordion">
|
2
|
+
<button class="Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
|
3
3
|
<%= app['use_existing'] ? ::I18n.t('.code_snippets.use_your_app') : ::I18n.t('.code_snippets.create_an_app') %>
|
4
|
-
</
|
4
|
+
</button>
|
5
5
|
|
6
|
-
<div id="acc<%=id %>"
|
6
|
+
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<%= ::I18n.t('.code_snippets.application_messages_dispatch.no_application_html') %>
|
8
8
|
</div>
|
9
9
|
</div>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
|
2
|
-
<
|
1
|
+
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis Vlt-accordion">
|
2
|
+
<button class="Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
|
3
3
|
<%= ::I18n.t('.code_snippets.create_an_app') %>
|
4
|
-
</
|
4
|
+
</button>
|
5
5
|
|
6
|
-
<div id="acc<%=id %>" class="Vlt-
|
6
|
+
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<p><%= ::I18n.t('.code_snippets.nexmo_application_contains_html') %></p>
|
8
8
|
<h4><%= ::I18n.t('.code_snippets.install_the_cli') %></h4>
|
9
9
|
<pre class="Vlt-prism--dark dependencies command-line Vlt-prism--copy-disabled language-bash" data-prompt='$'><code>npm install -g nexmo-cli</code></pre>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
|
2
|
-
<
|
1
|
+
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis Vlt-accordion">
|
2
|
+
<button class="Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
|
3
3
|
<%= app['use_existing'] ? ::I18n.t('.code_snippets.use_your_app') : ::I18n.t('.code_snippets.create_an_app') %>
|
4
|
-
</
|
4
|
+
</button>
|
5
5
|
|
6
|
-
<div id="acc<%=id %>"
|
6
|
+
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<% if app['use_existing'] %>
|
8
8
|
<p><%= app['use_existing'] %></p>
|
9
9
|
<% else %>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis Vlt-accordion">
|
2
|
+
<button class="Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
|
3
|
+
<%= ::I18n.t('.code_snippets.configure_client.initialize_dependencies') %>
|
4
|
+
</button>
|
5
5
|
|
6
|
-
|
6
|
+
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<%= create_instructions %>
|
8
8
|
<div class="copy-wrapper">
|
9
9
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
|
2
|
-
<
|
1
|
+
<div class="Vlt-box Vlt-box--lesspadding Vlt-accordion Nxd-accordion-emphasis">
|
2
|
+
<button class="Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0"><%= title %></button>
|
3
3
|
|
4
|
-
<div id="acc<%= id %>" class="Vlt-
|
4
|
+
<div id="acc<%= id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
5
5
|
<p><%=deps['text']%></p>
|
6
6
|
<% if deps['code'] %>
|
7
7
|
<pre class="Vlt-prism--dark language-<%= deps['type'] || 'bash' %> dependencies command-line Vlt-prism--copy-disabled" data-prompt='$'><code><%=deps['code']%></code></pre>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
|
2
|
-
<
|
1
|
+
<div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis Vlt-accordion">
|
2
|
+
<button class="Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
|
3
3
|
<%= ::I18n.t('.code_snippets.configure_client.import_dependencies') %>
|
4
|
-
</
|
4
|
+
</button>
|
5
5
|
|
6
|
-
<div id="acc<%=id %>"
|
6
|
+
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<%= create_instructions %>
|
8
8
|
<div class="copy-wrapper">
|
9
9
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexmo_markdown_renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nexmo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: banzai
|
@@ -260,7 +260,9 @@ files:
|
|
260
260
|
- lib/nexmo_markdown_renderer/filters/frontmatter_filter.rb
|
261
261
|
- lib/nexmo_markdown_renderer/filters/heading_filter.rb
|
262
262
|
- lib/nexmo_markdown_renderer/filters/i18n/frontmatter_filter.rb
|
263
|
-
- lib/nexmo_markdown_renderer/filters/i18n/
|
263
|
+
- lib/nexmo_markdown_renderer/filters/i18n/smartling/code_block_filter.rb
|
264
|
+
- lib/nexmo_markdown_renderer/filters/i18n/smartling/escape_filter.rb
|
265
|
+
- lib/nexmo_markdown_renderer/filters/i18n/smartling/frontmatter_filter.rb
|
264
266
|
- lib/nexmo_markdown_renderer/filters/icon_filter.rb
|
265
267
|
- lib/nexmo_markdown_renderer/filters/indent_filter.rb
|
266
268
|
- lib/nexmo_markdown_renderer/filters/inline_escape_filter.rb
|
@@ -274,6 +276,7 @@ files:
|
|
274
276
|
- lib/nexmo_markdown_renderer/filters/php_inliner_filter.rb
|
275
277
|
- lib/nexmo_markdown_renderer/filters/relative_link_filter.rb
|
276
278
|
- lib/nexmo_markdown_renderer/filters/screenshot_filter.rb
|
279
|
+
- lib/nexmo_markdown_renderer/filters/snippet_variables_filter.rb
|
277
280
|
- lib/nexmo_markdown_renderer/filters/tab_filter.rb
|
278
281
|
- lib/nexmo_markdown_renderer/filters/techio_filter.rb
|
279
282
|
- lib/nexmo_markdown_renderer/filters/tooltip_filter.rb
|
@@ -293,6 +296,8 @@ files:
|
|
293
296
|
- lib/nexmo_markdown_renderer/models/tutorial/prerequisite.rb
|
294
297
|
- lib/nexmo_markdown_renderer/models/tutorial/task.rb
|
295
298
|
- lib/nexmo_markdown_renderer/models/use_case.rb
|
299
|
+
- lib/nexmo_markdown_renderer/pipelines/smartling/download.rb
|
300
|
+
- lib/nexmo_markdown_renderer/pipelines/smartling/preprocessor.rb
|
296
301
|
- lib/nexmo_markdown_renderer/services/code_snippet_renderer/android.rb
|
297
302
|
- lib/nexmo_markdown_renderer/services/code_snippet_renderer/base.rb
|
298
303
|
- lib/nexmo_markdown_renderer/services/code_snippet_renderer/curl.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Nexmo
|
2
|
-
module Markdown
|
3
|
-
module I18n
|
4
|
-
class SmartlingConverterFilter < Banzai::Filter
|
5
|
-
def call(input)
|
6
|
-
input = input.gsub(/\A\*\*\* \*\* \* \*\* \*\*\*\n*(.*)\n*------------------------------------------/m) do |_frontmatter|
|
7
|
-
front = $1.gsub(/`(.*):`(.*)/) do |_config|
|
8
|
-
"#{$1}:#{$2}"
|
9
|
-
end
|
10
|
-
<<~FRONTMATTER
|
11
|
-
---
|
12
|
-
#{front}
|
13
|
-
---
|
14
|
-
FRONTMATTER
|
15
|
-
end
|
16
|
-
input.gsub('\-', '-').gsub('\|', '|')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|