markdown_exec 0.0.6 → 0.1.2
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 +7 -1
- data/README.md +18 -39
- data/Rakefile +6 -7
- data/bin/mde +2 -4
- data/lib/markdown_exec/version.rb +4 -1
- data/lib/markdown_exec.rb +138 -155
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9bea3a54afa348fb845a58f5878a0ffaa7c1054c3ddcb3444d67a8ab82f3f33
|
4
|
+
data.tar.gz: 3c305eb76fc06e013f38978144d668d864a67903d2be9a9de8eaa1e0f221c448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba10e7a6a74ad1d13c08c3f19ec7ccde273df98a15194022fd803088bfa5c11a880a1f2b094b9b9e9f8979a998b480afd133252bf7b5e960bd2a7f856f26c2f
|
7
|
+
data.tar.gz: 3e031e16cf98a6301677d05caf09da89c227a32139c62f2844567e73acb5404171aa204a0bbf823844afab4e29a54894161f12a585d57e5223e304e587f96e2b
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
markdown_exec (0.
|
4
|
+
markdown_exec (0.1.1)
|
5
|
+
open3 (~> 0.1.1)
|
6
|
+
optparse (~> 0.1.1)
|
5
7
|
tty-prompt (~> 0.23.1)
|
8
|
+
yaml (~> 0.2.0)
|
6
9
|
|
7
10
|
GEM
|
8
11
|
remote: https://rubygems.org/
|
9
12
|
specs:
|
10
13
|
ast (2.4.2)
|
11
14
|
minitest (5.15.0)
|
15
|
+
open3 (0.1.1)
|
16
|
+
optparse (0.1.1)
|
12
17
|
parallel (1.21.0)
|
13
18
|
parser (3.1.1.0)
|
14
19
|
ast (~> 2.4.1)
|
@@ -42,6 +47,7 @@ GEM
|
|
42
47
|
tty-screen (0.8.1)
|
43
48
|
unicode-display_width (2.1.0)
|
44
49
|
wisper (2.0.1)
|
50
|
+
yaml (0.2.0)
|
45
51
|
|
46
52
|
PLATFORMS
|
47
53
|
arm64-darwin-21
|
data/README.md
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
# MarkdownExec
|
2
2
|
|
3
|
-
|
3
|
+
This gem allows you to run code blocks in markdown files.
|
4
4
|
|
5
|
-
|
5
|
+
* Code blocks can be named.
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'markdown_exec'
|
13
|
-
```
|
7
|
+
* Named blocks can be required by other blocks.
|
14
8
|
|
15
|
-
|
9
|
+
* The selected code block, and all required blocks, are collected in the order they appear in the markdown file.
|
16
10
|
|
17
|
-
|
11
|
+
## Installation
|
18
12
|
|
19
|
-
|
13
|
+
Install:
|
20
14
|
|
21
15
|
$ gem install markdown_exec
|
22
16
|
|
23
17
|
## Usage
|
24
18
|
|
25
|
-
|
19
|
+
`mde --help`
|
20
|
+
Displays help information.
|
26
21
|
|
27
|
-
|
22
|
+
`mde`
|
23
|
+
Process `README.md` file in the current directory. Displays all the blocks in the file and allows you to select using [up], [down], and [return]. Press [ctrl]-c to abort selection.
|
28
24
|
|
29
|
-
|
25
|
+
`mde -f my.md`
|
26
|
+
Process `my.md` file in the current directory.
|
30
27
|
|
31
|
-
|
28
|
+
`mde -p child`
|
29
|
+
Process markdown files in the `child` directory.
|
32
30
|
|
33
|
-
|
31
|
+
`mde --list-blocks`
|
32
|
+
List all blocks in the selected files.
|
34
33
|
|
35
|
-
|
34
|
+
`mde --list-docs`
|
35
|
+
List all markdown documents in the selected folder.
|
36
36
|
|
37
37
|
## License
|
38
38
|
|
@@ -41,24 +41,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
41
|
## Code of Conduct
|
42
42
|
|
43
43
|
Everyone interacting in the MarkdownExec project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/markdown_exec/blob/master/CODE_OF_CONDUCT.md).
|
44
|
-
|
45
|
-
# 2022-03-06
|
46
|
-
```
|
47
|
-
gem build markdown_exec.gemspec
|
48
|
-
```
|
49
|
-
```expect
|
50
|
-
Successfully built RubyGem
|
51
|
-
Name: markdown_exec
|
52
|
-
Version: 0.0.1
|
53
|
-
File: markdown_exec-0.0.1.gem
|
54
|
-
```
|
55
|
-
```
|
56
|
-
gem install ./markdown_exec-0.0.1.gem
|
57
|
-
```
|
58
|
-
```
|
59
|
-
gem list | grep exec
|
60
|
-
```
|
61
|
-
```
|
62
|
-
gem uninstall markdown_exec
|
63
|
-
```
|
64
|
-
pusher api key: rubygems_8c4b38ef685484719858c53c3161a124c15d7a9bec6cb65a
|
data/Rakefile
CHANGED
@@ -13,27 +13,26 @@ require 'rubocop/rake_task'
|
|
13
13
|
|
14
14
|
RuboCop::RakeTask.new
|
15
15
|
|
16
|
-
|
16
|
+
require_relative 'lib/markdown_exec/version'
|
17
17
|
|
18
|
-
|
19
|
-
GEM_VERSION = '0.0.6'
|
18
|
+
task default: %i[test rubocop]
|
20
19
|
|
21
20
|
# task :default => :build
|
22
21
|
|
23
22
|
task :build do
|
24
|
-
system "gem build #{GEM_NAME}.gemspec"
|
23
|
+
system "gem build #{MarkdownExec::GEM_NAME}.gemspec"
|
25
24
|
end
|
26
25
|
|
27
26
|
task install: :build do
|
28
|
-
system "gem install #{GEM_NAME}-#{
|
27
|
+
system "gem install #{MarkdownExec::GEM_NAME}-#{MarkdownExec::VERSION}.gem"
|
29
28
|
end
|
30
29
|
|
31
30
|
task publish: :build do
|
32
|
-
system "gem push #{GEM_NAME}-#{
|
31
|
+
system "gem push #{MarkdownExec::GEM_NAME}-#{MarkdownExec::VERSION}.gem"
|
33
32
|
end
|
34
33
|
|
35
34
|
task uninstall: :build do
|
36
|
-
system "gem uninstall #{GEM_NAME}"
|
35
|
+
system "gem uninstall #{MarkdownExec::GEM_NAME}"
|
37
36
|
end
|
38
37
|
|
39
38
|
task :clean do
|
data/bin/mde
CHANGED
data/lib/markdown_exec.rb
CHANGED
@@ -1,38 +1,17 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'markdown_exec/version'
|
4
|
-
|
5
1
|
#!/usr/bin/env ruby
|
6
2
|
# frozen_string_literal: true
|
7
3
|
|
8
4
|
# encoding=utf-8
|
9
|
-
# rubocop:disable Style/GlobalVars
|
10
|
-
|
11
|
-
env_debug = ENV['MARKDOWN_EXEC_DEBUG']
|
12
|
-
$pdebug = !(env_debug || '').empty?
|
13
5
|
|
14
|
-
#
|
15
|
-
|
16
|
-
# VERSION = '0.0.6'
|
17
|
-
|
18
|
-
# require 'markdown_exec'
|
19
|
-
# # puts MarkdownExec::MarkParse.echo(ARGV[0])
|
6
|
+
# rubocop:disable Style/GlobalVars
|
7
|
+
$pdebug = !(ENV['MARKDOWN_EXEC_DEBUG'] || '').empty?
|
20
8
|
|
9
|
+
require 'open3'
|
21
10
|
require 'optparse'
|
22
|
-
require 'pathname'
|
11
|
+
# require 'pathname'
|
23
12
|
require 'tty-prompt'
|
24
13
|
require 'yaml'
|
25
|
-
|
26
|
-
# require_relative 'mdlib'
|
27
|
-
# #!/usr/bin/env ruby
|
28
|
-
# # frozen_string_literal: true
|
29
|
-
# # encoding=utf-8
|
30
|
-
|
31
|
-
# env_debug = ENV['MARKDOWN_EXEC_DEBUG']
|
32
|
-
# $pdebug = !(env_debug || '').empty?
|
33
|
-
|
34
|
-
require 'open3'
|
35
|
-
# require 'tty-prompt'
|
14
|
+
require_relative 'markdown_exec/version'
|
36
15
|
|
37
16
|
BLOCK_SIZE = 1024
|
38
17
|
SELECT_PAGE_HEIGHT = 12
|
@@ -40,12 +19,6 @@ SELECT_PAGE_HEIGHT = 12
|
|
40
19
|
module MarkdownExec
|
41
20
|
class Error < StandardError; end
|
42
21
|
|
43
|
-
# Markdown Exec
|
44
|
-
# class MarkParse
|
45
|
-
# def self.echo(str = '')
|
46
|
-
# "#{str}#{str}"
|
47
|
-
# end
|
48
|
-
# end
|
49
22
|
##
|
50
23
|
#
|
51
24
|
class MarkParse
|
@@ -183,7 +156,7 @@ module MarkdownExec
|
|
183
156
|
end
|
184
157
|
end
|
185
158
|
blocks.tap { |ret| puts "get_blocks() ret: #{ret.inspect}" if $pdebug }
|
186
|
-
end
|
159
|
+
end # get_blocks
|
187
160
|
|
188
161
|
def make_block_label(block, call_options = {})
|
189
162
|
opts = options.merge(call_options)
|
@@ -303,7 +276,7 @@ module MarkdownExec
|
|
303
276
|
end
|
304
277
|
|
305
278
|
selected[:name]
|
306
|
-
end
|
279
|
+
end # select_block
|
307
280
|
|
308
281
|
def select_md_file
|
309
282
|
opts = options
|
@@ -387,150 +360,160 @@ module MarkdownExec
|
|
387
360
|
end
|
388
361
|
all.tap { |ret| puts "unroll() ret: #{ret.inspect}" if $pdebug }
|
389
362
|
end
|
390
|
-
end
|
391
363
|
|
392
|
-
|
393
|
-
|
364
|
+
# $stderr.sync = true
|
365
|
+
# $stdout.sync = true
|
394
366
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
options
|
405
|
-
.transform_keys(&:to_sym))
|
406
|
-
# rubocop:enable Security/YAMLLoad
|
367
|
+
## configuration file
|
368
|
+
#
|
369
|
+
def read_configuration!(options, configuration_path)
|
370
|
+
if File.exist?(configuration_path)
|
371
|
+
# rubocop:disable Security/YAMLLoad
|
372
|
+
options.merge!((YAML.load(File.open(configuration_path)) || {})
|
373
|
+
.transform_keys(&:to_sym))
|
374
|
+
# rubocop:enable Security/YAMLLoad
|
375
|
+
end
|
376
|
+
options
|
407
377
|
end
|
408
|
-
options
|
409
|
-
end
|
410
378
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
379
|
+
def run
|
380
|
+
## default configuration
|
381
|
+
#
|
382
|
+
options = {
|
383
|
+
mdheadings: true,
|
384
|
+
list_blocks: false,
|
385
|
+
list_docs: false,
|
386
|
+
mdfilename: 'README.md',
|
387
|
+
mdfolder: '.'
|
388
|
+
}
|
421
389
|
|
422
|
-
|
390
|
+
def options_finalize!(options); end
|
423
391
|
|
424
|
-
|
425
|
-
#
|
426
|
-
read_configuration! options, ".#{APP_NAME.downcase}.yml"
|
392
|
+
# puts "MDE run() ARGV: #{ARGV.inspect}"
|
427
393
|
|
428
|
-
|
429
|
-
#
|
430
|
-
# load_resources! options
|
431
|
-
# puts "q31 options: #{options.to_yaml}" if $pdebug
|
432
|
-
|
433
|
-
# rubocop:disable Metrics/BlockLength
|
434
|
-
option_parser = OptionParser.new do |opts|
|
435
|
-
executable_name = File.basename($PROGRAM_NAME)
|
436
|
-
opts.banner = [
|
437
|
-
"#{APP_NAME} - #{APP_DESC} (#{VERSION})".freeze,
|
438
|
-
"Usage: #{executable_name} [options]"
|
439
|
-
].join("\n")
|
440
|
-
|
441
|
-
## menu top: on_head appear in reverse order added
|
394
|
+
# read local configuration file
|
442
395
|
#
|
443
|
-
|
444
|
-
read_configuration! options, value
|
445
|
-
end
|
396
|
+
read_configuration! options, ".#{MarkdownExec::APP_NAME.downcase}.yml"
|
446
397
|
|
447
|
-
##
|
398
|
+
## read current details for aws resources from app_data_file
|
448
399
|
#
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
400
|
+
# load_resources! options
|
401
|
+
# puts "q31 options: #{options.to_yaml}" if $pdebug
|
402
|
+
|
403
|
+
# rubocop:disable Metrics/BlockLength
|
404
|
+
option_parser = OptionParser.new do |opts|
|
405
|
+
executable_name = File.basename($PROGRAM_NAME)
|
406
|
+
opts.banner = [
|
407
|
+
"#{MarkdownExec::APP_NAME} - #{MarkdownExec::APP_DESC} (#{MarkdownExec::VERSION})",
|
408
|
+
"Usage: #{executable_name} [options]"
|
409
|
+
].join("\n")
|
410
|
+
|
411
|
+
## menu top: on_head appear in reverse order added
|
412
|
+
#
|
413
|
+
opts.on('--config PATH', 'Read configuration file') do |value|
|
414
|
+
read_configuration! options, value
|
415
|
+
end
|
456
416
|
|
457
|
-
|
458
|
-
|
459
|
-
|
417
|
+
## menu body: items appear in order added
|
418
|
+
#
|
419
|
+
opts.on('-f RELATIVE', '--mdfilename', 'Name of document') do |value|
|
420
|
+
options[:mdfilename] = value
|
421
|
+
end
|
460
422
|
|
461
|
-
|
462
|
-
|
463
|
-
|
423
|
+
opts.on('-p PATH', '--mdfolder', 'Path to documents') do |value|
|
424
|
+
options[:mdfolder] = value
|
425
|
+
end
|
464
426
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
puts option_parser.help
|
469
|
-
exit
|
470
|
-
end
|
427
|
+
opts.on('--list-blocks', 'List blocks') do |_value|
|
428
|
+
options[:list_blocks] = true
|
429
|
+
end
|
471
430
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
end
|
431
|
+
opts.on('--list-docs', 'List docs in current folder') do |_value|
|
432
|
+
options[:list_docs] = true
|
433
|
+
end
|
476
434
|
|
477
|
-
|
478
|
-
|
479
|
-
|
435
|
+
## menu bottom: items appear in order added
|
436
|
+
#
|
437
|
+
opts.on_tail('-h', '--help', 'App help') do |_value|
|
438
|
+
puts option_parser.help
|
439
|
+
exit
|
440
|
+
end
|
480
441
|
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
end
|
486
|
-
# rubocop:enable Metrics/BlockLength
|
442
|
+
opts.on_tail('-v', '--version', 'App version') do |_value|
|
443
|
+
puts MarkdownExec::VERSION
|
444
|
+
exit
|
445
|
+
end
|
487
446
|
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
options_finalize! options
|
447
|
+
opts.on_tail('-x', '--exit', 'Exit app') do |_value|
|
448
|
+
exit
|
449
|
+
end
|
492
450
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
{
|
500
|
-
approve: true,
|
501
|
-
bash: true,
|
502
|
-
display: true,
|
503
|
-
exclude_expect_blocks: true,
|
504
|
-
execute: true,
|
505
|
-
prompt: 'Execute',
|
506
|
-
struct: true
|
507
|
-
}
|
508
|
-
)
|
509
|
-
|
510
|
-
## show
|
511
|
-
#
|
512
|
-
if options[:list_docs]
|
513
|
-
fout mp.find_files
|
514
|
-
break
|
515
|
-
end
|
451
|
+
opts.on_tail('-0', 'Show configuration') do |_v|
|
452
|
+
options_finalize! options
|
453
|
+
puts options.to_yaml
|
454
|
+
end
|
455
|
+
end # OptionParser
|
456
|
+
# rubocop:enable Metrics/BlockLength
|
516
457
|
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
break
|
522
|
-
end
|
458
|
+
option_parser.load # filename defaults to basename of the program without suffix in a directory ~/.options
|
459
|
+
option_parser.environment # env defaults to the basename of the program.
|
460
|
+
option_parser.parse! # (into: options)
|
461
|
+
options_finalize! options
|
523
462
|
|
524
463
|
## process
|
525
464
|
#
|
526
|
-
|
465
|
+
# rubocop:disable Metrics/BlockLength
|
466
|
+
loop do # once
|
467
|
+
mp = MarkParse.new options
|
468
|
+
options.merge!(
|
469
|
+
{
|
470
|
+
approve: true,
|
471
|
+
bash: true,
|
472
|
+
display: true,
|
473
|
+
exclude_expect_blocks: true,
|
474
|
+
execute: true,
|
475
|
+
prompt: 'Execute',
|
476
|
+
struct: true
|
477
|
+
}
|
478
|
+
)
|
479
|
+
|
480
|
+
## show
|
481
|
+
#
|
482
|
+
if options[:list_docs]
|
483
|
+
fout mp.find_files
|
484
|
+
break
|
485
|
+
end
|
527
486
|
|
528
|
-
|
529
|
-
|
487
|
+
if options[:list_blocks]
|
488
|
+
fout (mp.find_files.map do |file|
|
489
|
+
mp.make_block_labels(mdfilename: file, struct: true)
|
490
|
+
end).flatten(1).to_yaml
|
491
|
+
break
|
492
|
+
end
|
493
|
+
|
494
|
+
## process
|
495
|
+
#
|
496
|
+
mp.select_block(bash: true, struct: true) if options[:mdfilename]
|
497
|
+
|
498
|
+
# rubocop:disable Style/BlockComments
|
499
|
+
=begin
|
500
|
+
# rescue ArgumentError => e
|
501
|
+
# puts "User abort: #{e}"
|
502
|
+
|
503
|
+
# rescue StandardError => e
|
504
|
+
# puts "ERROR: #{e}"
|
505
|
+
# raise StandardError, e
|
506
|
+
|
507
|
+
# ensure
|
508
|
+
# exit
|
509
|
+
=end
|
510
|
+
# rubocop:enable Style/BlockComments
|
511
|
+
|
512
|
+
break unless false # rubocop:disable Lint/LiteralAsCondition
|
513
|
+
end # loop
|
514
|
+
end # run
|
515
|
+
end # class MarkParse
|
530
516
|
|
531
|
-
break unless false # rubocop:disable Lint/LiteralAsCondition
|
532
|
-
end
|
533
|
-
end
|
534
517
|
# rubocop:enable Metrics/BlockLength
|
535
518
|
# rubocop:enable Style/GlobalVars
|
536
|
-
end
|
519
|
+
end # module MarkdownExec
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdown_exec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: open3
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.1.1
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: pathname
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: tty-prompt
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|