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.
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 => err
47
- warn("ERROR ** Filter::fcb_select?(); #{err.inspect}")
48
- raise err
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] = !!(name =~ /#{options[:select_by_name_regex]}/)
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] = !!(name =~ /#{options[:exclude_by_name_regex]}/)
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] = !!(shell =~ /#{options[:select_by_shell_regex]}/)
99
+ filters[:shell_select] =
100
+ !!(shell =~ /#{options[:select_by_shell_regex]}/)
94
101
  end
95
102
 
96
- return unless shell.present? && options[:exclude_by_shell_regex].present?
103
+ unless shell.present? && options[:exclude_by_shell_regex].present?
104
+ return
105
+ end
97
106
 
98
- filters[:shell_exclude] = !!(shell =~ /#{options[:exclude_by_shell_regex]}/)
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[:fcb_chrome] == true
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
- # blocks for menu, without missing exit and back chrome
164
- # remove hidden blocks
175
+ # check if a block is not in the menu based on multiple match patterns
165
176
  #
166
- def self.prepared_not_in_menu?(options, fcb)
167
- fcb[:shell] == BlockType::BASH &&
168
- ((options[:block_name_include_match].present? &&
169
- fcb[:oname] =~ /#{options[:block_name_include_match]}/) ||
170
- (options[:block_name_wrapper_match].present? &&
171
- fcb[:oname] =~ /#{options[:block_name_wrapper_match]}/))
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