nexmo_markdown_renderer 0.7.0 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77ca5e9a51e8e1d8d1e0d3e0fad14c48fb01ab3fc67e893e2c2e45f1061b0d5d
4
- data.tar.gz: d83bcc9efe2cd831553a5dc9c362f2f6db75fd3553ebad6d312172571fdcf23a
3
+ metadata.gz: a7d22b5298177cc9423ba86447361a3d59f7f12428d62c2c623ee13f2760861b
4
+ data.tar.gz: 0c0bb88101ee6af385d924c6be9233ad98a41e106dcca73c591dac1f209a8426
5
5
  SHA512:
6
- metadata.gz: 951a51a1bdebc045a64769796ce16aaa1262c3f889730485aff1051a320f4b21c658505ace846cfc0b7dd9ed6db75d8cb1046eba2481c4b4ec79b623980ce6c7
7
- data.tar.gz: 4b93e1a292a403cc32726d63ff18eba1ebb6f26fc6e28e944fa4fb87eebd5682466edfa83620d21d6e1b3bf5386da4963900b620e9ec65e439552fc63b244871
6
+ metadata.gz: d2ed733f1228b84a32bbef3a86ee4ad56f6506218ee7dc24faa77ec032f29fede9be1fef2db733bfc1491b03faff6f485dec206d07d36a44e650b14a54a079ea
7
+ data.tar.gz: 4cd84845df9bdc696dee67041b0d0f3c05d43c118f99b17158dd1179320963d54c5d80a71cd87a92e4cd8997e77ea0f9e517686fe24319b8de4d1dd1a1985bb9
@@ -32,11 +32,6 @@ require_relative 'nexmo_markdown_renderer/services/doc_finder/doc'
32
32
  require_relative 'nexmo_markdown_renderer/models/code_language'
33
33
  require_relative 'nexmo_markdown_renderer/models/code_snippet'
34
34
  require_relative 'nexmo_markdown_renderer/models/concept'
35
- require_relative 'nexmo_markdown_renderer/models/tutorial'
36
- require_relative 'nexmo_markdown_renderer/models/tutorial/file_loader'
37
- require_relative 'nexmo_markdown_renderer/models/tutorial/metadata'
38
- require_relative 'nexmo_markdown_renderer/models/tutorial/prerequisite'
39
- require_relative 'nexmo_markdown_renderer/models/tutorial/task'
40
35
  require_relative 'nexmo_markdown_renderer/models/use_case'
41
36
 
42
37
  require_relative 'nexmo_markdown_renderer/filters/code_snippet/binding'
@@ -1,10 +1,10 @@
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)!?(----+|\*\*\* \*\* \* \*\* \*\*\*)\n*/m) do |_frontmatter|
7
+ input.gsub(/\A\*\*\* \*\* \* \*\* \*\*\*\n*(.*?\n)!?(\*\*\* \*\* \* \*\* \*\*\*|----+)\n*/m) do |_frontmatter|
8
8
  front = $1.gsub(/`products: (.*)`\n\n/) do |products|
9
9
  "products: #{$1}\n\n"
10
10
  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
 
@@ -1,6 +1,7 @@
1
1
  module Nexmo
2
2
  module Markdown
3
3
  class Tutorial::Prerequisite
4
+ attr_accessor :name
4
5
  delegate :content, :yaml, to: :@file_loader
5
6
 
6
7
  def initialize(current_step:, code_language:, name:)
@@ -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
@@ -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
@@ -68,10 +68,11 @@ module Nexmo
68
68
 
69
69
  def self.build_key(root:, document:, product: nil, format: nil)
70
70
  path = if Pathname.new(document).extname.blank?
71
- "#{root}/#{product}/#{document}.#{format}"
72
- else
73
- "#{root}/#{product}/#{document}"
74
- end
71
+ [root, product, document].compact.join("/").concat(".#{format}")
72
+ else
73
+ [root, product, document].compact.join("/")
74
+ end
75
+
75
76
  path.gsub(%r{\/\/\/|\/\/}, '/')
76
77
  end
77
78
 
@@ -1,7 +1,7 @@
1
1
  # :nocov:
2
2
  module Nexmo
3
3
  module Markdown
4
- VERSION = '0.7.0'
4
+ VERSION = '0.7.5'
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.7.0
4
+ version: 0.7.5
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-26 00:00:00.000000000 Z
11
+ date: 2021-01-12 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
@@ -290,11 +289,7 @@ files:
290
289
  - lib/nexmo_markdown_renderer/models/code_language.rb
291
290
  - lib/nexmo_markdown_renderer/models/code_snippet.rb
292
291
  - lib/nexmo_markdown_renderer/models/concept.rb
293
- - lib/nexmo_markdown_renderer/models/tutorial.rb
294
- - lib/nexmo_markdown_renderer/models/tutorial/file_loader.rb
295
- - lib/nexmo_markdown_renderer/models/tutorial/metadata.rb
296
292
  - lib/nexmo_markdown_renderer/models/tutorial/prerequisite.rb
297
- - lib/nexmo_markdown_renderer/models/tutorial/task.rb
298
293
  - lib/nexmo_markdown_renderer/models/use_case.rb
299
294
  - lib/nexmo_markdown_renderer/pipelines/smartling/download.rb
300
295
  - lib/nexmo_markdown_renderer/pipelines/smartling/preprocessor.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
@@ -1,192 +0,0 @@
1
- module Nexmo
2
- module Markdown
3
- class Tutorial
4
- include ActiveModel::Model
5
-
6
- attr_reader :name, :current_step
7
- delegate :path, :yaml, to: :@file_loader
8
- delegate :available_code_languages, to: :metadata
9
-
10
- def initialize(name:, current_step:, current_product: nil, code_language: nil)
11
- @name = name
12
- @current_step = current_step
13
- @product = current_product
14
- @language = code_language
15
- @file_loader = load_file!
16
- end
17
-
18
- def metadata
19
- @metadata ||= Metadata.new(name: name)
20
- end
21
-
22
- def current_product
23
- @current_product ||= @product || metadata.default_product
24
- end
25
-
26
- def code_language
27
- @code_language ||= @language || metadata.code_language
28
- end
29
-
30
- def title
31
- @title ||= yaml['title'] || metadata.title
32
- end
33
-
34
- def description
35
- @description ||= yaml['description'] || metadata.description
36
- end
37
-
38
- def products
39
- @products ||= yaml['products'] || metadata.products
40
- end
41
-
42
- def prerequisites
43
- @prerequisites ||= (yaml['prerequisites'] || []).map do |prereq|
44
- Prerequisite.new(name: prereq, code_language: code_language, current_step: current_step)
45
- end
46
- end
47
-
48
- def content_for(step_name)
49
- if ['introduction', 'conclusion'].include? step_name
50
- raise "Invalid step: #{step_name}" unless yaml[step_name]
51
-
52
- return yaml[step_name]['content']
53
- end
54
-
55
- path = Nexmo::Markdown::DocFinder.find(
56
- root: self.class.task_content_path,
57
- document: step_name,
58
- language: ::I18n.locale,
59
- code_language: code_language
60
- ).path
61
-
62
- File.read(path)
63
- end
64
-
65
- def first_step
66
- subtasks.first&.name
67
- end
68
-
69
- def prerequisite?
70
- prerequisites.map(&:name).include?(@current_step)
71
- end
72
-
73
- def next_step
74
- current_task_index = subtasks.map(&:name).index(@current_step)
75
- return nil unless current_task_index
76
-
77
- subtasks[current_task_index + 1]
78
- end
79
-
80
- def previous_step
81
- current_task_index = subtasks.map(&:name).index(@current_step)
82
- return nil unless current_task_index
83
- return nil if current_task_index <= 0
84
-
85
- subtasks[current_task_index - 1]
86
- end
87
-
88
- def subtasks
89
- @subtasks ||= begin
90
- tasks = []
91
-
92
- (yaml['tasks'] || []).map do |t|
93
- tasks.push(
94
- Task.make_from(
95
- name: t,
96
- code_language: code_language,
97
- current_step: current_step
98
- )
99
- )
100
- end
101
-
102
- tasks.unshift(prerequisite_task)
103
- tasks.unshift(introduction_task)
104
- tasks.push(conclusion_task)
105
-
106
- tasks.compact
107
- end
108
- end
109
-
110
- def self.load_prerequisites(prerequisites, current_step)
111
- return [] unless prerequisites
112
-
113
- prerequisites.map do |t|
114
- t_path = Nexmo::Markdown::DocFinder.find(
115
- root: task_content_path,
116
- document: t,
117
- language: ::I18n.locale
118
- ).path
119
- raise "Prerequisite not found: #{t}" unless File.exist? t_path
120
-
121
- content = File.read(t_path)
122
- prereq = YAML.safe_load(content)
123
- {
124
- 'path' => t,
125
- 'title' => prereq['title'],
126
- 'description' => prereq['description'],
127
- 'is_active' => t == current_step,
128
- 'content' => content,
129
- }
130
- end
131
- end
132
-
133
- def prerequisite_task
134
- return if prerequisites.empty?
135
-
136
- Task.new(
137
- name: 'prerequisites',
138
- title: 'Prerequisites',
139
- description: 'Everything you need to complete this task',
140
- current_step: current_step
141
- )
142
- end
143
-
144
- def introduction_task
145
- return unless yaml['introduction']
146
-
147
- Task.new(
148
- name: 'introduction',
149
- title: yaml['introduction']['title'],
150
- description: yaml['introduction']['description'],
151
- current_step: current_step
152
- )
153
- end
154
-
155
- def conclusion_task
156
- return unless yaml['conclusion']
157
-
158
- Task.new(
159
- name: 'conclusion',
160
- title: yaml['conclusion']['title'],
161
- description: yaml['conclusion']['description'],
162
- current_step: current_step
163
- )
164
- end
165
-
166
- def self.load(name, current_step, current_product = nil, code_language = nil)
167
- new(
168
- name: name,
169
- current_step: current_step,
170
- current_product: current_product,
171
- code_language: code_language
172
- )
173
- end
174
-
175
- def load_file!
176
- Tutorial::FileLoader.new(
177
- root: self.class.tutorials_path,
178
- code_language: code_language,
179
- doc_name: name
180
- )
181
- end
182
-
183
- def self.task_content_path
184
- "#{Nexmo::Markdown::Config.docs_base_path}/_tutorials"
185
- end
186
-
187
- def self.tutorials_path
188
- 'config/tutorials'
189
- end
190
- end
191
- end
192
- end
@@ -1,32 +0,0 @@
1
- module Nexmo
2
- module Markdown
3
- class Tutorial::FileLoader
4
- attr_reader :root, :code_language, :doc_name, :format
5
-
6
- def initialize(root:, code_language:, doc_name:, format: 'yml')
7
- @root = root
8
- @code_language = code_language
9
- @doc_name = doc_name
10
- @format = format
11
- end
12
-
13
- def path
14
- @path ||= Nexmo::Markdown::DocFinder.find(
15
- root: root,
16
- document: doc_name,
17
- language: ::I18n.locale,
18
- code_language: code_language,
19
- format: format
20
- ).path
21
- end
22
-
23
- def content
24
- @content ||= File.read(path)
25
- end
26
-
27
- def yaml
28
- @yaml ||= YAML.safe_load(content)
29
- end
30
- end
31
- end
32
- end
@@ -1,57 +0,0 @@
1
- module Nexmo
2
- module Markdown
3
- class Tutorial::Metadata
4
- attr_reader :name, :file_loader
5
- delegate :path, :yaml, to: :file_loader
6
-
7
- def initialize(name:)
8
- @name = name
9
- @file_loader = load_file!
10
- end
11
-
12
- def products
13
- @products ||= yaml['products'] || []
14
- end
15
-
16
- def title
17
- @title ||= yaml['title']
18
- end
19
-
20
- def description
21
- @description ||= yaml['description']
22
- end
23
-
24
- def external_link
25
- @external_link ||= yaml['external_link']
26
- end
27
-
28
- def available_code_languages
29
- @available_code_languages ||= begin
30
- DocFinder
31
- .code_languages_for_tutorial(path: path.sub('.yml', '/'))
32
- .map { |file_path| File.basename(Pathname.new(file_path).basename, '.yml') }
33
- .sort_by { |l| CodeLanguage.find(l).weight }
34
- end
35
- end
36
-
37
- def code_language
38
- @code_language ||= begin
39
- available_code_languages
40
- .min_by { |k| CodeLanguage.languages.map(&:key).index(k) }
41
- end
42
- end
43
-
44
- def default_product
45
- @default_product ||= products.first
46
- end
47
-
48
- def load_file!
49
- Tutorial::FileLoader.new(
50
- root: Tutorial.tutorials_path,
51
- code_language: nil,
52
- doc_name: @name
53
- )
54
- end
55
- end
56
- end
57
- end
@@ -1,49 +0,0 @@
1
- module Nexmo
2
- module Markdown
3
- class Tutorial::Task
4
- attr_reader :name, :title, :description, :current_step
5
-
6
- def initialize(name:, title:, description:, current_step:)
7
- @name = name
8
- @title = title
9
- @description = description
10
- @current_step = current_step
11
- end
12
-
13
- def active?
14
- @name == @current_step
15
- end
16
-
17
- def self.make_from(name:, code_language:, current_step:)
18
- file_loader = Tutorial::FileLoader.new(
19
- root: Tutorial.task_content_path,
20
- doc_name: name,
21
- code_language: code_language,
22
- format: 'md'
23
- )
24
-
25
- new(
26
- name: name,
27
- title: file_loader.yaml['title'],
28
- description: file_loader.yaml['description'],
29
- current_step: current_step
30
- )
31
- end
32
-
33
- def ==(other)
34
- name == other.name &&
35
- title == other.title &&
36
- description == other.description &&
37
- current_step == other.current_step
38
- end
39
-
40
- def eql?(other)
41
- self == other
42
- end
43
-
44
- def hash
45
- name.hash ^ title.hash ^ description.hash ^ current_step.hash
46
- end
47
- end
48
- end
49
- end