md-ruby-eval 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/VERSION +1 -1
- data/bin/md-ruby-eval +8 -3
- data/lib/md_ruby_eval.rb +31 -29
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50a72fe6be4309793db0ef2c0a4b07d7f3f122f6b4c17fa163e4e650c1777ddc
|
4
|
+
data.tar.gz: 7b6235cb501c789122e47aea7736e355510d0e6f35bcb67d86e1289058e05887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac33b73fbbad84b03c6a40225858d5650a42a4fc062f73f592f8ea8937d79abac314ad9758aab98513567a52a5886d3fd4fc166635f79c7391caaa2f8d670d7
|
7
|
+
data.tar.gz: a2ba788a388490b98015d8a7bd789dfb1d7e4f6588bae4e5bd954aac459dc78b83dc6196a847e0cc54605cd25bee1dbe55a103ccdac6e2042c1e297ef7039273
|
data/README.md
CHANGED
@@ -56,11 +56,11 @@ added to the output as a comment, which is useful for method and class definitio
|
|
56
56
|
|
57
57
|
a.in.md
|
58
58
|
a.init.rb
|
59
|
-
b.in.
|
59
|
+
b.in.rb
|
60
60
|
c.md
|
61
61
|
|
62
62
|
- `md-ruby-eval --auto` call the tool
|
63
63
|
|
64
|
-
Creates files `a.out.md` and `b.out.
|
64
|
+
Creates files `a.out.md` and `b.out.rb` evaluating each in isolated environments, before
|
65
65
|
`a.out.md` is evaluated `a.init.md` is required to setup its environment. `c.md` is ignored
|
66
66
|
since it does not have `in` marker.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/bin/md-ruby-eval
CHANGED
@@ -46,17 +46,22 @@ end.parse!
|
|
46
46
|
|
47
47
|
Dir.chdir dir do
|
48
48
|
if auto
|
49
|
-
input_paths = Dir.glob('*.in.md')
|
49
|
+
input_paths = Dir.glob('*.in.{md,rb}')
|
50
50
|
input_paths.each do |input_path|
|
51
51
|
|
52
52
|
pid = fork do
|
53
53
|
to_require.each { |p| require p }
|
54
|
-
init_path = File.basename(input_path
|
54
|
+
init_path = File.basename(input_path).gsub(/\.in\.(md|rb)/, '.init.rb')
|
55
55
|
if File.exist? init_path
|
56
56
|
puts "using: #{init_path}"
|
57
57
|
load init_path
|
58
58
|
end
|
59
|
-
MDRubyEval.new input_path,
|
59
|
+
MDRubyEval.new input_path,
|
60
|
+
input_path.gsub(/(\.in)?\.(md|rb)$/) { ".out.#{$2}" },
|
61
|
+
binding,
|
62
|
+
indentation,
|
63
|
+
line_length,
|
64
|
+
verbose
|
60
65
|
end
|
61
66
|
|
62
67
|
Process.wait pid
|
data/lib/md_ruby_eval.rb
CHANGED
@@ -86,48 +86,50 @@ class MDRubyEval
|
|
86
86
|
puts "evaluating: #{input_path}"
|
87
87
|
|
88
88
|
input = File.read(input_path)
|
89
|
-
parts = input.split(/^(```\w*\n)/)
|
90
89
|
|
91
|
-
|
90
|
+
if File.extname(input_path) == '.rb'
|
91
|
+
@output << process_ruby(input, 1)
|
92
|
+
else
|
93
|
+
parts = input.split(/^(```\w*\n)/)
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
+
code_block = nil
|
96
|
+
line_count = 1
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
parts.each do |part|
|
99
|
+
if part =~ /^```(\w+)$/
|
100
|
+
code_block = $1
|
101
|
+
@output << part
|
102
|
+
line_count += 1
|
103
|
+
next
|
104
|
+
end
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
if part =~ /^```$/
|
107
|
+
code_block = nil
|
108
|
+
@output << part
|
109
|
+
line_count += 1
|
110
|
+
next
|
111
|
+
end
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
+
if code_block == 'ruby'
|
114
|
+
@output << process_ruby(part, line_count)
|
115
|
+
line_count += part.lines.size
|
116
|
+
next
|
117
|
+
end
|
118
|
+
|
119
|
+
@output << part
|
113
120
|
line_count += part.lines.size
|
114
|
-
next
|
115
121
|
end
|
116
122
|
|
117
|
-
@
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
if to_print.size > 0
|
123
|
-
puts "#{to_print.size} longest evaluations:"
|
124
|
-
to_print.each { |_, out| puts out }
|
123
|
+
to_print = @too_long.sort_by { |took, _| -took }[0..10]
|
124
|
+
if to_print.size > 0
|
125
|
+
puts "#{to_print.size} longest evaluations:"
|
126
|
+
to_print.each { |_, out| puts out }
|
127
|
+
end
|
125
128
|
end
|
126
129
|
|
127
130
|
puts "writing: #{@output_path}"
|
128
131
|
File.write(@output_path, @output)
|
129
132
|
rescue => ex
|
130
133
|
puts "#{ex} (#{ex.class})\n#{ex.backtrace * "\n"}"
|
131
|
-
|
132
134
|
end
|
133
135
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md-ruby-eval
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Chalupa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -58,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
|
62
|
-
rubygems_version: 2.7.6
|
61
|
+
rubygems_version: 3.0.1
|
63
62
|
signing_key:
|
64
63
|
specification_version: 4
|
65
64
|
summary: Evaluator of Ruby examples in Markdown files.
|