markdown_helper 2.5.2 → 2.5.3
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/markdown_helper/markdown_irb_runner.rb +31 -20
- data/lib/markdown_helper/version.rb +1 -1
- data/markdown_helper.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d2db5445cf4ffb89620cb25b2398039a51e220998daf5faee18460f28cba80b
|
4
|
+
data.tar.gz: f29c591a7476c98a129848adfb8ee8c5d6279bf562353632d37a43386da99f77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b52f9a2024ead671a40bf521ba8a6be0b436477bcbbb599c588e45c29932cca9dacea2a9d232ad2c111240999913aa5eb04828d95b71465ac9138b8e67eab9
|
7
|
+
data.tar.gz: ca38ee5472ed9b6425bd8ccd87c49a45623b6de0dcb1661bfffeb2ef14dd4e41c6b22349bcee4432af66d961e0695fef8217b3d49fffe3ff43db2b8247eaa5b1
|
data/Gemfile.lock
CHANGED
@@ -2,10 +2,13 @@ require 'tmpdir'
|
|
2
2
|
|
3
3
|
class MarkdownIrbRunner < MarkdownHelper
|
4
4
|
|
5
|
-
|
6
|
-
BeginTextDirective = "=begin #{IrbFilterPragma}"
|
7
|
-
EndTextDirective = "=end #{IrbFilterPragma}"
|
5
|
+
CommentPrefix = '#run_irb '
|
8
6
|
|
7
|
+
##
|
8
|
+
# Run Ruby Interactive Shell (irb) for each embedded snippet
|
9
|
+
# that begins with '```#run_irb' and end with '```'.
|
10
|
+
# The irb output replaces the entire sequence,
|
11
|
+
# and is preceded by '```ruby' and followed by '```'.
|
9
12
|
def run_irb(template_file_path, markdown_file_path)
|
10
13
|
irb_input = make_irb_input(template_file_path)
|
11
14
|
irb_output = make_irb_output(irb_input)
|
@@ -13,50 +16,58 @@ class MarkdownIrbRunner < MarkdownHelper
|
|
13
16
|
File.write(markdown_file_path, markdown)
|
14
17
|
end
|
15
18
|
|
19
|
+
##
|
20
|
+
# Comment out all lines except the irb snippets.
|
16
21
|
def make_irb_input(template_file_path)
|
17
22
|
irb_lines = []
|
18
|
-
|
23
|
+
in_irb_block = false
|
19
24
|
source_lines = File.readlines(template_file_path)
|
20
25
|
source_lines.each do |source_line|
|
21
26
|
source_line.chomp!
|
22
|
-
if source_line ==
|
23
|
-
|
27
|
+
if source_line == '```#run_irb'
|
28
|
+
# Begin irb snippet; put commented-out markdown pragma.
|
29
|
+
in_irb_block = true
|
30
|
+
irb_lines.push(CommentPrefix + '```ruby')
|
24
31
|
elsif source_line == '```'
|
25
|
-
|
32
|
+
# End irb snippet; put commented-out markdown pragma.
|
33
|
+
in_irb_block = false
|
34
|
+
irb_lines.push(CommentPrefix + '```')
|
26
35
|
else
|
27
|
-
|
36
|
+
if in_irb_block
|
37
|
+
irb_lines.push(source_line)
|
38
|
+
else
|
39
|
+
irb_lines.push(CommentPrefix + source_line)
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
30
|
-
irb_lines.push(EndTextDirective)
|
31
43
|
irb_lines.push('') unless irb_lines.last.empty?
|
32
44
|
irb_lines.join("\n")
|
33
45
|
end
|
34
46
|
|
47
|
+
##
|
48
|
+
# Run irb over the prepared file.
|
35
49
|
def make_irb_output(irb_input)
|
36
50
|
Dir.mktmpdir do |dir|
|
37
51
|
Dir.chdir(dir) do
|
38
52
|
File.write('irb_input', irb_input)
|
39
|
-
command = 'irb --noecho --noprompt irb_input
|
40
|
-
system(command
|
53
|
+
command = 'irb --noecho --noprompt irb_input > irb_output'
|
54
|
+
system(command)
|
41
55
|
File.read('irb_output')
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|
45
59
|
|
60
|
+
##
|
61
|
+
# Uncomment the text.
|
46
62
|
def make_markdown(irb_output)
|
47
63
|
output_lines = []
|
48
64
|
irb_lines = irb_output.split("\n")
|
49
65
|
irb_lines.each_with_index do |irb_line, i|
|
50
66
|
irb_line.chomp!
|
51
|
-
if irb_line ==
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
if irb_line == EndTextDirective
|
56
|
-
output_lines.push('```ruby') unless i == irb_lines.size - 1
|
57
|
-
next
|
58
|
-
end
|
59
|
-
output_lines.push(irb_line)
|
67
|
+
next if (i == 0) && (irb_line == 'Switch to inspect mode.')
|
68
|
+
|
69
|
+
output_line = irb_line.sub(CommentPrefix, '')
|
70
|
+
output_lines.push(output_line)
|
60
71
|
end
|
61
72
|
output_lines.push('') unless output_lines.last.nil? || output_lines.last.empty?
|
62
73
|
output_lines.join("\n")
|
data/markdown_helper.gemspec
CHANGED
@@ -36,7 +36,7 @@ EOT
|
|
36
36
|
spec.require_paths = ['lib']
|
37
37
|
|
38
38
|
spec.add_development_dependency 'bundler', '~> 1.14'
|
39
|
-
spec.add_development_dependency 'rake', '~>
|
39
|
+
spec.add_development_dependency 'rake', '~> 12.3.2'
|
40
40
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
41
41
|
spec.add_development_dependency 'diff-lcs', '~> 1.3'
|
42
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdown_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- burdettelamar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.2
|
34
34
|
type: :development
|
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: 12.3.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
212
|
- !ruby/object:Gem::Version
|
213
213
|
version: '0'
|
214
214
|
requirements: []
|
215
|
-
rubygems_version: 3.
|
215
|
+
rubygems_version: 3.1.2
|
216
216
|
signing_key:
|
217
217
|
specification_version: 4
|
218
218
|
summary: Class to help with GitHub markdown.
|