markdown_exec 1.3.7 → 1.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +53 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +5 -1
- data/Rakefile +11 -6
- 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 +28 -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 +5 -0
- data/lib/cached_nested_file_reader.rb +0 -1
- data/lib/colorize.rb +37 -23
- data/lib/fcb.rb +12 -30
- data/lib/filter.rb +147 -71
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +523 -235
- data/lib/mdoc.rb +190 -58
- data/lib/menu.src.yml +323 -257
- data/lib/menu.yml +324 -258
- metadata +17 -6
- data/lib/env_opts.rb +0 -242
- data/lib/markdown_block_manager.rb +0 -195
- data/lib/menu_options.rb +0 -0
- data/lib/menu_options.yml +0 -0
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
@@ -6,13 +6,22 @@
|
|
6
6
|
module MarkdownExec
|
7
7
|
# Filter
|
8
8
|
#
|
9
|
-
# The Filter class provides utilities to determine the inclusion of
|
10
|
-
# based on a set of provided options. The
|
11
|
-
# various properties of an
|
9
|
+
# The Filter class provides utilities to determine the inclusion of
|
10
|
+
# fenced code blocks (FCB) based on a set of provided options. The
|
11
|
+
# primary function, `fcb_select?`, checks various properties of an
|
12
|
+
# FCB and decides whether to include or exclude it.
|
12
13
|
#
|
13
14
|
# :reek:UtilityFunction
|
14
|
-
|
15
15
|
class Filter
|
16
|
+
# Determines whether to include or exclude a fenced code block
|
17
|
+
# (FCB) based on the provided options.
|
18
|
+
#
|
19
|
+
# @param options [Hash] The options used for filtering FCBs.
|
20
|
+
# @param fcb [Hash] The fenced code block to be evaluated.
|
21
|
+
# @return [Boolean] True if the FCB should be included; false if
|
22
|
+
# it should be excluded.
|
23
|
+
# @raise [StandardError] If an error occurs during the evaluation.
|
24
|
+
#
|
16
25
|
def self.fcb_select?(options, fcb)
|
17
26
|
filters = {
|
18
27
|
name_default: true,
|
@@ -21,13 +30,15 @@ module MarkdownExec
|
|
21
30
|
shell_default: true,
|
22
31
|
shell_exclude: nil,
|
23
32
|
shell_select: nil,
|
24
|
-
hidden_name: nil
|
33
|
+
hidden_name: nil,
|
34
|
+
include_name: nil,
|
35
|
+
wrap_name: nil
|
25
36
|
}
|
26
37
|
|
27
|
-
name = fcb.
|
38
|
+
name = fcb.oname
|
28
39
|
shell = fcb.fetch(:shell, '')
|
29
40
|
|
30
|
-
apply_name_filters(options, filters, name)
|
41
|
+
apply_name_filters(options, filters, name) #if shell == 'bash'
|
31
42
|
apply_shell_filters(options, filters, shell)
|
32
43
|
apply_other_filters(options, filters, fcb)
|
33
44
|
|
@@ -37,6 +48,14 @@ module MarkdownExec
|
|
37
48
|
raise err
|
38
49
|
end
|
39
50
|
|
51
|
+
# Applies name-based filters to determine whether to include or
|
52
|
+
# exclude a fenced code block (FCB)
|
53
|
+
# based on the block's name and provided options.
|
54
|
+
#
|
55
|
+
# @param options [Hash] The options used for filtering FCBs.
|
56
|
+
# @param filters [Hash] The filter settings to be updated.
|
57
|
+
# @param name [String] The name of the fenced code block.
|
58
|
+
#
|
40
59
|
def self.apply_name_filters(options, filters, name)
|
41
60
|
if name.present? && options[:block_name]
|
42
61
|
if name =~ /#{options[:block_name]}/
|
@@ -59,6 +78,14 @@ module MarkdownExec
|
|
59
78
|
filters[:name_exclude] = !!(name =~ /#{options[:exclude_by_name_regex]}/)
|
60
79
|
end
|
61
80
|
|
81
|
+
# Applies shell-based filters to determine whether to include or
|
82
|
+
# exclude a fenced code block (FCB)
|
83
|
+
# based on the block's shell type and provided options.
|
84
|
+
#
|
85
|
+
# @param options [Hash] The options used for filtering FCBs.
|
86
|
+
# @param filters [Hash] The filter settings to be updated.
|
87
|
+
# @param shell [String] The shell type of the fenced code block.
|
88
|
+
#
|
62
89
|
def self.apply_shell_filters(options, filters, shell)
|
63
90
|
filters[:shell_expect] = shell == 'expect'
|
64
91
|
|
@@ -71,34 +98,58 @@ module MarkdownExec
|
|
71
98
|
filters[:shell_exclude] = !!(shell =~ /#{options[:exclude_by_shell_regex]}/)
|
72
99
|
end
|
73
100
|
|
101
|
+
# Applies additional filters to determine whether to include or
|
102
|
+
# exclude a fenced code block (FCB)
|
103
|
+
# based on various criteria and provided options.
|
104
|
+
#
|
105
|
+
# @param options [Hash] The options used for filtering FCBs.
|
106
|
+
# @param filters [Hash] The filter settings to be updated.
|
107
|
+
# @param fcb [Hash] The fenced code block to be evaluated.
|
108
|
+
#
|
74
109
|
def self.apply_other_filters(options, filters, fcb)
|
75
|
-
name = fcb.
|
110
|
+
name = fcb.oname
|
76
111
|
shell = fcb.fetch(:shell, '')
|
77
112
|
filters[:fcb_chrome] = fcb.fetch(:chrome, false)
|
78
113
|
|
79
|
-
if name.present? && options[:hide_blocks_by_name]
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
if shell.present? && options[:hide_blocks_by_shell] &&
|
85
|
-
options[:block_shell_hidden_match].present?
|
86
|
-
!!(shell =~ /#{options[:block_shell_hidden_match]}/)
|
114
|
+
if name.present? && options[:hide_blocks_by_name]
|
115
|
+
filters[:hidden_name] =
|
116
|
+
!!(options[:block_name_hidden_match].present? &&
|
117
|
+
name =~ /#{options[:block_name_hidden_match]}/)
|
87
118
|
end
|
119
|
+
filters[:include_name] =
|
120
|
+
!!(options[:block_name_include_match].present? &&
|
121
|
+
name =~ /#{options[:block_name_include_match]}/)
|
122
|
+
filters[:wrap_name] =
|
123
|
+
!!(options[:block_name_wrapper_match].present? &&
|
124
|
+
name =~ /#{options[:block_name_wrapper_match]}/)
|
88
125
|
|
89
126
|
return unless options[:bash_only]
|
90
127
|
|
91
128
|
filters[:shell_default] = (shell == 'bash')
|
92
129
|
end
|
93
130
|
|
131
|
+
# Evaluates the filter settings to make a final decision on
|
132
|
+
# whether to include or exclude a fenced
|
133
|
+
# code block (FCB) based on the provided options.
|
134
|
+
#
|
135
|
+
# @param options [Hash] The options used for filtering FCBs.
|
136
|
+
# @param filters [Hash] The filter settings to be evaluated.
|
137
|
+
# @return [Boolean] True if the FCB should be included; false
|
138
|
+
# if it should be excluded.
|
139
|
+
#
|
94
140
|
def self.evaluate_filters(options, filters)
|
95
|
-
if options[:no_chrome] && filters[:fcb_chrome]
|
141
|
+
if options[:no_chrome] && filters[:fcb_chrome] == true
|
96
142
|
false
|
97
|
-
elsif options[:exclude_expect_blocks] && filters[:shell_expect]
|
143
|
+
elsif options[:exclude_expect_blocks] && filters[:shell_expect] == true
|
98
144
|
false
|
99
145
|
elsif filters[:hidden_name] == true
|
146
|
+
false
|
147
|
+
elsif filters[:include_name] == true
|
100
148
|
true
|
101
|
-
elsif filters[:
|
149
|
+
elsif filters[:wrap_name] == true
|
150
|
+
true
|
151
|
+
elsif filters[:name_exclude] == true || filters[:shell_exclude] == true ||
|
152
|
+
filters[:name_select] == false || filters[:shell_select] == false
|
102
153
|
false
|
103
154
|
elsif filters[:name_select] == true || filters[:shell_select] == true
|
104
155
|
true
|
@@ -112,70 +163,95 @@ module MarkdownExec
|
|
112
163
|
end
|
113
164
|
|
114
165
|
if $PROGRAM_NAME == __FILE__
|
166
|
+
require 'bundler/setup'
|
167
|
+
Bundler.require(:default)
|
168
|
+
|
169
|
+
require 'fcb'
|
115
170
|
require 'minitest/autorun'
|
116
171
|
|
117
|
-
|
118
|
-
|
172
|
+
module MarkdownExec
|
173
|
+
class FilterTest < Minitest::Test
|
174
|
+
def setup
|
175
|
+
@options = {}
|
176
|
+
@fcb = FCB.new(
|
177
|
+
dname: nil,
|
178
|
+
oname: nil
|
179
|
+
)
|
180
|
+
end
|
119
181
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
182
|
+
# Tests for fcb_select? method
|
183
|
+
def test_no_chrome_condition
|
184
|
+
@options[:no_chrome] = true
|
185
|
+
@fcb[:chrome] = true
|
186
|
+
refute Filter.fcb_select?(@options, @fcb)
|
187
|
+
end
|
126
188
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
189
|
+
def test_exclude_expect_blocks_condition
|
190
|
+
@options[:exclude_expect_blocks] = true
|
191
|
+
@fcb[:shell] = 'expect'
|
192
|
+
refute Filter.fcb_select?(@options, @fcb)
|
193
|
+
end
|
132
194
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
195
|
+
def test_hidden_name_condition
|
196
|
+
@options[:hide_blocks_by_name] = true
|
197
|
+
@options[:block_name_hidden_match] = 'hidden'
|
198
|
+
@fcb[:oname] = 'hidden_block'
|
199
|
+
refute Filter.fcb_select?(@options, @fcb)
|
200
|
+
end
|
138
201
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
202
|
+
def test_include_name_condition
|
203
|
+
@options[:hide_blocks_by_name] = true
|
204
|
+
@options[:block_name_indlude_match] = 'include'
|
205
|
+
@fcb[:oname] = 'include_block'
|
206
|
+
assert Filter.fcb_select?(@options, @fcb)
|
207
|
+
end
|
144
208
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
209
|
+
def test_wrap_name_condition
|
210
|
+
@options[:hide_blocks_by_name] = true
|
211
|
+
@options[:block_name_wrapper_match] = 'wrap'
|
212
|
+
@fcb[:oname] = 'wrap_block'
|
213
|
+
assert Filter.fcb_select?(@options, @fcb)
|
214
|
+
end
|
150
215
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
216
|
+
def test_name_exclude_condition
|
217
|
+
@options[:block_name] = 'test'
|
218
|
+
@fcb[:oname] = 'sample'
|
219
|
+
refute Filter.fcb_select?(@options, @fcb)
|
220
|
+
end
|
156
221
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
222
|
+
def test_shell_exclude_condition
|
223
|
+
@options[:exclude_by_shell_regex] = 'exclude_this'
|
224
|
+
@fcb[:shell] = 'exclude_this_shell'
|
225
|
+
refute Filter.fcb_select?(@options, @fcb)
|
226
|
+
end
|
162
227
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
228
|
+
def test_name_select_condition
|
229
|
+
@options[:select_by_name_regex] = 'select'
|
230
|
+
@fcb[:oname] = 'select_this'
|
231
|
+
assert Filter.fcb_select?(@options, @fcb)
|
232
|
+
end
|
168
233
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
234
|
+
def test_shell_select_condition
|
235
|
+
@options[:select_by_shell_regex] = 'select_this'
|
236
|
+
@fcb[:shell] = 'select_this_shell'
|
237
|
+
assert Filter.fcb_select?(@options, @fcb)
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_bash_only_condition_true
|
241
|
+
@options[:bash_only] = true
|
242
|
+
@fcb[:shell] = 'bash'
|
243
|
+
assert Filter.fcb_select?(@options, @fcb)
|
244
|
+
end
|
174
245
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
246
|
+
def test_bash_only_condition_false
|
247
|
+
@options[:bash_only] = true
|
248
|
+
@fcb[:shell] = 'zsh'
|
249
|
+
refute Filter.fcb_select?(@options, @fcb)
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_default_case
|
253
|
+
assert Filter.fcb_select?(@options, @fcb)
|
254
|
+
end
|
179
255
|
end
|
180
256
|
end
|
181
257
|
end
|