nexmo_markdown_renderer 0.6.0 → 0.7.4

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: 41ef7bc208bcb98d22e13d771819af665bedfd65c2c5b8b1516b50bdcd0f0ed7
4
- data.tar.gz: 5e6507ad1e17a66325a07b45397654798dbe0ae556a1633989ec4615a6f0569a
3
+ metadata.gz: 223be8922220948e621ffb0b0c8ff486358f8262b3507071f7fc78817f6d0e24
4
+ data.tar.gz: 933d10ac4261586660cbc3642fbd9f6b2ed78249222d822b76b1798f708cf0da
5
5
  SHA512:
6
- metadata.gz: ca682dbe30887f444fe7d858ab5090e3f1f3b07da8fdfd2b015adfff08a03dace1dd4f72d1d72266b8a787f4529e235839511237a5f0fd96966eaa7c51f5a453
7
- data.tar.gz: 0df50b173c98b7b3e70c8f46790e224a3eabef5220edf0cd5c11909923c2ce1bfa018e065a4b971d49af84174dc26940d2cbc9e2e51cae20ecc6da410b7ff75b
6
+ metadata.gz: 46ebc7af03925d304df282b1fe09bbcd6bb3d6be83ca6e02db2b2220dfeff924f6e0d640be7ff2cf8416566653123a7472f822de75aa2162262e34c005ab6808
7
+ data.tar.gz: 7cfe33bd3212392b6654a60ac2148817525abb530080701359648d9d6e67603063755db5eca09e1ee4b534f5490b4113a5b94116d5a178c06da6e324f75557ba
@@ -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,9 +4,20 @@ 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
@@ -1,17 +1,33 @@
1
- module Nexmo
1
+ module Nexmo
2
2
  module Markdown
3
3
  module I18n
4
4
  module Smartling
5
5
  class FrontmatterFilter < Banzai::Filter
6
6
  def call(input)
7
- input.gsub(/\A\*\*\* \*\* \* \*\* \*\*\*\n*([^-]*)\n*-+/m) do |_frontmatter|
8
- front = $1.gsub(/`(.*):`(.*)/) do |_config|
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|
9
13
  "#{$1}: #{$2}"
10
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
+
11
26
  <<~FRONTMATTER
12
27
  ---
13
28
  #{front}
14
29
  ---
30
+
15
31
  FRONTMATTER
16
32
  end
17
33
  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
@@ -13,12 +13,16 @@ module Nexmo
13
13
  -- | --
14
14
  HEREDOC
15
15
  config.each do |key|
16
+
16
17
  details = variables[key]
17
18
  raise "#{key} is not a valid snippet variable" unless details
18
- raise "#{key} does not have a description" unless details['description']
19
+
20
+ # We have some variables in the format TO_NUMBER.SMS etc, and we only want to render the first segment
21
+ # This can be multiple segments e.g. UUID.MODIFY.VOICE will be rendered as UUID
22
+ title = key.split('.').first
19
23
 
20
24
  output += <<~HEREDOC
21
- `#{key}` | #{details['description']}
25
+ `#{title}` | #{details}
22
26
  HEREDOC
23
27
  end
24
28
 
@@ -65,7 +65,7 @@ module Nexmo
65
65
  end
66
66
 
67
67
  private_class_method def self.files
68
- Dir.glob("#{origin}/**/*.md")
68
+ Dir.glob("#{origin}/#{::I18n.default_locale}/**/*.md")
69
69
  end
70
70
  end
71
71
  end
@@ -6,8 +6,7 @@ module Nexmo
6
6
  def initialize(_options = {})
7
7
  super(
8
8
  I18n::Smartling::FrontmatterFilter,
9
- I18n::Smartling::EscapeFilter,
10
- I18n::Smartling::CodeBlockFilter
9
+ I18n::Smartling::EscapeFilter
11
10
  )
12
11
  end
13
12
  end
@@ -5,7 +5,7 @@ module Nexmo
5
5
  class Preprocessor < Banzai::Pipeline
6
6
  def initialize(_options = {})
7
7
  super(
8
- I18n::FrontmatterFilter
8
+ I18n::FrontmatterFilter,
9
9
  )
10
10
  end
11
11
  end
@@ -6,8 +6,8 @@ module Nexmo
6
6
  EXCLUSIONS = ['.', '..', ::I18n.default_locale.to_s].freeze
7
7
 
8
8
  class << self
9
- mattr_accessor :paths
10
- mattr_accessor :dictionary
9
+ attr_accessor :paths
10
+ attr_accessor :dictionary
11
11
  end
12
12
 
13
13
  # rubocop:disable Metrics/ParameterLists
@@ -1,7 +1,7 @@
1
1
  # :nocov:
2
2
  module Nexmo
3
3
  module Markdown
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.4'
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.6.0
4
+ version: 0.7.4
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-25 00:00:00.000000000 Z
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: banzai
@@ -260,7 +260,6 @@ 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/code_block_filter.rb
264
263
  - lib/nexmo_markdown_renderer/filters/i18n/smartling/escape_filter.rb
265
264
  - lib/nexmo_markdown_renderer/filters/i18n/smartling/frontmatter_filter.rb
266
265
  - lib/nexmo_markdown_renderer/filters/icon_filter.rb
@@ -1,20 +0,0 @@
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