markdown_exec 3.0.2 → 3.0.4
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/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/docs/dev/block-type-ux-allowed.md +1 -1
- data/lib/hash_delegator.rb +26 -18
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/mdoc.rb +43 -22
- data/lib/ww.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '05862fe57c684d4f2fd510c9bea4b54b9d035837d5865c32810c2c8ad08b76b2'
|
4
|
+
data.tar.gz: 6e9b150d5938c2a297dd34fb45420f1f6fb339c22ce3af59beb65b4b3558b72e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '020862e33c9713980663eb7840d2a5d3369c0c6cc7a40422fa87313c8206cf1ab287dc26c7f266d8ea25929ea4eabb4e08e5ac37cfcda112b7c8e768a9a73199'
|
7
|
+
data.tar.gz: 3bd45e67c4976d0391bb133650f524db7c6c0bd0550103f4346ffb8ebe9ef7d6aedfd4d78b80cae356772fd699ad55d5d4b6b1ce5b2a2b11762e9a5e0e47d2f1
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ name: SPECIES
|
|
8
8
|
/ automatic block loads first line in output of exec
|
9
9
|
```ux :[document_ux_GENUS]
|
10
10
|
allowed: :exec
|
11
|
-
exec:
|
11
|
+
exec: printf "Pongo\nHistiophryne psychedelica"
|
12
12
|
name: GENUS
|
13
13
|
```
|
14
14
|
/ executed block presents a menu of the allowed list
|
data/lib/hash_delegator.rb
CHANGED
@@ -1377,11 +1377,13 @@ module MarkdownExec
|
|
1377
1377
|
end
|
1378
1378
|
|
1379
1379
|
if allow_execution
|
1380
|
-
execute_required_lines(
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1380
|
+
execute_required_lines(
|
1381
|
+
blockname: selected.pub_name,
|
1382
|
+
erls: { play_bin: play_bin,
|
1383
|
+
shell: selected_shell(selected.shell) },
|
1384
|
+
required_lines: required_lines,
|
1385
|
+
shell: selected_shell(selected.shell)
|
1386
|
+
)
|
1385
1387
|
end
|
1386
1388
|
|
1387
1389
|
link_state.block_name = nil
|
@@ -1694,6 +1696,10 @@ module MarkdownExec
|
|
1694
1696
|
@prior_execution_block = nil
|
1695
1697
|
end
|
1696
1698
|
|
1699
|
+
def selected_shell(shell_name)
|
1700
|
+
shell_name.empty? ? shell : shell_name
|
1701
|
+
end
|
1702
|
+
|
1697
1703
|
# Determines the state of a selected block in the menu based
|
1698
1704
|
# on the selected option.
|
1699
1705
|
# It categorizes the selected option into either EXIT, BACK,
|
@@ -2490,7 +2496,7 @@ module MarkdownExec
|
|
2490
2496
|
if @delegate_object[:save_executed_script]
|
2491
2497
|
write_command_file(blockname: blockname,
|
2492
2498
|
required_lines: required_lines,
|
2493
|
-
shell: shell)
|
2499
|
+
shell: selected_shell(shell))
|
2494
2500
|
end
|
2495
2501
|
if @dml_block_state
|
2496
2502
|
calc_logged_stdout_filename(block_name: @dml_block_state.block.oname)
|
@@ -2498,7 +2504,7 @@ module MarkdownExec
|
|
2498
2504
|
format_and_execute_command(
|
2499
2505
|
code_lines: required_lines,
|
2500
2506
|
erls: erls,
|
2501
|
-
shell: shell
|
2507
|
+
shell: selected_shell(shell)
|
2502
2508
|
)
|
2503
2509
|
post_execution_process
|
2504
2510
|
end
|
@@ -2705,7 +2711,7 @@ module MarkdownExec
|
|
2705
2711
|
formatted_command,
|
2706
2712
|
args: @pass_args,
|
2707
2713
|
erls: erls,
|
2708
|
-
shell: shell
|
2714
|
+
shell: selected_shell(shell)
|
2709
2715
|
)
|
2710
2716
|
@fout.fout fetch_color(data_sym: :script_execution_tail,
|
2711
2717
|
color_sym: :script_execution_frame_color)
|
@@ -2968,8 +2974,8 @@ module MarkdownExec
|
|
2968
2974
|
else
|
2969
2975
|
iter_blocks_from_nested_files do |btype, fcb|
|
2970
2976
|
case btype
|
2971
|
-
when :blocks
|
2972
|
-
when :filter
|
2977
|
+
when :blocks then yield fcb
|
2978
|
+
when :filter then %i[blocks]
|
2973
2979
|
end
|
2974
2980
|
end
|
2975
2981
|
end
|
@@ -3138,7 +3144,10 @@ module MarkdownExec
|
|
3138
3144
|
opts_block_name)
|
3139
3145
|
return if selected_blocks.empty?
|
3140
3146
|
|
3141
|
-
dependency_map =
|
3147
|
+
dependency_map = selected_blocks.to_h do |block|
|
3148
|
+
[block.id, block.reqs]
|
3149
|
+
end
|
3150
|
+
|
3142
3151
|
selected_blocks.each do |block|
|
3143
3152
|
mdoc.collect_dependencies(memo: dependency_map, block: block)
|
3144
3153
|
end
|
@@ -3573,7 +3582,7 @@ module MarkdownExec
|
|
3573
3582
|
bash_script_lines
|
3574
3583
|
)
|
3575
3584
|
)
|
3576
|
-
temp_file.close
|
3585
|
+
temp_file.close # Close the file before chmod and execution
|
3577
3586
|
File.chmod(0o755, temp_file.path)
|
3578
3587
|
|
3579
3588
|
if @delegate_object[:archive_ad_hoc_scripts]
|
@@ -3584,8 +3593,7 @@ module MarkdownExec
|
|
3584
3593
|
`cp #{temp_file.path} #{archive_filename}`
|
3585
3594
|
end
|
3586
3595
|
|
3587
|
-
output =
|
3588
|
-
#### use shell per configuration
|
3596
|
+
output = `#{shell} #{temp_file.path}`
|
3589
3597
|
|
3590
3598
|
CommandResult.new(stdout: output, exit_status: $?.exitstatus)
|
3591
3599
|
end
|
@@ -3865,7 +3873,7 @@ module MarkdownExec
|
|
3865
3873
|
elsif sel == MenuOptions::SAVE_SCRIPT
|
3866
3874
|
save_to_file(
|
3867
3875
|
required_lines: required_lines, selected: selected,
|
3868
|
-
shell: selected.shell
|
3876
|
+
shell: selected_shell(selected.shell)
|
3869
3877
|
)
|
3870
3878
|
end
|
3871
3879
|
|
@@ -4201,7 +4209,7 @@ module MarkdownExec
|
|
4201
4209
|
required_lines:, selected:, shell:
|
4202
4210
|
)
|
4203
4211
|
write_command_file(
|
4204
|
-
required_lines: required_lines, blockname: selected.pub_name, shell: shell
|
4212
|
+
required_lines: required_lines, blockname: selected.pub_name, shell: selected_shell(shell)
|
4205
4213
|
)
|
4206
4214
|
@fout.fout "File saved: #{@run_state.saved_filespec}"
|
4207
4215
|
end
|
@@ -4212,7 +4220,7 @@ module MarkdownExec
|
|
4212
4220
|
saved_asset_format:
|
4213
4221
|
shell_escape_asset_format(
|
4214
4222
|
code_lines: link_state&.inherited_lines,
|
4215
|
-
shell: shell
|
4223
|
+
shell: selected_shell(shell)
|
4216
4224
|
)
|
4217
4225
|
).generate_name
|
4218
4226
|
end
|
@@ -4604,7 +4612,7 @@ module MarkdownExec
|
|
4604
4612
|
new_lines = []
|
4605
4613
|
command_result = nil
|
4606
4614
|
|
4607
|
-
case
|
4615
|
+
case FCB.act_source(export)
|
4608
4616
|
when false, UxActSource::FALSE
|
4609
4617
|
raise 'Should not be reached.'
|
4610
4618
|
|
data/lib/mdoc.rb
CHANGED
@@ -121,7 +121,7 @@ module MarkdownExec
|
|
121
121
|
|
122
122
|
nickname = name_block.pub_name
|
123
123
|
|
124
|
-
dependencies = collect_dependencies(
|
124
|
+
dependencies = collect_dependencies(pubname: nickname)
|
125
125
|
# !!t dependencies.count
|
126
126
|
all_dependency_names =
|
127
127
|
collect_unique_names(dependencies).push(nickname).uniq
|
@@ -372,6 +372,18 @@ module MarkdownExec
|
|
372
372
|
end.fetch(0, default)
|
373
373
|
end
|
374
374
|
|
375
|
+
# Retrieves code blocks by a name.
|
376
|
+
#
|
377
|
+
# @param name [String] The name of the code block to retrieve.
|
378
|
+
# @param default [Hash] The default value to return if the code block is not found.
|
379
|
+
# @return [Hash] The code block as a hash or the default value if not found.
|
380
|
+
#
|
381
|
+
def get_blocks_by_anyname(name)
|
382
|
+
table_not_split.select do |fcb|
|
383
|
+
fcb.is_named?(name)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
375
387
|
# Checks if a code block should be hidden based on the given options.
|
376
388
|
#
|
377
389
|
# @param opts [Hash] The options used for hiding code blocks.
|
@@ -426,13 +438,12 @@ module MarkdownExec
|
|
426
438
|
return memo unless source
|
427
439
|
return memo if memo.keys.include? source
|
428
440
|
|
429
|
-
|
430
|
-
|
431
|
-
if block.nil?
|
441
|
+
blocks = get_blocks_by_anyname(source)
|
442
|
+
if blocks.empty?
|
432
443
|
raise "Named code block `#{source}` not found. (@#{__LINE__})"
|
433
444
|
end
|
434
445
|
|
435
|
-
memo[source] =
|
446
|
+
memo[source] = blocks.map(&:reqs).flatten(1)
|
436
447
|
return memo unless memo[source]&.count&.positive?
|
437
448
|
|
438
449
|
memo[source].each do |req|
|
@@ -447,21 +458,31 @@ module MarkdownExec
|
|
447
458
|
# @param source [String] The name of the initial source block.
|
448
459
|
# @param memo [Hash] A memoization hash to store resolved dependencies.
|
449
460
|
# @return [Hash] A hash mapping sources to their respective dependencies.
|
450
|
-
def collect_dependencies(block: nil, memo: {},
|
461
|
+
def collect_dependencies(block: nil, memo: {}, pubname: nil)
|
451
462
|
if block.nil?
|
452
|
-
return memo unless
|
463
|
+
return memo unless pubname
|
453
464
|
|
454
|
-
|
455
|
-
if
|
456
|
-
raise "Named code block `#{
|
465
|
+
blocks = get_blocks_by_anyname(pubname)
|
466
|
+
if blocks.empty?
|
467
|
+
raise "Named code block `#{pubname}` not found. (@#{__LINE__})"
|
457
468
|
end
|
469
|
+
else
|
470
|
+
blocks = [block]
|
458
471
|
end
|
459
|
-
|
472
|
+
blocks.each do |block|
|
473
|
+
memo[block.id] = []
|
474
|
+
end
|
475
|
+
return memo unless blocks.count.positive?
|
476
|
+
|
477
|
+
required_blocks = blocks.map(&:reqs).flatten(1)
|
478
|
+
return memo unless required_blocks.count.positive?
|
460
479
|
|
461
|
-
|
480
|
+
blocks.each do |block|
|
481
|
+
memo[block.id] = required_blocks
|
482
|
+
end
|
462
483
|
|
463
|
-
|
464
|
-
collect_dependencies(
|
484
|
+
required_blocks.each do |req|
|
485
|
+
collect_dependencies(pubname: req, memo: memo)
|
465
486
|
end
|
466
487
|
|
467
488
|
memo
|
@@ -519,19 +540,19 @@ if $PROGRAM_NAME == __FILE__
|
|
519
540
|
### must raise error
|
520
541
|
def test_collect_dependencies_with_nonexistent_source
|
521
542
|
assert_raises(RuntimeError) do
|
522
|
-
@mdoc.collect_dependencies(
|
543
|
+
@mdoc.collect_dependencies(pubname: 'nonexistent')
|
523
544
|
end
|
524
545
|
end if false
|
525
546
|
|
526
547
|
def test_collect_dependencies_with_valid_source
|
527
|
-
@mdoc.stubs(:
|
528
|
-
.with('source1').returns(OpenStruct.new(id: 'source1',
|
529
|
-
|
530
|
-
@mdoc.stubs(:
|
531
|
-
.with('source2').returns(OpenStruct.new(id: 'source2', reqs: []))
|
548
|
+
@mdoc.stubs(:get_blocks_by_anyname)
|
549
|
+
.with('source1').returns([OpenStruct.new(id: 'source1',
|
550
|
+
reqs: ['source2'])])
|
551
|
+
@mdoc.stubs(:get_blocks_by_anyname)
|
552
|
+
.with('source2').returns([OpenStruct.new(id: 'source2', reqs: [])])
|
532
553
|
|
533
554
|
expected = { 'source1' => ['source2'], 'source2' => [] }
|
534
|
-
assert_equal expected, @mdoc.collect_dependencies(
|
555
|
+
assert_equal expected, @mdoc.collect_dependencies(pubname: 'source1')
|
535
556
|
end
|
536
557
|
end
|
537
558
|
|
@@ -609,7 +630,7 @@ if $PROGRAM_NAME == __FILE__
|
|
609
630
|
result = @doc.recursively_required_hash('block3')
|
610
631
|
assert_equal ({ 'block3' => ['block1'],
|
611
632
|
'block1' => ['block2'],
|
612
|
-
'block2' => nil }),
|
633
|
+
'block2' => [nil] }),
|
613
634
|
result
|
614
635
|
|
615
636
|
result_no_reqs = @doc.recursively_required_hash(nil)
|
data/lib/ww.rb
CHANGED
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: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|