nexmo_markdown_renderer 0.4.3 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe9250e32774af04ea28ec4dc345d674abe07e513b41e99ca99747101988d035
4
- data.tar.gz: 062731fbb4162919f74a193f413454691347543b86f8b52283864a0ddc7d9b6f
3
+ metadata.gz: a77a40b7cc8162d5b8087bcf750f3cff31a5c0962991cb90d0f7d573ade580ec
4
+ data.tar.gz: 0c15812da744a7215555c04a4d026b8fe3a61454952a98c4b17255c86fd08104
5
5
  SHA512:
6
- metadata.gz: 2f880c2e23c71f0e64fc5520567224a1ed19e3ba6c075985d0e0c587ceb44c56b1ee06fdb4d62e27fb9f305b24f550f1ac2c9d83705a0feb27b474cc9ebdf7dc
7
- data.tar.gz: e87719a922f7ad01a9896a26eaffbb05c8d693392f6f153a4a34b954d3249afc8274e0499ba4f5c677533e5cc2866148abbe92a5d95007b34bf3fe7faf0adbd0
6
+ metadata.gz: 6a37388e6c4173e69184d9836da5b7619a81439d49768bf3c08c89f84c53eb6257c1c142f91255fd2b0681c072dcfe37a9c94517ef210e356223a9e5ac56ac50
7
+ data.tar.gz: b4cf624eb1215e4379f938ae1688d416a7fb3bbcb347650363afb3b1d7b81f8e5f76b8d12efd3ad7a83177398b32f1af8969f87532a3cc6d69586d66f6a91037
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Nexmo Markdown Renderer
2
2
 
3
- [![Build Status](https://api.travis-ci.org/Nexmo/nexmo-markdown-renderer.svg?branch=master)](https://travis-ci.org/Nexmo/nexmo-markdown-renderer/)
3
+ ![Build Status](https://github.com/Nexmo/nexmo-markdown-renderer/workflows/CI/badge.svg)
4
4
  [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.txt)
5
5
 
6
6
  This gem facilitates the presentation of markdown documents in a Rails app by applying custom filters for tabs, code snippets, icons, indentation and more. It is used in the [Nexmo Developer Platform](https://developer.nexmo.com).
@@ -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'
@@ -11,6 +11,5 @@ module Nexmo
11
11
  end
12
12
  end
13
13
  end
14
-
15
14
  end
16
- end
15
+ end
@@ -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
@@ -63,7 +63,9 @@ module Nexmo
63
63
  '<figure>' \
64
64
  '<img src="'\
65
65
  "#{link}"\
66
- '" alt="#{alt_text}">' \
66
+ '" alt="'\
67
+ "#{_alt_text}"\
68
+ '">' \
67
69
  '</figure>'
68
70
  end
69
71
 
@@ -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}&nbsp;
@@ -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
- Dir.glob("#{origin}/**/code-snippets/**/*.md")
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
@@ -0,0 +1,15 @@
1
+ module Nexmo
2
+ module Markdown
3
+ module Pipelines
4
+ module Smartling
5
+ class Preprocessor < Banzai::Pipeline
6
+ def initialize(_options = {})
7
+ super(
8
+ I18n::FrontmatterFilter
9
+ )
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,9 @@
1
- <div class="Vlt-box Vlt-box--lesspadding Nxd-accordion-emphasis">
2
- <h5 class="Vlt-js-accordion__trigger Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
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
- </h5>
4
+ </button>
5
5
 
6
- <div id="acc<%=id %>" class="Vlt-js-accordion__content Vlt-accordion__content Vlt-accordion__content--noborder">
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
- <h5 class="Vlt-js-accordion__trigger Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
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
- </h5>
4
+ </button>
5
5
 
6
- <div id="acc<%=id %>" class="Vlt-js-accordion__content Vlt-accordion__content Vlt-accordion__content--noborder">
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
- <h5 class="Vlt-js-accordion__trigger Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
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
- </h5>
4
+ </button>
5
5
 
6
- <div id="acc<%=id %>" class="Vlt-js-accordion__content Vlt-accordion__content Vlt-accordion__content--noborder">
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
- <h5 class="Vlt-js-accordion__trigger Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
3
- <%= ::I18n.t('.code_snippets.configure_client.initialize_dependencies') %>
4
- </h5>
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
- <div id="acc<%=id %>" class="Vlt-js-accordion__content Vlt-accordion__content Vlt-accordion__content--noborder">
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
- <h5 class="Vlt-js-accordion__trigger Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0"><%= title %></h5>
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-js-accordion__content Vlt-accordion__content Vlt-accordion__content--noborder">
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
- <h5 class="Vlt-js-accordion__trigger Vlt-accordion__trigger" data-accordion="acc<%= id %>" tabindex="0">
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
- </h5>
4
+ </button>
5
5
 
6
- <div id="acc<%=id %>" class="Vlt-js-accordion__content Vlt-accordion__content Vlt-accordion__content--noborder">
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
1
  # :nocov:
2
2
  module Nexmo
3
3
  module Markdown
4
- VERSION = '0.4.3'
4
+ VERSION = '0.5.1'
5
5
  end
6
6
  end
7
7
  # :nocov:
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.3
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nexmo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2020-11-17 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/smartling_converter_filter.rb
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
@@ -293,6 +295,8 @@ files:
293
295
  - lib/nexmo_markdown_renderer/models/tutorial/prerequisite.rb
294
296
  - lib/nexmo_markdown_renderer/models/tutorial/task.rb
295
297
  - lib/nexmo_markdown_renderer/models/use_case.rb
298
+ - lib/nexmo_markdown_renderer/pipelines/smartling/download.rb
299
+ - lib/nexmo_markdown_renderer/pipelines/smartling/preprocessor.rb
296
300
  - lib/nexmo_markdown_renderer/services/code_snippet_renderer/android.rb
297
301
  - lib/nexmo_markdown_renderer/services/code_snippet_renderer/base.rb
298
302
  - lib/nexmo_markdown_renderer/services/code_snippet_renderer/curl.rb
@@ -345,8 +349,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
345
349
  - !ruby/object:Gem::Version
346
350
  version: '0'
347
351
  requirements: []
348
- rubyforge_project:
349
- rubygems_version: 2.7.6.2
352
+ rubygems_version: 3.0.1
350
353
  signing_key:
351
354
  specification_version: 4
352
355
  summary: Middleware to render Markdown Documents in Nexmo Developer Platform.
@@ -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