markdown_exec 1.8.6 → 1.8.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44e42ccdbdf5eed7e6ee36add8a5dcdcfe62d6cd3fb6fd531daf960c6ce7c9b7
4
- data.tar.gz: 753076d46e44f5d17698be53a0421212d8f2c804368f9737591dc92a7d5457d6
3
+ metadata.gz: 9fb4c6a799eb433c1df5b2a5b9969757bc7073bcd8ce410a341f8714dc4dd5dd
4
+ data.tar.gz: 385a8fe67c4cb460b43ae1263c7643d819fe5c236e572e3d3a6c04f26fb64666
5
5
  SHA512:
6
- metadata.gz: 84d952fcfafed40a5e3949783760aec570448de48293fdae536b5386b95d8080d2c9c41f0149861686d2fd4985a59ebea6794e7953d7b4dc1185340d790e68a2
7
- data.tar.gz: 9db0c523154e32c3094046084594564c9114fbd2519f6ff5d9a8fcc5feb0d31b76dc3ccd1d6c4e2625507b81b4f70f9b6fdf31e250d132a5fdf2fa54d3cb8c77
6
+ metadata.gz: 658083cad39ed6e9e2caf0243b9aa2d33d9c8b881ed370938cee3f062ba4d9f2fa4f940de7d1dfe2066c0afe285c562f1caefef367d18eacfa4a9d295061f0fb
7
+ data.tar.gz: 244c774edf797545ad63326caa39014b23cf3ed53622cdffcd2d37d37012be972ae3f538b619f6895c3ae72fcd80cafd0b9e9428bbd20788bb267307e5168a8d
data/.pryrc CHANGED
@@ -1,4 +1,3 @@
1
- binding.pry
2
1
  if defined?(PryByebug)
3
2
  Pry.config.pager = false
4
3
  Pry.commands.alias_command 'c', 'continue'
data/.rubocop.yml CHANGED
@@ -14,8 +14,6 @@ Layout/LineContinuationLeadingSpace:
14
14
  Enabled: false
15
15
 
16
16
  Layout/LineLength:
17
- # Max: 78
18
- # Max: 80
19
17
  Max: 96
20
18
 
21
19
  Lint/Debugger:
@@ -106,3 +104,6 @@ Style/StringLiterals:
106
104
  Style/StringLiteralsInInterpolation:
107
105
  Enabled: true
108
106
  EnforcedStyle: single_quotes
107
+
108
+ Style/UnlessElse:
109
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,20 +1,62 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.8.8] - 2024-01-15
4
+
5
+ ### Added
6
+
7
+ - Debounce/Control repeated launching of the same block via the menu.
8
+
9
+ - Option to match block nicknames.
10
+ Nicknames are used for scripting and are not displayed in the menu -- the block body is shown the menu.
11
+
12
+ - Option to execute script to launch Terminal window.
13
+ Provide batch variables to use in the execute_command_format script.
14
+ Limit iTerm window position to visible area.
15
+ Store output of executed script.
16
+ Menu to replay, review, and exit.
17
+
18
+ - Report line in document importing a missing file.
19
+
20
+ - Option to search for import files within each of the specified paths (recursion optional).
21
+
22
+ - Eval block loads (appends) local file to inherited lines.
23
+
24
+ - Eval block executes script and appends filtered output to inherited lines.
25
+ Select output using begin and end matching lines.
26
+ Transform selected output with per-line match and print specifications.
27
+
28
+ ### Changed
29
+
30
+ - Sanitize block names in formatted lines above and below inherited code.
31
+
32
+ ## [1.8.7] - 2023-12-31
33
+
34
+ ### Added
35
+
36
+ - Option for block name that presents the menu.
37
+ - Options for decorating inherited lines in the menu.
38
+ - Options for parse and display of heading levels 1, 2, and 3.
39
+
40
+ ### Changed
41
+
42
+ - Bypass chrome blocks when collecting dependencies.
43
+
3
44
  ## [1.8.6] - 2023-12-25
4
45
 
5
46
  ### Added
6
47
 
7
- - Default path for find command
48
+ - Default path for find command.
8
49
 
9
50
  ### Changed
10
51
 
11
- - Refactor command-line processing
52
+ - Refactor command-line processing.
12
53
 
13
54
  ## [1.8.5] - 2023-12-22
14
55
 
15
56
  ### Added
16
57
 
17
- - "eval" key for link block type to compute lines to append to the inherited state.
58
+ - "eval" boolean value for Link blocks to compute lines to append to the inherited state.
59
+ - "return" boolean value for Link blocks to return to the original page.
18
60
  - Options for dumping data associated with the menu or state.
19
61
  - Debug and irb gems.
20
62
 
data/Gemfile CHANGED
@@ -9,6 +9,7 @@ gemspec
9
9
  gem 'clipboard'
10
10
  gem 'debug'
11
11
  gem 'erb'
12
+ gem 'httparty' # 2024-01-01 for ChatGPI API
12
13
  gem 'irb', '>= 1.8.0'
13
14
  gem 'mocha', require: false
14
15
  gem 'minitest', require: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (1.8.6)
4
+ markdown_exec (1.8.8)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
@@ -47,6 +47,9 @@ GEM
47
47
  erb (4.0.3)
48
48
  cgi (>= 0.3.3)
49
49
  erubi (1.12.0)
50
+ httparty (0.21.0)
51
+ mini_mime (>= 1.0.0)
52
+ multi_xml (>= 0.5.2)
50
53
  i18n (1.14.1)
51
54
  concurrent-ruby (~> 1.0)
52
55
  io-console (0.7.1)
@@ -60,9 +63,11 @@ GEM
60
63
  crass (~> 1.0.2)
61
64
  nokogiri (>= 1.12.0)
62
65
  method_source (1.0.0)
66
+ mini_mime (1.1.5)
63
67
  minitest (5.20.0)
64
68
  mocha (2.1.0)
65
69
  ruby2_keywords (>= 0.0.5)
70
+ multi_xml (0.6.0)
66
71
  nokogiri (1.15.4-arm64-darwin)
67
72
  racc (~> 1.4)
68
73
  open3 (0.1.2)
@@ -182,6 +187,7 @@ DEPENDENCIES
182
187
  clipboard
183
188
  debug
184
189
  erb
190
+ httparty
185
191
  irb (>= 1.8.0)
186
192
  markdown_exec!
187
193
  minitest
data/Rakefile CHANGED
@@ -82,6 +82,7 @@ task :minitest do
82
82
  './lib/directory_searcher.rb',
83
83
  './lib/fcb.rb',
84
84
  './lib/filter.rb',
85
+ './lib/find_files.rb',
85
86
  './lib/hash_delegator.rb',
86
87
  './lib/markdown_exec.rb',
87
88
  './lib/mdoc.rb',
data/bin/bmde CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env bundle exec ruby
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # encoding=utf-8
@@ -13,7 +13,7 @@ __filedirs_all()
13
13
  }
14
14
 
15
15
  _mde_echo_version() {
16
- echo "1.8.6"
16
+ echo "1.8.8"
17
17
  }
18
18
 
19
19
  _mde() {
@@ -80,9 +80,9 @@ _mde() {
80
80
 
81
81
  --saved-stdout-folder) COMPREPLY="logs"; return 0 ;;
82
82
 
83
- --user-must-approve) COMPREPLY="1"; return 0 ;;
83
+ --user-must-approve) COMPREPLY="0"; return 0 ;;
84
84
 
85
- -q) COMPREPLY="1"; return 0 ;;
85
+ -q) COMPREPLY="0"; return 0 ;;
86
86
 
87
87
  --display-level) COMPREPLY="1"; return 0 ;;
88
88
 
@@ -178,4 +178,4 @@ _mde() {
178
178
 
179
179
  complete -o filenames -o nospace -F _mde mde
180
180
  # _mde_echo_version
181
- # echo "Updated: 2023-12-26 00:07:49 UTC"
181
+ # echo "Updated: 2024-01-18 17:32:47 UTC"
data/examples/colors.md CHANGED
@@ -43,7 +43,8 @@ warning_color: fg_rgbh_ff_7f_00
43
43
  ```
44
44
 
45
45
  ::: Example blocks
46
-
46
+ ```
47
+ ```
47
48
  ```bash :Bash1
48
49
  ```
49
50
  ```link :Link1
@@ -0,0 +1,66 @@
1
+ This is a concise guide for using Bash commands to find and list recent files in a Linux system. The commands are safe to use and can help you quickly locate recently modified or accessed files.
2
+
3
+ 1. **List Recently Modified Files**:
4
+ You can use the `ls` command with sorting options to list recently modified files in the current directory.
5
+
6
+ ```bash
7
+ ls -lt
8
+ ```
9
+
10
+ 2. **Using `stat` for File Details**:
11
+ To get detailed information about file modifications, access, and change, use the `stat` command.
12
+
13
+ Example for a specific file:
14
+ ```bash
15
+ stat .
16
+ ```
17
+
18
+ 3. **Find Files**:
19
+ A. **Find Files Modified in the Last N Days**:
20
+ The `find` command is useful for searching files modified within a specific number of days.
21
+
22
+ For example, to find files modified in the last 7 days:
23
+ ```bash
24
+ find . -type f -mtime -7
25
+ ```
26
+
27
+ B. **Display Files Accessed Recently**:
28
+ Similarly, you can list files that were accessed recently using the `find` command.
29
+
30
+ 1. To list files accessed in the last 3 days:
31
+ ```bash
32
+ find . -type f -atime -3
33
+ ```
34
+
35
+ 2. **Advanced Search with `find`**:
36
+ Combine `find` with other commands for advanced searching. For instance, to list and sort files by modification time:
37
+
38
+ ```bash
39
+ find . -type f -mtime -7 -exec ls -lt {} +
40
+ ```
41
+
42
+ These commands provide a basic way to manage and track file modifications and access on your system. They are particularly useful for system administration and file management tasks.
43
+
44
+ ```link :Link1
45
+ ```
46
+
47
+ ```link :Link2
48
+ ```
49
+
50
+ ```opts :Opts1
51
+ ```
52
+
53
+ ```opts :Opts2
54
+ ```
55
+
56
+ ```port :Port1
57
+ ```
58
+
59
+ ```port :Port2
60
+ ```
61
+
62
+ ```vars :Vars1
63
+ ```
64
+
65
+ ```vars :Vars2
66
+ ```
data/examples/linked.md CHANGED
@@ -1,7 +1,6 @@
1
1
  Demonstrate setting a variable interactively for use in generated scripts.
2
2
 
3
3
  ```opts :(document_options)
4
- dump_inherited_lines: true
5
4
  pause_after_script_execution: false
6
5
  user_must_approve: false
7
6
  ```
@@ -48,5 +47,25 @@ echo VARIABLE=B
48
47
 
49
48
  ```bash :display_variable
50
49
  source bin/colorize_env_vars.sh
50
+ echo The current value of environment variable VARIABLE is now:
51
51
  colorize_env_vars '' VARIABLE
52
52
  ```
53
+
54
+ ```bash :(set_timestamp)
55
+ echo 'yyyymmdd? (default: today UTC) '; read -r yyyymmdd; [[ -z $yyyymmdd ]] && yyyymmdd="$(date -u +%y%m%d)"
56
+ echo "EC2_STACK_TS='$yyyymmdd'"
57
+ ```
58
+ ```link :request_input_and_inherit_output +(set_timestamp)
59
+ exec: true
60
+ ```
61
+
62
+ ::: Load file into inherited lines
63
+ Load (do not evaluate) and append to inherited lines.
64
+ ```link :load1
65
+ load: examples/load1.sh
66
+ ```
67
+ Load, evaluate, and append output to inherited lines.
68
+ ```link :load2_eval
69
+ load: examples/load2.sh
70
+ eval: true
71
+ ```
data/examples/load1.sh ADDED
@@ -0,0 +1,5 @@
1
+ # line 1
2
+ var1=line2
3
+ # line 3
4
+ var2=line4
5
+ # line 5
data/examples/load2.sh ADDED
@@ -0,0 +1,5 @@
1
+ # line 1
2
+ echo "var1=line2"
3
+ # line 3
4
+ echo "var2=line4"
5
+ # line 5
@@ -0,0 +1,26 @@
1
+ # Demo block nicknames
2
+
3
+ ```opts :(document_options)
4
+ save_executed_script: true
5
+ ```
6
+
7
+ ::: This block has no name.
8
+ ::: The code block is displayed.
9
+
10
+ ```bash
11
+ echo Unnamed block
12
+ ```
13
+
14
+ ::: These blocks use nicknames.
15
+ ::: The code blocks are displayed.
16
+ ::: The nicknames can be used for requiring blocks.
17
+
18
+ ```bash :[A]
19
+ echo From the required block 2
20
+ ```
21
+
22
+ ::: Execute this block that requires the block above.
23
+
24
+ ```bash :[B] +[A]
25
+ echo From the parent block 1
26
+ ```
data/examples/opts.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Demo configuring options
2
+ ## H2
3
+ ### H3
2
4
 
3
5
  ::: These Opts blocks set the color of a couple of menu options to demonstrate the live update of options.
4
6
 
@@ -21,11 +21,7 @@ class AnsiFormatter
21
21
  (data&.map do |item|
22
22
  scan_and_process_multiple_substrings(item, highlight, plain_color_sym,
23
23
  highlight_color_sym).join
24
- # color_sym = highlight.include?(item) ? highlight_color_sym : c
25
- # string_send_color(item, color_sym)
26
- end || []) #.join
27
- # formatted_deps
28
- # "#{line_prefix}#{string_send_color(label, highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n")
24
+ end || [])
29
25
  end
30
26
 
31
27
  # Function to scan a string and process its segments based on multiple substrings
data/lib/array.rb CHANGED
@@ -4,6 +4,10 @@
4
4
  # encoding=utf-8
5
5
 
6
6
  class Array
7
+ def pluck(key)
8
+ map { |hash| hash[key] if hash.is_a?(Hash) }.compact
9
+ end
10
+
7
11
  # Processes each element of the array, yielding the previous, current, and next elements to the given block.
8
12
  # Deletes the current element if the block returns true.
9
13
  # @return [Array] The modified array after conditional deletions.
@@ -8,6 +8,7 @@
8
8
  require 'fileutils'
9
9
  require_relative 'constants'
10
10
  require_relative 'exceptions'
11
+ require_relative 'find_files'
11
12
 
12
13
  ##
13
14
  # The CachedNestedFileReader class provides functionality to read file lines with the ability
@@ -38,25 +39,28 @@ class CachedNestedFileReader
38
39
  )
39
40
  end
40
41
 
41
- def readlines(filename, depth = 0, &block)
42
+ def readlines(filename, depth = 0, context: '', import_paths: nil, &block)
42
43
  if @file_cache.key?(filename)
43
44
  @file_cache[filename].each(&block) if block
44
45
  return @file_cache[filename]
45
46
  end
46
47
 
47
48
  directory_path = File.dirname(filename)
48
- # lines = File.readlines(filename, chomp: true)
49
49
  processed_lines = []
50
-
51
- File.readlines(filename, chomp: true).each do |line|
50
+ File.readlines(filename, chomp: true).each.with_index do |line, ind|
52
51
  if Regexp.new(@import_pattern) =~ line
53
52
  name_strip = $~[:name].strip
54
53
  included_file_path = if name_strip =~ %r{^/}
55
54
  name_strip
55
+ elsif import_paths
56
+ find_files(name_strip, import_paths + [directory_path])&.first
56
57
  else
57
58
  File.join(directory_path, name_strip)
58
59
  end
60
+
59
61
  processed_lines += readlines(included_file_path, depth + 1,
62
+ context: "#{filename}:#{ind + 1}",
63
+ import_paths: import_paths,
60
64
  &block)
61
65
  else
62
66
  nested_line = NestedLine.new(line, depth)
@@ -68,58 +72,58 @@ class CachedNestedFileReader
68
72
  @file_cache[filename] = processed_lines
69
73
  rescue Errno::ENOENT
70
74
  # Exceptions.error_handler('readlines', { abort: true })
71
- warn_format('readlines', "No such file -- #{filename}", { abort: true })
75
+ warn_format('readlines', "No such file -- #{filename} @@ #{context}", { abort: true })
72
76
  end
73
77
  end
74
78
 
75
- if $PROGRAM_NAME == __FILE__
76
- require 'minitest/autorun'
77
- require 'tempfile'
79
+ return if $PROGRAM_NAME != __FILE__
78
80
 
79
- class CachedNestedFileReaderTest < Minitest::Test
80
- def setup
81
- @file2 = Tempfile.new('test2.txt')
82
- @file2.write("ImportedLine1\nImportedLine2")
83
- @file2.rewind
81
+ require 'minitest/autorun'
82
+ require 'tempfile'
84
83
 
85
- @file1 = Tempfile.new('test1.txt')
86
- @file1.write("Line1\nLine2\n #insert #{@file2.path}\nLine3")
87
- @file1.rewind
88
- @reader = CachedNestedFileReader.new(import_pattern: /^ *#insert (?'name'.+)$/)
89
- end
84
+ class CachedNestedFileReaderTest < Minitest::Test
85
+ def setup
86
+ @file2 = Tempfile.new('test2.txt')
87
+ @file2.write("ImportedLine1\nImportedLine2")
88
+ @file2.rewind
90
89
 
91
- def teardown
92
- @file1.close
93
- @file1.unlink
90
+ @file1 = Tempfile.new('test1.txt')
91
+ @file1.write("Line1\nLine2\n #insert #{@file2.path}\nLine3")
92
+ @file1.rewind
93
+ @reader = CachedNestedFileReader.new(import_pattern: /^ *#insert (?'name'.+)$/)
94
+ end
94
95
 
95
- @file2.close
96
- @file2.unlink
97
- end
96
+ def teardown
97
+ @file1.close
98
+ @file1.unlink
98
99
 
99
- def test_readlines_without_imports
100
- result = @reader.readlines(@file2.path).map(&:to_s)
101
- assert_equal %w[ImportedLine1 ImportedLine2], result
102
- end
100
+ @file2.close
101
+ @file2.unlink
102
+ end
103
103
 
104
- def test_readlines_with_imports
105
- result = @reader.readlines(@file1.path).map(&:to_s)
106
- assert_equal %w[Line1 Line2 ImportedLine1 ImportedLine2 Line3],
107
- result
108
- end
104
+ def test_readlines_without_imports
105
+ result = @reader.readlines(@file2.path).map(&:to_s)
106
+ assert_equal %w[ImportedLine1 ImportedLine2], result
107
+ end
109
108
 
110
- def test_caching_functionality
111
- # First read
109
+ def test_readlines_with_imports
110
+ result = @reader.readlines(@file1.path).map(&:to_s)
111
+ assert_equal %w[Line1 Line2 ImportedLine1 ImportedLine2 Line3],
112
+ result
113
+ end
112
114
 
113
- result1 = @reader.readlines(@file2.path).map(&:to_s)
115
+ def test_caching_functionality
116
+ # First read
114
117
 
115
- # Simulate file content change
116
- @file2.reopen(@file2.path, 'w') { |f| f.write('ChangedLine') }
118
+ result1 = @reader.readlines(@file2.path).map(&:to_s)
117
119
 
118
- # Second read (should read from cache, not the changed file)
119
- result2 = @reader.readlines(@file2.path).map(&:to_s)
120
+ # Simulate file content change
121
+ @file2.reopen(@file2.path, 'w') { |f| f.write('ChangedLine') }
120
122
 
121
- assert_equal result1, result2
122
- assert_equal %w[ImportedLine1 ImportedLine2], result2
123
- end
123
+ # Second read (should read from cache, not the changed file)
124
+ result2 = @reader.readlines(@file2.path).map(&:to_s)
125
+
126
+ assert_equal result1, result2
127
+ assert_equal %w[ImportedLine1 ImportedLine2], result2
124
128
  end
125
129
  end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+ require 'terminal-table'
3
+
4
+ cmd = 'aws ce get-cost-and-usage --time-period Start=2023-12-01,End=2023-12-31 --granularity MONTHLY --metrics "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE'
5
+
6
+ # Parse the YAML content
7
+ text = system(cmd)
8
+ data = YAML.load(text)
9
+
10
+ # Extracting the relevant information
11
+ services = data["ResultsByTime"][0]["Groups"].map do |group|
12
+ service_name = group["Keys"][0]
13
+ unblended_cost = "#{group['Metrics']['UnblendedCost']['Amount']} #{group['Metrics']['UnblendedCost']['Unit']}"
14
+ usage_quantity = "#{group['Metrics']['UsageQuantity']['Amount']} #{group['Metrics']['UsageQuantity']['Unit']}"
15
+ [service_name, unblended_cost, usage_quantity]
16
+ end
17
+
18
+ # Create a table
19
+ table = Terminal::Table.new :headings => ['Service', 'Unblended Cost', 'Usage Quantity'], :rows => services
20
+
21
+ # Output the table
22
+ puts table
data/lib/constants.rb CHANGED
@@ -17,6 +17,13 @@ IndexedLine = Struct.new(:index, :line) do
17
17
  end
18
18
  end
19
19
 
20
+ class LinkDataKeys
21
+ Eval = 'eval'
22
+ Exec = 'exec'
23
+ Load = 'load'
24
+ Return = 'return'
25
+ end
26
+
20
27
  class LoadFile
21
28
  Load = true
22
29
  Reuse = false
data/lib/exceptions.rb CHANGED
@@ -4,12 +4,14 @@
4
4
  # encoding=utf-8
5
5
 
6
6
  module Exceptions
7
- def self.error_handler(name = '', opts = {}, format_string: "\nError: %{name} -- %{message}", color_symbol: :red, take_count: 16)
7
+ def self.error_handler(name = '', opts = {}, backtrace: $@, format_string: "\nError: %{name} -- %{message}", color_symbol: :red, take_count: 16)
8
8
  warn(error = format(format_string,
9
9
  { name: name, message: $! }).send(color_symbol))
10
- warn($@.select do |s|
11
- s.include? 'markdown_exec'
12
- end.reject { |s| s.include? 'vendor' }.take(take_count).map.with_index { |line, ind| " * #{ind}: #{line}" })
10
+ if backtrace
11
+ warn(backtrace.select do |s|
12
+ s.include? 'markdown_exec'
13
+ end.reject { |s| s.include? 'vendor' }.take(take_count).map.with_index { |line, ind| " * #{ind}: #{line}" })
14
+ end
13
15
 
14
16
  binding.pry if $tap_enable
15
17
  raise ArgumentError, error unless opts.fetch(:abort, true)
data/lib/fcb.rb CHANGED
@@ -21,6 +21,7 @@ module MarkdownExec
21
21
  dname: nil,
22
22
  indent: '',
23
23
  name: nil,
24
+ nickname: nil,
24
25
  oname: nil,
25
26
  reqs: [],
26
27
  shell: '',
@@ -38,12 +39,13 @@ module MarkdownExec
38
39
  # @param fcb [Object] The FCB object whose title is to be derived.
39
40
  # @return [String] The derived title.
40
41
  def derive_title_from_body
41
- body_content = @attrs[:body]
42
- unless body_content
42
+ unless (body_content = @attrs[:body])
43
+ # empty body -> empty title
43
44
  @attrs[:title] = ''
44
45
  return
45
46
  end
46
47
 
48
+ # body -> title
47
49
  @attrs[:title] = if body_content.count == 1
48
50
  body_content.first
49
51
  else
@@ -113,6 +115,7 @@ if $PROGRAM_NAME == __FILE__
113
115
  headings: %w[Header1 Header2],
114
116
  dname: 'Sample name',
115
117
  indent: '',
118
+ nickname: nil,
116
119
  name: 'Sample name',
117
120
  oname: 'Sample name',
118
121
  reqs: %w[req1 req2],
data/lib/filter.rb CHANGED
@@ -38,10 +38,6 @@ 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]
45
41
  apply_name_filters(options, filters, name)
46
42
  apply_shell_filters(options, filters, shell)
47
43
  apply_other_filters(options, filters, fcb)
@@ -88,17 +84,19 @@ module MarkdownExec
88
84
  def self.apply_shell_filters(options, filters, shell)
89
85
  filters[:shell_expect] = shell == 'expect'
90
86
 
87
+ if shell.empty? && options[:bash_only]
88
+ filters[:shell_exclude] = true
89
+ return
90
+ end
91
+
91
92
  if shell.present? && options[:select_by_shell_regex].present?
92
93
  filters[:shell_select] =
93
94
  !!(shell =~ /#{options[:select_by_shell_regex]}/)
94
95
  end
95
96
 
96
- unless shell.present? && options[:exclude_by_shell_regex].present?
97
- return
98
- end
97
+ return unless shell.present? && options[:exclude_by_shell_regex].present?
99
98
 
100
- filters[:shell_exclude] =
101
- !!(shell =~ /#{options[:exclude_by_shell_regex]}/)
99
+ filters[:shell_exclude] = !!(shell =~ /#{options[:exclude_by_shell_regex]}/)
102
100
  end
103
101
 
104
102
  # Applies additional filters to determine whether to include or
@@ -126,8 +124,6 @@ module MarkdownExec
126
124
  !!(options[:block_name_wrapper_match].present? &&
127
125
  name =~ /#{options[:block_name_wrapper_match]}/)
128
126
 
129
- return unless options[:bash_only]
130
-
131
127
  filters[:shell_default] = (shell == BlockType::BASH)
132
128
  end
133
129
 
@@ -178,6 +174,20 @@ module MarkdownExec
178
174
  options[pattern].present? && fcb[:oname] =~ /#{options[pattern]}/
179
175
  end
180
176
  end
177
+
178
+ # Yields to the provided block with specified parameters if certain conditions are met.
179
+ # The method checks if a block is given, if the selected_messages include :blocks,
180
+ # and if the fcb_select? method returns true for the given fcb.
181
+ #
182
+ # @param fcb [Object] The object to be evaluated and potentially passed to the block.
183
+ # @param selected_messages [Array<Symbol>] A collection of message types, one of which must be :blocks.
184
+ # @param block [Block] A block to be called if conditions are met.
185
+ def self.yield_to_block_if_applicable(fcb, selected_messages, configuration = {}, &block)
186
+ if block_given? && selected_messages.include?(:blocks) &&
187
+ fcb_select?(configuration, fcb)
188
+ block.call :blocks, fcb
189
+ end
190
+ end
181
191
  end
182
192
  end
183
193