markdown_exec 1.5 → 1.7
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/.rubocop.yml +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +6 -1
- data/Rakefile +1 -0
- data/bin/tab_completion.sh +2 -2
- data/examples/import0.md +41 -5
- data/examples/import1.md +9 -8
- data/examples/linked1.md +8 -4
- data/examples/opts.md +4 -7
- data/lib/array.rb +27 -0
- data/lib/array_util.rb +21 -0
- data/lib/cached_nested_file_reader.rb +51 -31
- data/lib/constants.rb +46 -0
- data/lib/env.rb +2 -1
- data/lib/exceptions.rb +34 -0
- data/lib/fcb.rb +41 -1
- data/lib/filter.rb +32 -17
- data/lib/fout.rb +52 -0
- data/lib/hash.rb +21 -0
- data/lib/hash_delegator.rb +2709 -0
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +137 -1456
- data/lib/mdoc.rb +0 -3
- data/lib/menu.src.yml +145 -31
- data/lib/menu.yml +136 -27
- data/lib/method_sorter.rb +19 -17
- data/lib/object_present.rb +1 -1
- data/lib/option_value.rb +4 -2
- data/lib/pty1.rb +26 -0
- data/lib/regexp.rb +4 -5
- data/lib/saved_assets.rb +4 -2
- data/lib/saved_files_matcher.rb +7 -3
- data/lib/shared.rb +0 -5
- data/lib/string_util.rb +22 -0
- data/lib/tap.rb +5 -2
- metadata +11 -3
- data/lib/environment_opt_parse.rb +0 -209
data/lib/filter.rb
CHANGED
@@ -38,14 +38,18 @@ module MarkdownExec
|
|
38
38
|
name = fcb.oname
|
39
39
|
shell = fcb.fetch(:shell, '')
|
40
40
|
|
41
|
+
### filter in menu, not in source code
|
42
|
+
filters[:depth] =
|
43
|
+
fcb.fetch(:depth,
|
44
|
+
0).positive? && !options[:menu_include_imported_blocks]
|
41
45
|
apply_name_filters(options, filters, name)
|
42
46
|
apply_shell_filters(options, filters, shell)
|
43
47
|
apply_other_filters(options, filters, fcb)
|
44
48
|
|
45
49
|
evaluate_filters(options, filters)
|
46
|
-
rescue StandardError
|
47
|
-
warn("ERROR ** Filter::fcb_select?(); #{
|
48
|
-
raise
|
50
|
+
rescue StandardError
|
51
|
+
warn("ERROR ** Filter::fcb_select?(); #{$!.inspect}")
|
52
|
+
raise ArgumentError, $!
|
49
53
|
end
|
50
54
|
|
51
55
|
# Applies name-based filters to determine whether to include or
|
@@ -68,14 +72,16 @@ module MarkdownExec
|
|
68
72
|
end
|
69
73
|
|
70
74
|
if name.present? && filters[:name_select].nil? && options[:select_by_name_regex].present?
|
71
|
-
filters[:name_select] =
|
75
|
+
filters[:name_select] =
|
76
|
+
!!(name =~ /#{options[:select_by_name_regex]}/)
|
72
77
|
end
|
73
78
|
|
74
79
|
unless name.present? && filters[:name_exclude].nil? && options[:exclude_by_name_regex].present?
|
75
80
|
return
|
76
81
|
end
|
77
82
|
|
78
|
-
filters[:name_exclude] =
|
83
|
+
filters[:name_exclude] =
|
84
|
+
!!(name =~ /#{options[:exclude_by_name_regex]}/)
|
79
85
|
end
|
80
86
|
|
81
87
|
# Applies shell-based filters to determine whether to include or
|
@@ -90,12 +96,16 @@ module MarkdownExec
|
|
90
96
|
filters[:shell_expect] = shell == 'expect'
|
91
97
|
|
92
98
|
if shell.present? && options[:select_by_shell_regex].present?
|
93
|
-
filters[:shell_select] =
|
99
|
+
filters[:shell_select] =
|
100
|
+
!!(shell =~ /#{options[:select_by_shell_regex]}/)
|
94
101
|
end
|
95
102
|
|
96
|
-
|
103
|
+
unless shell.present? && options[:exclude_by_shell_regex].present?
|
104
|
+
return
|
105
|
+
end
|
97
106
|
|
98
|
-
filters[:shell_exclude] =
|
107
|
+
filters[:shell_exclude] =
|
108
|
+
!!(shell =~ /#{options[:exclude_by_shell_regex]}/)
|
99
109
|
end
|
100
110
|
|
101
111
|
# Applies additional filters to determine whether to include or
|
@@ -138,7 +148,9 @@ module MarkdownExec
|
|
138
148
|
# if it should be excluded.
|
139
149
|
#
|
140
150
|
def self.evaluate_filters(options, filters)
|
141
|
-
if filters[:
|
151
|
+
if filters[:depth] == true
|
152
|
+
false
|
153
|
+
elsif filters[:fcb_chrome] == true
|
142
154
|
!options[:no_chrome]
|
143
155
|
elsif options[:exclude_expect_blocks] && filters[:shell_expect] == true
|
144
156
|
false
|
@@ -160,15 +172,18 @@ module MarkdownExec
|
|
160
172
|
end
|
161
173
|
end
|
162
174
|
|
163
|
-
#
|
164
|
-
# remove hidden blocks
|
175
|
+
# check if a block is not in the menu based on multiple match patterns
|
165
176
|
#
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
177
|
+
# @param options [Hash] Options hash containing various settings
|
178
|
+
# @param fcb [Hash] Hash representing a file code block
|
179
|
+
# @param match_patterns [Array<String>] Array of regular expression patterns for matching
|
180
|
+
# @return [Boolean] True if the block should not be in the menu, false otherwise
|
181
|
+
def self.prepared_not_in_menu?(options, fcb, match_patterns)
|
182
|
+
return false unless fcb[:shell] == BlockType::BASH
|
183
|
+
|
184
|
+
match_patterns.any? do |pattern|
|
185
|
+
options[pattern].present? && fcb[:oname] =~ /#{options[pattern]}/
|
186
|
+
end
|
172
187
|
end
|
173
188
|
end
|
174
189
|
end
|
data/lib/fout.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# encoding=utf-8
|
5
|
+
|
6
|
+
# stdout manager
|
7
|
+
#
|
8
|
+
# module FOut
|
9
|
+
class FOut
|
10
|
+
def initialize(config)
|
11
|
+
@config = config
|
12
|
+
end
|
13
|
+
|
14
|
+
def approved_fout?(level)
|
15
|
+
level <= fetch_display_level
|
16
|
+
end
|
17
|
+
|
18
|
+
# integer value for comparison
|
19
|
+
#
|
20
|
+
def fetch_display_level
|
21
|
+
@config.fetch(:display_level, 1)
|
22
|
+
end
|
23
|
+
|
24
|
+
# integer value for comparison
|
25
|
+
#
|
26
|
+
def fetch_display_level_xbase_prefix
|
27
|
+
@config.fetch(:level_xbase_prefix, '')
|
28
|
+
end
|
29
|
+
|
30
|
+
# standard output; not for debug
|
31
|
+
#
|
32
|
+
def fout(str)
|
33
|
+
puts str
|
34
|
+
end
|
35
|
+
|
36
|
+
def fout_list(str)
|
37
|
+
puts str
|
38
|
+
end
|
39
|
+
|
40
|
+
def fout_section(name, data)
|
41
|
+
puts "# #{name}"
|
42
|
+
puts data.to_yaml
|
43
|
+
end
|
44
|
+
|
45
|
+
# display output at level or lower than filter (DISPLAY_LEVEL_DEFAULT)
|
46
|
+
#
|
47
|
+
def lout(str, level: DISPLAY_LEVEL_BASE)
|
48
|
+
return unless approved_fout?(level)
|
49
|
+
|
50
|
+
fout level == DISPLAY_LEVEL_BASE ? str : fetch_display_level_xbase_prefix + str
|
51
|
+
end
|
52
|
+
end
|
data/lib/hash.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# encoding=utf-8
|
5
|
+
|
6
|
+
# hash with keys sorted by name
|
7
|
+
# add Hash.sym_keys
|
8
|
+
#
|
9
|
+
class Hash
|
10
|
+
unless defined?(sort_by_key)
|
11
|
+
def sort_by_key
|
12
|
+
keys.sort.to_h { |key| [key, self[key]] }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
unless defined?(sym_keys)
|
17
|
+
def sym_keys
|
18
|
+
transform_keys(&:to_sym)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|