nexmo_markdown_renderer 0.7.4 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/config/locales/en.yml +2 -2
- data/lib/nexmo_markdown_renderer.rb +1 -6
- data/lib/nexmo_markdown_renderer/cli.rb +11 -0
- data/lib/nexmo_markdown_renderer/config/load_config.rb +2 -2
- data/lib/nexmo_markdown_renderer/filters/code_snippet/import_dependencies.rb +2 -2
- data/lib/nexmo_markdown_renderer/filters/code_snippet/initialize_dependencies.rb +2 -2
- data/lib/nexmo_markdown_renderer/filters/code_snippet/instructions.rb +2 -2
- data/lib/nexmo_markdown_renderer/filters/code_snippet/run.rb +0 -1
- data/lib/nexmo_markdown_renderer/filters/code_snippet_filter.rb +0 -1
- data/lib/nexmo_markdown_renderer/filters/concerns/prism_code_snippet.rb +3 -9
- data/lib/nexmo_markdown_renderer/filters/markdown_filter.rb +7 -8
- data/lib/nexmo_markdown_renderer/filters/partial_filter.rb +1 -1
- data/lib/nexmo_markdown_renderer/filters/tab_filter.rb +4 -1
- data/lib/nexmo_markdown_renderer/filters/utils.rb +4 -1
- data/lib/nexmo_markdown_renderer/markdown_renderer.rb +0 -1
- data/lib/nexmo_markdown_renderer/models/tutorial/prerequisite.rb +1 -0
- data/lib/nexmo_markdown_renderer/services/code_snippet_renderer/base.rb +1 -1
- 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/nexmo_markdown_renderer/views/code_snippets/_application_rtc.html.erb +2 -2
- data/lib/nexmo_markdown_renderer/views/code_snippets/_application_voice.html.erb +2 -2
- data/lib/nexmo_markdown_renderer/views/code_snippets/_code_only.html.erb +1 -6
- data/lib/nexmo_markdown_renderer/views/code_snippets/_configure_client.html.erb +1 -7
- data/lib/nexmo_markdown_renderer/views/code_snippets/_dependencies.html.erb +1 -1
- data/lib/nexmo_markdown_renderer/views/code_snippets/_import_dependencies.html.erb +1 -7
- data/lib/nexmo_markdown_renderer/views/code_snippets/_write_code.html.erb +1 -7
- data/lib/version.rb +1 -1
- metadata +16 -20
- data/lib/nexmo_markdown_renderer/filters/screenshot_filter.rb +0 -22
- 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: 81cc4aad0e0e959c6e5c48d4ded1043bbd484801fa60f5d928f0715a8c7faf39
|
4
|
+
data.tar.gz: 80f21fe3c430da34d783c18270859ba19849114ed1c0b187fd8c4a88c0304190
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a3611e6b67f8855616768ecd88ff6cca7f8a3f5151a071637ab1e369ba042a91d5fb0d8896b3a53fcc56608106743fc39eaff7348305f6bf5d2771ca52b54c5
|
7
|
+
data.tar.gz: '09e3a7b5ad0f872aaef2f587d4d4e8aa43566b24d160db0f858d4d18ff2ab83790ba51b04bf6e51230a7669cda74e8ca7448d1b4ac5418cd0d19e3e90232aac5'
|
data/README.md
CHANGED
@@ -6,11 +6,15 @@
|
|
6
6
|
This gem facilitates the presentation of markdown documents in a Rails app by applying custom filters for tabs, code snippets, icons, indentation and more. It is used in the [Nexmo Developer Platform](https://developer.nexmo.com).
|
7
7
|
|
8
8
|
* [Installation and Usage](#installation-and-usage)
|
9
|
+
* [In An Application](#in-an-application)
|
10
|
+
* [CLI Standlone](#cli-standalone)
|
9
11
|
* [Contributing](#contributing)
|
10
12
|
* [License](#license)
|
11
13
|
|
12
14
|
## Installation and Usage
|
13
15
|
|
16
|
+
### In An Application
|
17
|
+
|
14
18
|
To use this gem you must install it in your application's Gemfile:
|
15
19
|
|
16
20
|
```ruby
|
@@ -45,6 +49,22 @@ Passing in a markdown file:
|
|
45
49
|
rendered = content.call("/_documentation/example/example_markdown.md")
|
46
50
|
```
|
47
51
|
|
52
|
+
### CLI Standalone
|
53
|
+
|
54
|
+
To use the markdown renderer with the built-in CLI, you first must install the gem locally:
|
55
|
+
|
56
|
+
```bash
|
57
|
+
$ gem install nexmo-markdown-renderer
|
58
|
+
```
|
59
|
+
|
60
|
+
Once the gem is installed you can use the CLI to generate HTML output for a provided markdown file. To do so, you must specify both a path to the documentation folder and the specific markdown file you wish to render:
|
61
|
+
|
62
|
+
```bash
|
63
|
+
$ DOCS_BASE_PATH=path/to/docs bundle exec nexmo-markdown-renderer render _documentation/path/sample.md
|
64
|
+
```
|
65
|
+
|
66
|
+
The converted HTML output will be displayed in your console.
|
67
|
+
|
48
68
|
## Contributing
|
49
69
|
|
50
70
|
We ❤️ contributions from everyone! [Bug reports](https://github.com/Nexmo/nexmo-markdown-renderer/issues), [bug fixes](https://github.com/Nexmo/nexmo-markdown-renderer/pulls) and feedback on the gem is always appreciated. Look at the [Contributor Guidelines](https://github.com/Nexmo/nexmo-markdown-renderer/blob/master/CONTRIBUTING.md) for more information.
|
data/config/locales/en.yml
CHANGED
@@ -153,7 +153,7 @@ en:
|
|
153
153
|
run_command: >-
|
154
154
|
## Run your code
|
155
155
|
Save this file to your machine and run it:
|
156
|
-
<pre class="Vlt-prism--dark command-line language-bash
|
156
|
+
<pre class="Vlt-prism--dark command-line language-bash" data-prompt="$"><code>%{command}</code></pre>
|
157
157
|
|
158
158
|
curl:
|
159
159
|
only_permitted_dependency: The only permitted curl dependency is `jwt`
|
@@ -174,4 +174,4 @@ en:
|
|
174
174
|
|
175
175
|
Run the following `gradle` command to execute your application, replacing `%{chomped_package}` with the package containing `%{file}`:
|
176
176
|
|
177
|
-
<pre class="language-shell Vlt-prism--dark command-line
|
177
|
+
<pre class="language-shell Vlt-prism--dark command-line" data-prompt="$"><code>gradle run -Pmain=%{main}</code></pre>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
GEM_ROOT = File.expand_path("../..", __FILE__)
|
3
3
|
require 'banzai'
|
4
|
-
require 'octicons_helper'
|
5
4
|
require 'nokogiri'
|
6
5
|
require 'open-uri'
|
7
6
|
require 'active_model'
|
7
|
+
require 'action_view'
|
8
8
|
require 'i18n'
|
9
9
|
|
10
10
|
require_relative 'nexmo_markdown_renderer/config/load_config'
|
@@ -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'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "thor"
|
2
|
+
require_relative "../nexmo_markdown_renderer"
|
3
|
+
require_relative "initializers/doc_finder"
|
4
|
+
module Nexmo::Markdown
|
5
|
+
class CLI < Thor
|
6
|
+
desc "render FILE", "passes FILE throught the pipeline and renders it as html"
|
7
|
+
def render(file)
|
8
|
+
puts Nexmo::Markdown::Renderer.new.call(File.read("#{ENV['DOCS_BASE_PATH']}/#{file}")).to_s
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -2,8 +2,8 @@ module Nexmo
|
|
2
2
|
module Markdown
|
3
3
|
class Config
|
4
4
|
def self.docs_base_path
|
5
|
-
@docs_base_path ||=
|
5
|
+
@docs_base_path ||= ENV.fetch('DOCS_BASE_PATH', '.')
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
@@ -3,7 +3,6 @@ module Nexmo
|
|
3
3
|
module Filters
|
4
4
|
module CodeSnippet
|
5
5
|
class ImportDependencies
|
6
|
-
include OcticonsHelper
|
7
6
|
include Renderable
|
8
7
|
|
9
8
|
attr_reader :config
|
@@ -21,7 +20,8 @@ module Nexmo
|
|
21
20
|
@highlighted_import_source ||= ::Nexmo::Markdown::Utils.generate_code_block(
|
22
21
|
language,
|
23
22
|
@config,
|
24
|
-
unindent
|
23
|
+
unindent,
|
24
|
+
renderer
|
25
25
|
)
|
26
26
|
end
|
27
27
|
|
@@ -3,7 +3,6 @@ module Nexmo
|
|
3
3
|
module Filters
|
4
4
|
module CodeSnippet
|
5
5
|
class InitializeDependencies
|
6
|
-
include OcticonsHelper
|
7
6
|
include Renderable
|
8
7
|
|
9
8
|
def initialize(config, snippet)
|
@@ -19,7 +18,8 @@ module Nexmo
|
|
19
18
|
@highlighted_client_source ||= ::Nexmo::Markdown::Utils.generate_code_block(
|
20
19
|
language,
|
21
20
|
@config,
|
22
|
-
unindent
|
21
|
+
unindent,
|
22
|
+
renderer
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
@@ -3,7 +3,6 @@ module Nexmo
|
|
3
3
|
module Filters
|
4
4
|
module CodeSnippet
|
5
5
|
class Instructions
|
6
|
-
include OcticonsHelper
|
7
6
|
include Renderable
|
8
7
|
|
9
8
|
attr_reader :config
|
@@ -27,7 +26,8 @@ module Nexmo
|
|
27
26
|
@highlighted_code_source ||= ::Nexmo::Markdown::Utils.generate_code_block(
|
28
27
|
language,
|
29
28
|
@config['code'],
|
30
|
-
unindent
|
29
|
+
unindent,
|
30
|
+
renderer
|
31
31
|
)
|
32
32
|
end
|
33
33
|
|
@@ -2,16 +2,10 @@ 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
|
+
def code_snippet_body(lexer, body, options = {})
|
8
7
|
<<~HEREDOC
|
9
|
-
<
|
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
|
+
<pre class="#{prism_css_classes(lexer)}" data-lang="#{code_language_to_prism(lexer.tag)}" data-section="code" data-block="#{options[:block]}"><code>#{body.chomp}</code></pre>
|
15
9
|
HEREDOC
|
16
10
|
end
|
17
11
|
|
@@ -21,7 +15,7 @@ module Nexmo
|
|
21
15
|
|
22
16
|
def prism_css_classes(lexer)
|
23
17
|
code_language = code_language_to_prism(lexer.tag)
|
24
|
-
"main-code Vlt-prism--dark language-#{code_language}
|
18
|
+
"main-code Vlt-prism--dark language-#{code_language}"
|
25
19
|
end
|
26
20
|
end
|
27
21
|
end
|
@@ -60,13 +60,12 @@ module Nexmo
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def image(link, _title, _alt_text)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
'</figure>'
|
63
|
+
<<~IMAGE
|
64
|
+
<figure>
|
65
|
+
<img src="#{link}" alt="#{_alt_text}">
|
66
|
+
<figcaption class="Vlt-center"><em>#{_alt_text}</em></figcaption>
|
67
|
+
</figure>
|
68
|
+
IMAGE
|
70
69
|
end
|
71
70
|
|
72
71
|
def list(contents, list_type)
|
@@ -94,7 +93,7 @@ module Nexmo
|
|
94
93
|
formatter ||= Rouge::Formatters::HTML.new
|
95
94
|
highlighted_source = formatter.format(lexer.lex(code))
|
96
95
|
|
97
|
-
code_snippet_body(lexer, highlighted_source)
|
96
|
+
code_snippet_body(lexer, highlighted_source, @options)
|
98
97
|
end
|
99
98
|
end
|
100
99
|
end
|
@@ -4,7 +4,7 @@ module Nexmo
|
|
4
4
|
def call(input)
|
5
5
|
input.gsub(/```partial(.+?)```/m) do |_s|
|
6
6
|
config = YAML.safe_load($1)
|
7
|
-
file_path = if config['source'].
|
7
|
+
file_path = if config['source'].start_with? 'app/views'
|
8
8
|
"#{Rails.root}/#{config['source']}"
|
9
9
|
else
|
10
10
|
"#{Nexmo::Markdown::Config.docs_base_path}/#{config['source']}"
|
@@ -29,6 +29,7 @@ module Nexmo
|
|
29
29
|
tab['class'] = 'Vlt-tabs__link'
|
30
30
|
tab['class'] += ' Vlt-tabs__link_active' if content[:active]
|
31
31
|
tab['role'] = 'tab'
|
32
|
+
tab['id'] = content[:tab_title].parameterize
|
32
33
|
|
33
34
|
if content[:language]
|
34
35
|
tab['data-language'] = content[:language].key
|
@@ -208,7 +209,9 @@ module Nexmo
|
|
208
209
|
content[:language_key] = content[:frontmatter]['language']
|
209
210
|
content[:platform_key] = content[:frontmatter]['platform']
|
210
211
|
content[:tab_title] = content[:frontmatter]['title']
|
211
|
-
content[:body] = Nexmo::Markdown::Renderer.new(
|
212
|
+
content[:body] = Nexmo::Markdown::Renderer.new(
|
213
|
+
options.merge(block: content[:tab_title].parameterize)
|
214
|
+
).call(source)
|
212
215
|
|
213
216
|
content
|
214
217
|
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
|
@@ -3,7 +3,7 @@ module Nexmo
|
|
3
3
|
module CodeSnippetRenderer
|
4
4
|
class Base
|
5
5
|
def self.inherited(base)
|
6
|
-
base.extend ActionView::Helpers::TranslationHelper
|
6
|
+
base.extend ::ActionView::Helpers::TranslationHelper
|
7
7
|
base.instance_variable_set :@virtual_path, "services.#{base.name.underscore.tr('/', '.')}"
|
8
8
|
end
|
9
9
|
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
|
|
@@ -56,7 +56,7 @@ module Nexmo
|
|
56
56
|
# rubocop:enable Metrics/ParameterLists
|
57
57
|
|
58
58
|
def self.build_doc(root:, language:, key:)
|
59
|
-
if root.
|
59
|
+
if root.start_with?('app/views')
|
60
60
|
DocFinder::Doc.new(path: dictionary.fetch(key) && key, available_languages: ['en'])
|
61
61
|
else
|
62
62
|
available_languages = dictionary.fetch(key)
|
@@ -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
|
|
@@ -91,7 +92,7 @@ module Nexmo
|
|
91
92
|
|
92
93
|
def self.load_english
|
93
94
|
paths.each do |path|
|
94
|
-
if defined?(Rails) && path.
|
95
|
+
if defined?(Rails::Application) && path.start_with?("#{Rails.root}/app/views")
|
95
96
|
Dir["#{path}/**/*.*"].each do |file|
|
96
97
|
dictionary[file.gsub("#{Rails.root}/", '')][::I18n.default_locale.to_s] = ::I18n.default_locale.to_s
|
97
98
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<p><%= ::I18n.t('.code_snippets.nexmo_application_contains_html') %></p>
|
8
8
|
<h4><%= ::I18n.t('.code_snippets.install_the_cli') %></h4>
|
9
|
-
<pre class="Vlt-prism--dark dependencies command-line
|
9
|
+
<pre class="Vlt-prism--dark dependencies command-line language-bash" data-prompt='$'><code>npm install -g nexmo-cli</code></pre>
|
10
10
|
|
11
11
|
<h4><%= ::I18n.t('.code_snippets.create_an_app') %></h4>
|
12
12
|
<p><%= ::I18n.t('.code_snippets.once_you_have_the_cli_installed_html') %></p>
|
@@ -15,7 +15,7 @@
|
|
15
15
|
<p><%= ::I18n.t('.code_snippets.nexmo_needs_to_connect_html') %></p>
|
16
16
|
<% end %>
|
17
17
|
|
18
|
-
<pre class="Vlt-prism--dark dependencies command-line
|
18
|
+
<pre class="Vlt-prism--dark dependencies command-line language-bash" data-prompt='$'><code>nexmo app:create "<%= name %>" <%= answer_url %> <%= event_url %> --keyfile=private.key --type=rtc</code></pre>
|
19
19
|
|
20
20
|
<h4><%= ::I18n.t('.code_snippets.application_rtc.use_your_existing_app') %></h4>
|
21
21
|
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<% else %>
|
10
10
|
<p><%= ::I18n.t('.code_snippets.nexmo_application_contains_html') %></p>
|
11
11
|
<h4><%= ::I18n.t('.code_snippets.install_the_cli') %></h4>
|
12
|
-
<pre class="Vlt-prism--dark dependencies command-line
|
12
|
+
<pre class="Vlt-prism--dark dependencies command-line language-bash" data-prompt='$'><code>npm install -g nexmo-cli</code></pre>
|
13
13
|
|
14
14
|
<h4><%= ::I18n.t('.code_snippets.create_an_app') %></h4>
|
15
15
|
<p><%= ::I18n.t('.code_snippets.once_you_have_the_cli_installed_html') %></p>
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<p><%= ::I18n.t('.code_snippets.nexmo_needs_to_connect_html') %></p>
|
19
19
|
<% end %>
|
20
20
|
|
21
|
-
<pre class="Vlt-prism--dark dependencies command-line
|
21
|
+
<pre class="Vlt-prism--dark dependencies command-line language-bash" data-prompt='$'><code>nexmo app:create "<%= name %>" <%= answer_url %> <%= event_url %> --keyfile private.key</code></pre>
|
22
22
|
<% end %>
|
23
23
|
</div>
|
24
24
|
</div>
|
@@ -1,6 +1 @@
|
|
1
|
-
<
|
2
|
-
<div class="copy-button" data-lang="<%= lang %>" data-block="<%= config['source'] %>" data-section="code">
|
3
|
-
<%= octicon "clippy", :class => 'top left' %> <span><%= ::I18n.t('.copy-to-clipboad') %></span>
|
4
|
-
</div>
|
5
|
-
<pre class="language-<%= lexer.tag %> main-code Vlt-prism--dark Vlt-prism--copy-disabled"><code><%= highlighted_code_source %></code></pre>
|
6
|
-
</div>
|
1
|
+
<pre class="language-<%= lexer.tag %> main-code Vlt-prism--dark" data-lang="<%= lang %>" data-block="<%= config['source'] %>" data-section="code"><code><%= highlighted_code_source %></code></pre>
|
@@ -5,13 +5,7 @@
|
|
5
5
|
|
6
6
|
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<%= create_instructions %>
|
8
|
-
<
|
9
|
-
|
10
|
-
<div class="copy-button" data-lang="<%= lang %>" data-block="<%= source %>" data-section="configure">
|
11
|
-
<%= octicon "clippy", :class => 'top left' %> <span>Copy to Clipboard</span>
|
12
|
-
</div>
|
13
|
-
<pre class="Vlt-prism--dark language-<%= lexer.tag %> Vlt-prism--copy-disabled"><code><%= highlighted_client_source %></code></pre>
|
14
|
-
</div>
|
8
|
+
<pre class="Vlt-prism--dark language-<%= lexer.tag %>" data-lang="<%= lang %>" data-block="<%= source %>" data-section="configure"><code><%= highlighted_client_source %></code></pre>
|
15
9
|
|
16
10
|
<p><a data-section="configure" data-lang="<%= lang %>" data-block="<%= source %>" href="<%= client_url %>">View full source</a></p>
|
17
11
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
<div id="acc<%= id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
5
5
|
<p><%=deps['text']%></p>
|
6
6
|
<% if deps['code'] %>
|
7
|
-
<pre class="Vlt-prism--dark language-<%= deps['type'] || 'bash' %> dependencies command-line
|
7
|
+
<pre class="Vlt-prism--dark language-<%= deps['type'] || 'bash' %> dependencies command-line" data-prompt='$'><code><%=deps['code']%></code></pre>
|
8
8
|
<% end %>
|
9
9
|
</div>
|
10
10
|
</div>
|
@@ -5,13 +5,7 @@
|
|
5
5
|
|
6
6
|
<div id="acc<%=id %>" class="Vlt-accordion__content Vlt-accordion__content--noborder">
|
7
7
|
<%= create_instructions %>
|
8
|
-
<
|
9
|
-
|
10
|
-
<div class="copy-button" data-lang="<%= lang %>" data-block="<%= config['source'] %>" data-section="configure">
|
11
|
-
<%= octicon "clippy", :class => 'top left' %> <span>Copy to Clipboard</span>
|
12
|
-
</div>
|
13
|
-
<pre class="Vlt-prism--dark language-<%= lexer.tag %> Vlt-prism--copy-disabled"><code><%= highlighted_import_source %></code></pre>
|
14
|
-
</div>
|
8
|
+
<pre class="Vlt-prism--dark language-<%= lexer.tag %>" data-lang="<%= lang %>" data-block="<%= config['source'] %>" data-section="configure"><code><%= highlighted_import_source %></code></pre>
|
15
9
|
|
16
10
|
<p><a data-section="configure" data-lang="<%= lang %>" data-block="<%= config['source'] %>" href="<%= client_url %>">View full source</a></p>
|
17
11
|
</div>
|
@@ -1,13 +1,7 @@
|
|
1
1
|
<h2 class="Vlt-title--margin-top3"><%= ::I18n.t('.code_snippets.write_code.write_the_code') %></h2>
|
2
2
|
<%= add_instructions %>
|
3
3
|
|
4
|
-
<
|
5
|
-
<div class="copy-button" data-lang="<%= lang %>" data-block="<%= config['source'] %>" data-section="code">
|
6
|
-
<%= octicon "clippy", :class => 'top left' %> <span><%= ::I18n.t('.code_snippets.copy_to_clipboard') %></span>
|
7
|
-
</div>
|
8
|
-
<pre class="language-<%= lexer.tag %> main-code Vlt-prism--dark Vlt-prism--copy-disabled"><code><%= highlighted_code_source %></code></pre>
|
9
|
-
|
10
|
-
</div>
|
4
|
+
<pre class="language-<%= lexer.tag %> main-code Vlt-prism--dark" data-lang="<%= lang %>" data-block="<%= config['source'] %>" data-section="code"><code><%= highlighted_code_source %></code></pre>
|
11
5
|
|
12
6
|
<p><a data-section="code" data-lang="<%= lang %>" data-block="<%= config['source'] %>" href="<%= source_url %>"><%= ::I18n.t('.code_snippets.write_code.view_full_source') %></a></p>
|
13
7
|
|
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.
|
4
|
+
version: 0.9.1
|
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-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: banzai
|
@@ -25,63 +25,63 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.1.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.10'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.10'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: redcarpet
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.4'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rouge
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.0.7
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.7
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: activemodel
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: '6.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: '6.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: actionview
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
@@ -233,6 +233,7 @@ files:
|
|
233
233
|
- config/dynamic_content.yml
|
234
234
|
- config/locales/en.yml
|
235
235
|
- lib/nexmo_markdown_renderer.rb
|
236
|
+
- lib/nexmo_markdown_renderer/cli.rb
|
236
237
|
- lib/nexmo_markdown_renderer/config/load_config.rb
|
237
238
|
- lib/nexmo_markdown_renderer/core_ext/string.rb
|
238
239
|
- lib/nexmo_markdown_renderer/filters/anchor_filter.rb
|
@@ -274,7 +275,6 @@ files:
|
|
274
275
|
- lib/nexmo_markdown_renderer/filters/partial_filter.rb
|
275
276
|
- lib/nexmo_markdown_renderer/filters/php_inliner_filter.rb
|
276
277
|
- lib/nexmo_markdown_renderer/filters/relative_link_filter.rb
|
277
|
-
- lib/nexmo_markdown_renderer/filters/screenshot_filter.rb
|
278
278
|
- lib/nexmo_markdown_renderer/filters/snippet_variables_filter.rb
|
279
279
|
- lib/nexmo_markdown_renderer/filters/tab_filter.rb
|
280
280
|
- lib/nexmo_markdown_renderer/filters/techio_filter.rb
|
@@ -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,22 +0,0 @@
|
|
1
|
-
module Nexmo
|
2
|
-
module Markdown
|
3
|
-
class ScreenshotFilter < Banzai::Filter
|
4
|
-
def call(input)
|
5
|
-
input.gsub(/```screenshot(.+?)```/m) do |_s|
|
6
|
-
config = YAML.safe_load($1)
|
7
|
-
if config['image'] && File.file?("#{Nexmo::Markdown::Config.docs_base_path}/#{config['image']}")
|
8
|
-
"![Screenshot](#{config['image'].gsub('public', '')})"
|
9
|
-
else
|
10
|
-
<<~HEREDOC
|
11
|
-
## Missing image
|
12
|
-
To fix this run:
|
13
|
-
```
|
14
|
-
$ rake screenshots:update
|
15
|
-
```
|
16
|
-
HEREDOC
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
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
|