nexmo_markdown_renderer 0.7.4 → 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: 223be8922220948e621ffb0b0c8ff486358f8262b3507071f7fc78817f6d0e24
4
- data.tar.gz: 933d10ac4261586660cbc3642fbd9f6b2ed78249222d822b76b1798f708cf0da
3
+ metadata.gz: a7d22b5298177cc9423ba86447361a3d59f7f12428d62c2c623ee13f2760861b
4
+ data.tar.gz: 0c0bb88101ee6af385d924c6be9233ad98a41e106dcca73c591dac1f209a8426
5
5
  SHA512:
6
- metadata.gz: 46ebc7af03925d304df282b1fe09bbcd6bb3d6be83ca6e02db2b2220dfeff924f6e0d640be7ff2cf8416566653123a7472f822de75aa2162262e34c005ab6808
7
- data.tar.gz: 7cfe33bd3212392b6654a60ac2148817525abb530080701359648d9d6e67603063755db5eca09e1ee4b534f5490b4113a5b94116d5a178c06da6e324f75557ba
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,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:)
@@ -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.4'
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.4
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-12-22 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
@@ -289,11 +289,7 @@ files:
289
289
  - lib/nexmo_markdown_renderer/models/code_language.rb
290
290
  - lib/nexmo_markdown_renderer/models/code_snippet.rb
291
291
  - lib/nexmo_markdown_renderer/models/concept.rb
292
- - lib/nexmo_markdown_renderer/models/tutorial.rb
293
- - lib/nexmo_markdown_renderer/models/tutorial/file_loader.rb
294
- - lib/nexmo_markdown_renderer/models/tutorial/metadata.rb
295
292
  - lib/nexmo_markdown_renderer/models/tutorial/prerequisite.rb
296
- - lib/nexmo_markdown_renderer/models/tutorial/task.rb
297
293
  - lib/nexmo_markdown_renderer/models/use_case.rb
298
294
  - lib/nexmo_markdown_renderer/pipelines/smartling/download.rb
299
295
  - lib/nexmo_markdown_renderer/pipelines/smartling/preprocessor.rb
@@ -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