nexmo_markdown_renderer 0.4.5 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fed5ac6ec1e55aa65964370c584baa463dbc160d0e27eb649489ce866298f713
4
- data.tar.gz: cb14711f686b58901619ed1dea31f171d8283c1afa5eb6413cf8e989a004a421
3
+ metadata.gz: 77ca5e9a51e8e1d8d1e0d3e0fad14c48fb01ab3fc67e893e2c2e45f1061b0d5d
4
+ data.tar.gz: d83bcc9efe2cd831553a5dc9c362f2f6db75fd3553ebad6d312172571fdcf23a
5
5
  SHA512:
6
- metadata.gz: 272e32a46296d8273f4242bc3a728c3bb9e6cdb8aeb53a9f8a78dc6ea30d636cb9a41122fa4eea3b1635d0e8e6702bc81b2d2075d957b1e8013b7781994ec7bb
7
- data.tar.gz: af90dfafa2ae3c9de263d36edfba57ed6af5a3c16aeb44abfc974fd2856512e0ec84e4d515aff280506a93d5f290f429d58040ecc31adfd4d8117f2867d560de
6
+ metadata.gz: 951a51a1bdebc045a64769796ce16aaa1262c3f889730485aff1051a320f4b21c658505ace846cfc0b7dd9ed6db75d8cb1046eba2481c4b4ec79b623980ce6c7
7
+ data.tar.gz: 4b93e1a292a403cc32726d63ff18eba1ebb6f26fc6e28e944fa4fb87eebd5682466edfa83620d21d6e1b3bf5386da4963900b620e9ec65e439552fc63b244871
@@ -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'
@@ -2,9 +2,16 @@ module Nexmo
2
2
  module Markdown
3
3
  module Concerns
4
4
  module PrismCodeSnippet
5
+ include OcticonsHelper
6
+
5
7
  def code_snippet_body(lexer, body)
6
8
  <<~HEREDOC
7
- <pre class="#{prism_css_classes(lexer)}"><code>#{body}</code></pre>
9
+ <div class="copy-wrapper">
10
+ <div class="copy-button" data-lang="#{code_language_to_prism(lexer.tag)}" data-section="code">
11
+ #{octicon "clippy", :class => 'top left'} <span>#{::I18n.t('code_snippets.copy_to_clipboard') }</span>
12
+ </div>
13
+ <pre class="#{prism_css_classes(lexer)}"><code>#{body}</code></pre>
14
+ </div>
8
15
  HEREDOC
9
16
  end
10
17
 
@@ -4,13 +4,23 @@ module Nexmo
4
4
  class FrontmatterFilter < Banzai::Filter
5
5
  def call(input)
6
6
  input.gsub(/\A(---.+?---)/mo) do |frontmatter|
7
- frontmatter.gsub(/(\w*:)/) do |_key|
8
- "```#{$1}```"
7
+ output = frontmatter.gsub(/^languages:\n(^\s+- ([a-zA-Z]+)\n)+/) do |languages|
8
+ languages.gsub(/^\s+- ([a-zA-Z]+)\n+/) do |language|
9
+ " - ```#{$1}```\n\n"
10
+ end
9
11
  end
12
+ output = output.gsub(/^(\w*:)(.*)\n/) do |_key|
13
+ if $1 == "products:"
14
+ "```#{$1}#{$2}```\n\n"
15
+ else
16
+ "```#{$1}```#{$2}\n\n"
17
+ end
18
+ end
19
+
20
+ output
10
21
  end
11
22
  end
12
23
  end
13
24
  end
14
-
15
25
  end
16
- end
26
+ 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,38 @@
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)!?(----+|\*\*\* \*\* \* \*\* \*\*\*)\n*/m) do |_frontmatter|
8
+ front = $1.gsub(/`products: (.*)`\n\n/) do |products|
9
+ "products: #{$1}\n\n"
10
+ end
11
+
12
+ front = front.gsub(/`(.*):`(.*)/) do |_config|
13
+ "#{$1}: #{$2}"
14
+ end
15
+
16
+ front = front.gsub(/languages: \n\n(.*)\n/m) do |_languages|
17
+ languages = $1.split("\n\n").map do |lang|
18
+ lang.gsub(/\* `(.*)`/) { |_l| " - #{$1}" }
19
+ end
20
+ <<~LANGUAGES
21
+ languages:
22
+ #{languages.join("\n")}
23
+ LANGUAGES
24
+ end
25
+
26
+ <<~FRONTMATTER
27
+ ---
28
+ #{front}
29
+ ---
30
+
31
+ FRONTMATTER
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -91,8 +91,10 @@ module Nexmo
91
91
  code.gsub! /^ /, "\t"
92
92
  end
93
93
 
94
- formatter = ::Rouge::Formatters::HTMLLegacy.new(:css_class => prism_css_classes(lexer))
95
- formatter.format(lexer.lex(code))
94
+ formatter ||= Rouge::Formatters::HTML.new
95
+ highlighted_source = formatter.format(lexer.lex(code))
96
+
97
+ code_snippet_body(lexer, highlighted_source)
96
98
  end
97
99
  end
98
100
  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}&nbsp;
@@ -29,6 +29,7 @@ module Nexmo
29
29
  ConceptListFilter.new(options),
30
30
  LanguageFilter,
31
31
  ColumnsFilter,
32
+ SnippetVariablesFilter,
32
33
  MarkdownFilter.new(options),
33
34
 
34
35
  # As HTML
@@ -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,7 +1,7 @@
1
1
  # :nocov:
2
2
  module Nexmo
3
3
  module Markdown
4
- VERSION = '0.4.5'
4
+ VERSION = '0.7.0'
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.5
4
+ version: 0.7.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-03 00:00:00.000000000 Z
11
+ date: 2020-11-26 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
@@ -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
@@ -345,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
345
350
  - !ruby/object:Gem::Version
346
351
  version: '0'
347
352
  requirements: []
348
- rubygems_version: 3.1.4
353
+ rubygems_version: 3.0.1
349
354
  signing_key:
350
355
  specification_version: 4
351
356
  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