markdown_exec 1.3.8 → 1.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/.pryrc +11 -0
- data/.rubocop.yml +15 -1
- data/CHANGELOG.md +41 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -1
- data/Rakefile +11 -7
- data/bin/bmde +11 -0
- data/bin/colorize_env_vars.sh +7 -0
- data/bin/tab_completion.sh +19 -19
- data/examples/duplicate_block.md +10 -0
- data/examples/import0.md +8 -0
- data/examples/import1.md +10 -0
- data/examples/include.md +12 -0
- data/examples/infile_config.md +10 -0
- data/examples/linked1.md +28 -0
- data/examples/linked2.md +29 -0
- data/examples/linked3.md +12 -0
- data/examples/opts.md +13 -0
- data/examples/pass-through.md +14 -0
- data/examples/plant.md +23 -0
- data/examples/port.md +23 -0
- data/examples/vars.md +20 -0
- data/examples/wrap.md +33 -0
- data/lib/block_types.rb +7 -0
- data/lib/cached_nested_file_reader.rb +0 -1
- data/lib/colorize.rb +61 -50
- data/lib/fcb.rb +12 -30
- data/lib/filter.rb +14 -10
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +1039 -541
- data/lib/mdoc.rb +106 -84
- data/lib/menu.src.yml +341 -267
- data/lib/menu.yml +342 -268
- data/lib/method_sorter.rb +76 -0
- data/lib/sort_yaml_gpt4.rb +32 -0
- metadata +22 -6
- data/lib/env_opts.rb +0 -242
- data/lib/markdown_block_manager.rb +0 -64
- data/lib/menu_options.rb +0 -0
- data/lib/menu_options.yml +0 -0
data/lib/colorize.rb
CHANGED
@@ -2,67 +2,78 @@
|
|
2
2
|
|
3
3
|
# encoding=utf-8
|
4
4
|
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# ├───┼───────────────────────┤
|
8
|
-
# │ │ │
|
9
|
-
# │1 │ for brighter colors │
|
10
|
-
# ├───┼───────────────────────┤
|
11
|
-
# │ │ │
|
12
|
-
# │4 │ for underlined text │
|
13
|
-
# ├───┼───────────────────────┤
|
14
|
-
# │ │ │
|
15
|
-
# │5 │ for flashing text
|
5
|
+
# Extends Ruby's native String class to include ANSI coloring functionality.
|
6
|
+
# Adds methods to apply RGB colors, named colors, and other formatting to strings.
|
16
7
|
class String
|
17
|
-
|
18
|
-
|
8
|
+
# Handles dynamic method calls to create RGB colors.
|
9
|
+
#
|
10
|
+
# @param method_name [Symbol] The name of the method being called.
|
11
|
+
# @param args [Array] The arguments passed to the method.
|
12
|
+
# @param block [Proc] An optional block.
|
13
|
+
# @return [String] The formatted string.
|
14
|
+
def method_missing(method_name, *args, &block)
|
15
|
+
case method_name.to_s
|
16
|
+
when /^fg_rgb_/
|
17
|
+
fg_rgb_color($'.gsub('_', ';'))
|
18
|
+
when /^fg_rgbh_/
|
19
|
+
hex_to_rgb($')
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
|
-
|
22
|
-
|
25
|
+
# Generates an ANSI control sequence for the string.
|
26
|
+
#
|
27
|
+
# @return [String] The string wrapped in an ANSI control sequence.
|
28
|
+
def ansi_control_sequence
|
29
|
+
"\033[#{self}\033[0m"
|
23
30
|
end
|
24
31
|
|
25
|
-
|
26
|
-
|
32
|
+
# Applies a 24-bit RGB foreground color to the string.
|
33
|
+
#
|
34
|
+
# @param rgb [String] The RGB color, expressed as a string like "1;2;3".
|
35
|
+
# @return [String] The string with the applied RGB foreground color.
|
36
|
+
def fg_rgb_color(rgb)
|
37
|
+
"38;2;#{rgb}m#{self}".ansi_control_sequence
|
27
38
|
end
|
28
39
|
|
29
|
-
|
30
|
-
|
40
|
+
# Converts hex color codes to RGB and applies them to the string.
|
41
|
+
#
|
42
|
+
# @param hex_str [String] The RGB color, expressed as a hex string like "FF00FF".
|
43
|
+
# @return [String] The string with the applied RGB foreground color.
|
44
|
+
def hex_to_rgb(hex_str)
|
45
|
+
fg_rgb_color(
|
46
|
+
hex_str.split('_').map { |hex| hex.to_i(16).to_s }.join(';')
|
47
|
+
)
|
31
48
|
end
|
32
49
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
"\033[1;32m#{self}\033[0m"
|
39
|
-
end
|
40
|
-
|
41
|
-
def yellow
|
42
|
-
"\033[33m#{self}\033[0m"
|
43
|
-
end
|
44
|
-
|
45
|
-
def byellow
|
46
|
-
"\033[1;33m#{self}\033[0m"
|
47
|
-
end
|
48
|
-
|
49
|
-
def blue
|
50
|
-
"\033[34m#{self}\033[0m"
|
51
|
-
end
|
52
|
-
|
53
|
-
def magenta
|
54
|
-
"\033[35m#{self}\033[0m"
|
50
|
+
# Provides a plain, unmodified version of the string.
|
51
|
+
#
|
52
|
+
# @return [String] The original string.
|
53
|
+
def plain
|
54
|
+
self
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
# A collection of methods for applying named colors.
|
58
|
+
#
|
59
|
+
# For example, #black applies a black foreground color to the string.
|
60
|
+
# These are provided for convenience and easy readability.
|
60
61
|
|
61
|
-
def
|
62
|
-
"
|
63
|
-
end
|
62
|
+
def black; "30m#{self}".ansi_control_sequence; end
|
63
|
+
def bred; "1;31m#{self}".ansi_control_sequence; end
|
64
|
+
def bgreen; "1;32m#{self}".ansi_control_sequence; end
|
65
|
+
def byellow; "1;33m#{self}".ansi_control_sequence; end
|
66
|
+
def magenta; "35m#{self}".ansi_control_sequence; end
|
67
|
+
def cyan; "36m#{self}".ansi_control_sequence; end
|
68
|
+
def white; "37m#{self}".ansi_control_sequence; end
|
69
|
+
def bwhite; "1;37m#{self}".ansi_control_sequence; end
|
64
70
|
|
65
|
-
|
66
|
-
|
67
|
-
end
|
71
|
+
# More named colors using RGB hex values
|
72
|
+
def blue; fg_rgbh_00_00_FF; end
|
73
|
+
def green; fg_rgbh_00_FF_00; end
|
74
|
+
def indigo; fg_rgbh_4B_00_82; end
|
75
|
+
def orange; fg_rgbh_FF_7F_00; end
|
76
|
+
def red; fg_rgbh_FF_00_00; end
|
77
|
+
def violet; fg_rgbh_94_00_D3; end
|
78
|
+
def yellow; fg_rgbh_FF_FF_00; end
|
68
79
|
end
|
data/lib/fcb.rb
CHANGED
@@ -18,7 +18,9 @@ module MarkdownExec
|
|
18
18
|
body: nil,
|
19
19
|
call: nil,
|
20
20
|
headings: [],
|
21
|
+
dname: nil,
|
21
22
|
name: nil,
|
23
|
+
oname: nil,
|
22
24
|
reqs: [],
|
23
25
|
shell: '',
|
24
26
|
title: '',
|
@@ -27,39 +29,9 @@ module MarkdownExec
|
|
27
29
|
}.merge(options)
|
28
30
|
end
|
29
31
|
|
30
|
-
def to_h
|
31
|
-
@attrs
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_yaml
|
35
|
-
@attrs.to_yaml
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# 2023-10-07 proposed but not functional with code
|
41
|
-
#
|
42
|
-
# def method_missing(method, *args, &block)
|
43
|
-
# method_name = method.to_s
|
44
|
-
|
45
|
-
# if method_name[-1] == '='
|
46
|
-
# @attrs[method_name.chop.to_sym] = args[0]
|
47
|
-
# elsif @attrs.key?(method_name.to_sym)
|
48
|
-
# @attrs[method_name.to_sym]
|
49
|
-
# else
|
50
|
-
# super
|
51
|
-
# end
|
52
|
-
# rescue StandardError => err
|
53
|
-
# warn(error = "ERROR ** FCB.method_missing(method: #{method_name}, *args: #{args.inspect}, &block)")
|
54
|
-
# warn err.inspect
|
55
|
-
# warn(caller[0..4])
|
56
|
-
# raise err # Here, we simply propagate the original error instead of wrapping it in a StandardError.
|
57
|
-
# end
|
58
|
-
|
59
32
|
# :reek:ManualDispatch
|
60
33
|
def method_missing(method, *args, &block)
|
61
34
|
method_name = method.to_s
|
62
|
-
|
63
35
|
if @attrs.respond_to?(method_name)
|
64
36
|
@attrs.send(method_name, *args, &block)
|
65
37
|
elsif method_name[-1] == '='
|
@@ -79,6 +51,14 @@ module MarkdownExec
|
|
79
51
|
def respond_to_missing?(method_name, _include_private = false)
|
80
52
|
@attrs.key?(method_name.to_sym) || super
|
81
53
|
end
|
54
|
+
|
55
|
+
def to_h
|
56
|
+
@attrs
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_yaml
|
60
|
+
@attrs.to_yaml
|
61
|
+
end
|
82
62
|
end
|
83
63
|
end
|
84
64
|
|
@@ -92,7 +72,9 @@ if $PROGRAM_NAME == __FILE__
|
|
92
72
|
body: 'Sample body',
|
93
73
|
call: 'Sample call',
|
94
74
|
headings: %w[Header1 Header2],
|
75
|
+
dname: 'Sample name',
|
95
76
|
name: 'Sample name',
|
77
|
+
oname: 'Sample name',
|
96
78
|
reqs: %w[req1 req2],
|
97
79
|
shell: 'bash',
|
98
80
|
text: 'Sample Text',
|
data/lib/filter.rb
CHANGED
@@ -35,7 +35,7 @@ module MarkdownExec
|
|
35
35
|
wrap_name: nil
|
36
36
|
}
|
37
37
|
|
38
|
-
name = fcb.
|
38
|
+
name = fcb.oname
|
39
39
|
shell = fcb.fetch(:shell, '')
|
40
40
|
|
41
41
|
apply_name_filters(options, filters, name)
|
@@ -107,7 +107,7 @@ module MarkdownExec
|
|
107
107
|
# @param fcb [Hash] The fenced code block to be evaluated.
|
108
108
|
#
|
109
109
|
def self.apply_other_filters(options, filters, fcb)
|
110
|
-
name = fcb.
|
110
|
+
name = fcb.oname
|
111
111
|
shell = fcb.fetch(:shell, '')
|
112
112
|
filters[:fcb_chrome] = fcb.fetch(:chrome, false)
|
113
113
|
|
@@ -125,7 +125,7 @@ module MarkdownExec
|
|
125
125
|
|
126
126
|
return unless options[:bash_only]
|
127
127
|
|
128
|
-
filters[:shell_default] = (shell ==
|
128
|
+
filters[:shell_default] = (shell == BLOCK_TYPE_BASH)
|
129
129
|
end
|
130
130
|
|
131
131
|
# Evaluates the filter settings to make a final decision on
|
@@ -166,13 +166,17 @@ if $PROGRAM_NAME == __FILE__
|
|
166
166
|
require 'bundler/setup'
|
167
167
|
Bundler.require(:default)
|
168
168
|
|
169
|
+
require 'fcb'
|
169
170
|
require 'minitest/autorun'
|
170
171
|
|
171
172
|
module MarkdownExec
|
172
173
|
class FilterTest < Minitest::Test
|
173
174
|
def setup
|
174
175
|
@options = {}
|
175
|
-
@fcb =
|
176
|
+
@fcb = FCB.new(
|
177
|
+
dname: nil,
|
178
|
+
oname: nil
|
179
|
+
)
|
176
180
|
end
|
177
181
|
|
178
182
|
# Tests for fcb_select? method
|
@@ -191,27 +195,27 @@ if $PROGRAM_NAME == __FILE__
|
|
191
195
|
def test_hidden_name_condition
|
192
196
|
@options[:hide_blocks_by_name] = true
|
193
197
|
@options[:block_name_hidden_match] = 'hidden'
|
194
|
-
@fcb[:
|
198
|
+
@fcb[:oname] = 'hidden_block'
|
195
199
|
refute Filter.fcb_select?(@options, @fcb)
|
196
200
|
end
|
197
201
|
|
198
202
|
def test_include_name_condition
|
199
203
|
@options[:hide_blocks_by_name] = true
|
200
204
|
@options[:block_name_indlude_match] = 'include'
|
201
|
-
@fcb[:
|
205
|
+
@fcb[:oname] = 'include_block'
|
202
206
|
assert Filter.fcb_select?(@options, @fcb)
|
203
207
|
end
|
204
208
|
|
205
209
|
def test_wrap_name_condition
|
206
210
|
@options[:hide_blocks_by_name] = true
|
207
211
|
@options[:block_name_wrapper_match] = 'wrap'
|
208
|
-
@fcb[:
|
212
|
+
@fcb[:oname] = 'wrap_block'
|
209
213
|
assert Filter.fcb_select?(@options, @fcb)
|
210
214
|
end
|
211
215
|
|
212
216
|
def test_name_exclude_condition
|
213
217
|
@options[:block_name] = 'test'
|
214
|
-
@fcb[:
|
218
|
+
@fcb[:oname] = 'sample'
|
215
219
|
refute Filter.fcb_select?(@options, @fcb)
|
216
220
|
end
|
217
221
|
|
@@ -223,7 +227,7 @@ if $PROGRAM_NAME == __FILE__
|
|
223
227
|
|
224
228
|
def test_name_select_condition
|
225
229
|
@options[:select_by_name_regex] = 'select'
|
226
|
-
@fcb[:
|
230
|
+
@fcb[:oname] = 'select_this'
|
227
231
|
assert Filter.fcb_select?(@options, @fcb)
|
228
232
|
end
|
229
233
|
|
@@ -235,7 +239,7 @@ if $PROGRAM_NAME == __FILE__
|
|
235
239
|
|
236
240
|
def test_bash_only_condition_true
|
237
241
|
@options[:bash_only] = true
|
238
|
-
@fcb[:shell] =
|
242
|
+
@fcb[:shell] = BLOCK_TYPE_BASH
|
239
243
|
assert Filter.fcb_select?(@options, @fcb)
|
240
244
|
end
|
241
245
|
|