md-ruby-eval 0.1.2 → 0.2.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 +8 -6
- data/VERSION +1 -1
- data/bin/md-ruby-eval +7 -2
- data/lib/md_ruby_eval.rb +19 -7
- metadata +18 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 976f3b3c85f20c71f00ccdbaee4fb6ccb47c5da7
|
4
|
+
data.tar.gz: ae934cd01a7893ebc779df854bedb76d8b01ed56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d242cec222b5c3cdda8ccca28f86a8dee722c90c37130ea829892232a0c2ed1140654bf859c0d6daa9cf4f3be1122c530ae307647aeaddadd5ced88065158a7b
|
7
|
+
data.tar.gz: 4697d9a800916ab71a16e777515e97666cdfa441b86eb8b6be5e275811c990f77b30780ab6c5e4b6a517cc5cb37ce9b5186c5c4e53d7c0522c387a4f0ac30e21
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# md-ruby-eval
|
2
2
|
|
3
|
-
Usage:
|
4
|
-
|
3
|
+
Usage: md-ruby-eval [options] --auto
|
4
|
+
md-ruby-eval [options] INPUT_FILE OUTPUT_FILE
|
5
|
+
md-ruby-eval --help
|
5
6
|
|
6
7
|
Evaluates Ruby examples in MD files.
|
7
8
|
|
@@ -45,7 +46,7 @@ becomes
|
|
45
46
|
a # => 3
|
46
47
|
```
|
47
48
|
|
48
|
-
A parseable piece of code ended with '#' will be evaluated but
|
49
|
+
A parseable piece of code ended with '#' will be evaluated but its result is not
|
49
50
|
added to the output as a comment, which is useful for method and class definitions.
|
50
51
|
|
51
52
|
## Example usage of `--auto`
|
@@ -59,6 +60,7 @@ added to the output as a comment, which is useful for method and class definitio
|
|
59
60
|
c.md
|
60
61
|
|
61
62
|
- `md-ruby-eval --auto` call the tool
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
|
64
|
+
Creates files `a.out.md` and `b.out.md` evaluating each in isolated environments, before
|
65
|
+
`a.out.md` is evaluated `a.init.md` is required to setup its environment. `c.md` is ignored
|
66
|
+
since it does not have `in` marker.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/md-ruby-eval
CHANGED
@@ -5,6 +5,7 @@ require 'md_ruby_eval'
|
|
5
5
|
# this will only run if the script was the main, not load'd or require'd
|
6
6
|
to_require = []
|
7
7
|
indentation = 40
|
8
|
+
line_length = 79
|
8
9
|
auto = false
|
9
10
|
|
10
11
|
OptionParser.new do |opts|
|
@@ -22,6 +23,10 @@ OptionParser.new do |opts|
|
|
22
23
|
indentation = v
|
23
24
|
end
|
24
25
|
|
26
|
+
opts.on('-l', '--line NUMBER', Integer, 'Default maximum line length') do |v|
|
27
|
+
line_length = v
|
28
|
+
end
|
29
|
+
|
25
30
|
opts.on('--[no-]auto',
|
26
31
|
'Automatic mode. Finds `*.in.md` files outputting `*.out.md` files') do |v|
|
27
32
|
auto = true
|
@@ -39,7 +44,7 @@ if auto
|
|
39
44
|
puts "using: #{init_path}"
|
40
45
|
load init_path
|
41
46
|
end
|
42
|
-
MDRubyEval.new input_path, input_path.gsub(/(\.in)?\.md$/, '.out.md'), binding, indentation
|
47
|
+
MDRubyEval.new input_path, input_path.gsub(/(\.in)?\.md$/, '.out.md'), binding, indentation, line_length
|
43
48
|
end
|
44
49
|
|
45
50
|
Process.wait pid
|
@@ -47,6 +52,6 @@ if auto
|
|
47
52
|
else
|
48
53
|
input_path, output_path = ARGV.map { |p| File.expand_path p }
|
49
54
|
raise 'no input path' unless input_path && File.exist?(input_path)
|
50
|
-
MDRubyEval.new input_path, output_path, binding, indentation
|
55
|
+
MDRubyEval.new input_path, output_path, binding, indentation, line_length
|
51
56
|
end
|
52
57
|
|
data/lib/md_ruby_eval.rb
CHANGED
@@ -4,12 +4,16 @@ require 'optparse'
|
|
4
4
|
|
5
5
|
class MDRubyEval
|
6
6
|
|
7
|
-
def initialize(input_path, output_path, environment, indentation)
|
7
|
+
def initialize(input_path, output_path, environment, indentation, line_length)
|
8
8
|
@input_path = input_path
|
9
9
|
@output_path = output_path
|
10
10
|
@environment = environment
|
11
11
|
@output = ''
|
12
12
|
@indentation = indentation
|
13
|
+
@line_length = line_length
|
14
|
+
|
15
|
+
@last_id = 1
|
16
|
+
@known_ids = Hash.new { |h, k| h[k] = format('%016x', @last_id += 1) }
|
13
17
|
|
14
18
|
process_file input_path
|
15
19
|
end
|
@@ -39,7 +43,7 @@ class MDRubyEval
|
|
39
43
|
chunk_lines.each do |chunk, lines|
|
40
44
|
result = evaluate(chunk, line_count)
|
41
45
|
if chunk.strip.empty? || chunk.include?('#')
|
42
|
-
output << (chunk.end_with?("#\n") ? chunk[0..-3]+"\n" : chunk)
|
46
|
+
output << (chunk.end_with?("#\n") ? chunk[0..-3] + "\n" : chunk)
|
43
47
|
else
|
44
48
|
pre_lines = chunk.lines.to_a
|
45
49
|
last_line = pre_lines.pop
|
@@ -48,10 +52,13 @@ class MDRubyEval
|
|
48
52
|
if last_line =~ /\#$/
|
49
53
|
output << last_line.gsub(/\#$/, '')
|
50
54
|
else
|
51
|
-
|
52
|
-
|
55
|
+
inspected_result = stabilize_object_ids result.inspect
|
56
|
+
if last_line.size < @indentation && inspected_result.size < @indentation
|
57
|
+
output << "%-#{@indentation}s %s" % [last_line.chomp, "# => #{inspected_result}\n"]
|
53
58
|
else
|
54
|
-
|
59
|
+
PP.pp result, (buf = ''), @line_length
|
60
|
+
buf = stabilize_object_ids buf
|
61
|
+
inspect_lines = buf.lines
|
55
62
|
output << last_line << "# => #{inspect_lines[0]}" << inspect_lines[1..-1].map { |l| format '# %s', l }.join
|
56
63
|
end
|
57
64
|
end
|
@@ -61,11 +68,16 @@ class MDRubyEval
|
|
61
68
|
output
|
62
69
|
end
|
63
70
|
|
71
|
+
|
72
|
+
def stabilize_object_ids(output)
|
73
|
+
output.gsub(/(#<[\w:_]+0x)([0-9a-f]{16})/) { $1 + @known_ids[$2] }
|
74
|
+
end
|
75
|
+
|
64
76
|
def process_file(input_path)
|
65
77
|
puts "evaluating: #{input_path}"
|
66
78
|
|
67
|
-
input
|
68
|
-
parts
|
79
|
+
input = File.read(input_path)
|
80
|
+
parts = input.split(/^(```\w*\n)/)
|
69
81
|
|
70
82
|
# pp parts.map(&:lines)
|
71
83
|
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.2.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:
|
12
|
-
dependencies:
|
11
|
+
date: 2018-08-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.11'
|
13
27
|
description:
|
14
28
|
email: git+md-ruby-eval@pitr.ch
|
15
29
|
executables:
|
@@ -45,9 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
59
|
version: '0'
|
46
60
|
requirements: []
|
47
61
|
rubyforge_project:
|
48
|
-
rubygems_version: 2.
|
62
|
+
rubygems_version: 2.6.14
|
49
63
|
signing_key:
|
50
64
|
specification_version: 4
|
51
65
|
summary: Evaluator of Ruby examples in Markdown files.
|
52
66
|
test_files: []
|
53
|
-
has_rdoc:
|