nexmo_markdown_renderer 0.7.1 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nexmo_markdown_renderer.rb +0 -5
- data/lib/nexmo_markdown_renderer/filters/code_snippet/import_dependencies.rb +2 -1
- data/lib/nexmo_markdown_renderer/filters/code_snippet/initialize_dependencies.rb +2 -1
- data/lib/nexmo_markdown_renderer/filters/code_snippet/instructions.rb +2 -1
- data/lib/nexmo_markdown_renderer/filters/i18n/smartling/frontmatter_filter.rb +2 -2
- data/lib/nexmo_markdown_renderer/filters/tab_filter.rb +1 -0
- data/lib/nexmo_markdown_renderer/filters/utils.rb +4 -1
- data/lib/nexmo_markdown_renderer/models/tutorial/prerequisite.rb +1 -0
- data/lib/nexmo_markdown_renderer/models/use_case.rb +1 -1
- data/lib/nexmo_markdown_renderer/pipelines/smartling/download.rb +1 -2
- data/lib/nexmo_markdown_renderer/services/code_snippet_renderer/curl.rb +8 -0
- data/lib/nexmo_markdown_renderer/services/doc_finder.rb +7 -6
- data/lib/version.rb +1 -1
- metadata +2 -7
- data/lib/nexmo_markdown_renderer/filters/i18n/smartling/code_block_filter.rb +0 -20
- data/lib/nexmo_markdown_renderer/models/tutorial.rb +0 -192
- data/lib/nexmo_markdown_renderer/models/tutorial/file_loader.rb +0 -32
- data/lib/nexmo_markdown_renderer/models/tutorial/metadata.rb +0 -57
- data/lib/nexmo_markdown_renderer/models/tutorial/task.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7800ee97436dd0317d85c054ba7293f1207c2e0ac9e90b1f1f443df61319d51
|
4
|
+
data.tar.gz: cf859ca6c2f8d165e4057242f460dc4e0bdabe4419a4e25f94e0c1611181ccf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00fa691a0b76fabaa820fbc90bd68b87ab0a9a7bf4fa87a949f153fa4031845000375ec661f721154932db2f357bc4358ff1e6f8cc28d7808c52288db655ecee
|
7
|
+
data.tar.gz: fb66fcd2e4582e40ac53dfc1bd74af9ddaa13c22f71e9f0d62ab45bcc9986a51ad5c5801bc6e0dccfbe42f93e50682fc3bfd26d18eb0e2616f10f7ea90227419
|
@@ -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*(
|
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
|
@@ -26,7 +26,7 @@ module Nexmo
|
|
26
26
|
start_section + file_section + line_section
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.generate_code_block(language, input, unindent)
|
29
|
+
def self.generate_code_block(language, input, unindent, renderer)
|
30
30
|
return '' unless input
|
31
31
|
filename = "#{Nexmo::Markdown::Config.docs_base_path}/#{input['source']}"
|
32
32
|
raise "CodeSnippetFilter - Could not load #{filename} for language #{language}" unless File.exist?(filename)
|
@@ -42,6 +42,9 @@ module Nexmo
|
|
42
42
|
|
43
43
|
code = code.lines[from_line..to_line].join
|
44
44
|
code.unindent! if unindent
|
45
|
+
|
46
|
+
code = renderer.post_process(code) if renderer.respond_to?(:post_process)
|
47
|
+
|
45
48
|
formatter = Rouge::Formatters::HTML.new
|
46
49
|
formatter.format(lexer.lex(code))
|
47
50
|
end
|
@@ -22,6 +22,14 @@ module Nexmo
|
|
22
22
|
def self.add_instructions(filename)
|
23
23
|
::I18n.t('services.code_snippet_renderer.add_instructions_to_file', file: filename)
|
24
24
|
end
|
25
|
+
|
26
|
+
def self.post_process(code)
|
27
|
+
self.strip_single_quotes(code)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.strip_single_quotes(code)
|
31
|
+
code.gsub(/"'(\$\w+)'"/, '"\1"')
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
@@ -6,8 +6,8 @@ module Nexmo
|
|
6
6
|
EXCLUSIONS = ['.', '..', ::I18n.default_locale.to_s].freeze
|
7
7
|
|
8
8
|
class << self
|
9
|
-
|
10
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
|
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.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nexmo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-14 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
|