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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1056df9d4b2215292650e16439ab7d8455e5df82c804a93c38e419613bd301c7
4
- data.tar.gz: 7f9b54997a435172f312f88773558bcc71c687d02f2c9013271774a9ea53b1e7
3
+ metadata.gz: 50a72fe6be4309793db0ef2c0a4b07d7f3f122f6b4c17fa163e4e650c1777ddc
4
+ data.tar.gz: 7b6235cb501c789122e47aea7736e355510d0e6f35bcb67d86e1289058e05887
5
5
  SHA512:
6
- metadata.gz: fcdce3c13297d80b29945804b71b3ca3663a2c922ebf5b585cbda351a3c3d11ff0c30c2bb4b4274d0d36ec32dbfdfca78fba07896058237b2636fd1241a13e73
7
- data.tar.gz: f6a973e077e4016d385e5b90ca8bdeb3085b1685748e9a518a0afde6da8a268a9edebbc9fffcd3a93a0a6fa66ab2bc479ec0128c17671c4f8dac802d9c4d982f
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.md
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.md` evaluating each in isolated environments, before
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.4.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, '.in.md') + '.init.rb'
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, input_path.gsub(/(\.in)?\.md$/, '.out.md'), binding, indentation, line_length, verbose
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
- # pp parts.map(&:lines)
90
+ if File.extname(input_path) == '.rb'
91
+ @output << process_ruby(input, 1)
92
+ else
93
+ parts = input.split(/^(```\w*\n)/)
92
94
 
93
- code_block = nil
94
- line_count = 1
95
+ code_block = nil
96
+ line_count = 1
95
97
 
96
- parts.each do |part|
97
- if part =~ /^```(\w+)$/
98
- code_block = $1
99
- @output << part
100
- line_count += 1
101
- next
102
- end
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
- if part =~ /^```$/
105
- code_block = nil
106
- @output << part
107
- line_count += 1
108
- next
109
- end
106
+ if part =~ /^```$/
107
+ code_block = nil
108
+ @output << part
109
+ line_count += 1
110
+ next
111
+ end
110
112
 
111
- if code_block == 'ruby'
112
- @output << process_ruby(part, line_count)
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
- @output << part
118
- line_count += part.lines.size
119
- end
120
-
121
- to_print = @too_long.sort_by { |took, _| -took }[0..10]
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.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-01-03 00:00:00.000000000 Z
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
- rubyforge_project:
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.