markdown_exec 2.0.8.4 → 2.2.0

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/saved_assets.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # encoding=utf-8
5
+ require_relative 'namer'
5
6
 
6
7
  module MarkdownExec
7
8
  # SavedAsset
@@ -12,23 +13,49 @@ module MarkdownExec
12
13
  # method derives a name for stdout redirection.
13
14
  #
14
15
  class SavedAsset
15
- FNR11 = %r{[^!#%&()\+,\-0-9=A-Z_a-z~]}.freeze
16
- # / !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
17
- FNR12 = '_'
18
16
  DEFAULT_FTIME = '%F-%H-%M-%S'
17
+ FILE_BLOCK_SEP = ','
18
+ JOIN_STR = '_'
19
+ MARK_STR = '~'
19
20
 
20
- # Generates a formatted script name based on the provided parameters.
21
- def self.script_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.sh')
22
- fne = filename.gsub(pattern, replace)
23
- bne = blockname.gsub(pattern, replace)
24
- "#{[prefix, time.strftime(ftime), fne, ',', bne].join(join_str)}#{exts}"
21
+ # @param filename [String] the name of the file
22
+ # @param prefix [String] the prefix to use
23
+ # @param time [Time] the time object for formatting
24
+ # @param blockname [String] the block name to include
25
+ # @param ftime [String] the time format (default: DEFAULT_FTIME)
26
+ # @param exts [String] the extension to append (default: '.sh')
27
+ def initialize(
28
+ saved_asset_format:, filename: nil, prefix: nil, time: nil, blockname: nil,
29
+ ftime: DEFAULT_FTIME, exts: nil,
30
+ mark: nil, join_str: nil
31
+ )
32
+ @filename = filename ? filename.pub_name : '*' # [String] the name of the file
33
+ @prefix = prefix || '*' # [String] the prefix to use
34
+ @time = time ? time.strftime(ftime) : '*' # [Time] the time object for formatting
35
+ @blockname = blockname ? blockname.pub_name : '*' # [String] the block name to include
36
+ # @ftime = ftime # [String] the time format (default: DEFAULT_FTIME)
37
+ @exts = exts || '.*' # [String] the extension to append (default: '.sh')
38
+ @mark = mark || MARK_STR
39
+ @join_str = join_str || JOIN_STR
40
+ @saved_asset_format = saved_asset_format
25
41
  end
26
42
 
27
- # Generates a formatted stdout name based on the provided parameters.
28
- def self.stdout_name(filename:, prefix:, time:, blockname:, ftime: DEFAULT_FTIME, join_str: '_', pattern: FNR11, replace: FNR12, exts: '.out.txt')
29
- fne = filename.gsub(pattern, replace)
30
- bne = blockname.gsub(pattern, replace)
31
- "#{[prefix, time.strftime(ftime), fne, ',', bne].join(join_str)}#{exts}"
43
+ # Generates a formatted name based on the provided parameters.
44
+ #
45
+ # @return [String] the generated formatted name
46
+ def generate_name
47
+ format(
48
+ @saved_asset_format,
49
+ {
50
+ blockname: @blockname,
51
+ exts: @exts,
52
+ filename: @filename,
53
+ join: @join_str,
54
+ mark: @mark,
55
+ prefix: @prefix,
56
+ time: @time
57
+ }
58
+ )
32
59
  end
33
60
  end
34
61
  end
@@ -61,4 +88,76 @@ class SavedAssetTest < Minitest::Test
61
88
  filename: filename, prefix: prefix, time: time, blockname: blockname
62
89
  )
63
90
  end
91
+
92
+ def test_wildcard_name_with_all_parameters
93
+ filename = 'sample.txt'
94
+ prefix = 'test'
95
+ time = Time.new(2023, 1, 1, 12, 0, 0)
96
+ blockname = 'block/1:2'
97
+ expected_wildcard = 'test_2023-01-01-12-00-00_sample_txt_,_block_1_2.sh'
98
+
99
+ assert_equal expected_wildcard, MarkdownExec::SavedAsset.wildcard_name(
100
+ filename: filename, prefix: prefix, time: time, blockname: blockname
101
+ )
102
+ end
103
+
104
+ def test_wildcard_name_with_missing_time
105
+ filename = 'sample.txt'
106
+ prefix = 'test'
107
+ time = nil
108
+ blockname = 'block/1:2'
109
+ expected_wildcard = 'test_*_sample_txt_,_block_1_2.sh'
110
+
111
+ assert_equal expected_wildcard, MarkdownExec::SavedAsset.wildcard_name(
112
+ filename: filename, prefix: prefix, time: time, blockname: blockname
113
+ )
114
+ end
115
+
116
+ def test_wildcard_name_with_missing_filename
117
+ filename = nil
118
+ prefix = 'test'
119
+ time = Time.new(2023, 1, 1, 12, 0, 0)
120
+ blockname = 'block/1:2'
121
+ expected_wildcard = 'test_2023-01-01-12-00-00_*_,_block_1_2.sh'
122
+
123
+ assert_equal expected_wildcard, MarkdownExec::SavedAsset.wildcard_name(
124
+ filename: filename, prefix: prefix, time: time, blockname: blockname
125
+ )
126
+ end
127
+
128
+ def test_wildcard_name_with_missing_prefix
129
+ filename = 'sample.txt'
130
+ prefix = nil
131
+ time = Time.new(2023, 1, 1, 12, 0, 0)
132
+ blockname = 'block/1:2'
133
+ expected_wildcard = '*_2023-01-01-12-00-00_sample_txt_,_block_1_2.sh'
134
+
135
+ assert_equal expected_wildcard, MarkdownExec::SavedAsset.wildcard_name(
136
+ filename: filename, prefix: prefix, time: time, blockname: blockname
137
+ )
138
+ end
139
+
140
+ def test_wildcard_name_with_missing_blockname
141
+ filename = 'sample.txt'
142
+ prefix = 'test'
143
+ time = Time.new(2023, 1, 1, 12, 0, 0)
144
+ blockname = nil
145
+ expected_wildcard = 'test_2023-01-01-12-00-00_sample_txt_,_*.sh'
146
+
147
+ assert_equal expected_wildcard, MarkdownExec::SavedAsset.wildcard_name(
148
+ filename: filename, prefix: prefix, time: time, blockname: blockname
149
+ )
150
+ end
151
+
152
+ def test_wildcard_name_with_all_missing
153
+ filename = nil
154
+ prefix = nil
155
+ time = nil
156
+ blockname = nil
157
+ expected_wildcard = '*_*_*_,_*.sh'
158
+
159
+ assert_equal expected_wildcard, MarkdownExec::SavedAsset.wildcard_name(
160
+ filename: filename, prefix: prefix, time: time, blockname: blockname
161
+ )
162
+ end
64
163
  end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # encoding=utf-8
5
+
6
+ class StreamsOut
7
+ attr_accessor :streams
8
+
9
+ def initialize
10
+ @streams = []
11
+ end
12
+
13
+ def append_stream_line(stream, line)
14
+ @streams << { stream: stream, line: line, timestamp: Time.now }
15
+ end
16
+
17
+ def write_execution_output_to_file(filespec)
18
+ FileUtils.mkdir_p File.dirname(filespec)
19
+
20
+ output = @streams.map do |entry|
21
+ case entry[:stream]
22
+ when ExecutionStreams::STD_OUT
23
+ entry[:line]
24
+ # "OUT: #{entry[:line]}"
25
+ when ExecutionStreams::STD_ERR
26
+ entry[:line]
27
+ # "ERR: #{entry[:line]}"
28
+ when ExecutionStreams::STD_IN
29
+ entry[:line]
30
+ # " IN: #{entry[:line]}"
31
+ end
32
+ end.join("\n")
33
+
34
+ File.write(filespec, output)
35
+ end
36
+ end
data/lib/string_util.rb CHANGED
@@ -2,7 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # encoding=utf-8
5
-
6
5
  module StringUtil
7
6
  # Splits the given string on the first occurrence of the specified character.
8
7
  # Returns an array containing the portion of the string before the character and the rest of the string.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8.4
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fareed Stevenson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2024-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -113,8 +113,11 @@ files:
113
113
  - bin/setup
114
114
  - bin/tab_completion.sh
115
115
  - bin/tab_completion.sh.erb
116
+ - examples/bash-blocks.md
117
+ - examples/block-names.md
116
118
  - examples/block_names.md
117
119
  - examples/colors.md
120
+ - examples/data-files.md
118
121
  - examples/document_options.md
119
122
  - examples/duplicate_block.md
120
123
  - examples/import0.md
@@ -124,6 +127,9 @@ files:
124
127
  - examples/index.md
125
128
  - examples/interrupt.md
126
129
  - examples/line-wrapping.md
130
+ - examples/link-blocks-block.md
131
+ - examples/link-blocks-load-save.md
132
+ - examples/link-blocks-vars.md
127
133
  - examples/linked.md
128
134
  - examples/linked1.md
129
135
  - examples/linked2.md
@@ -134,13 +140,16 @@ files:
134
140
  - examples/load2.sh
135
141
  - examples/load_code.md
136
142
  - examples/nickname.md
137
- - examples/opts.md
138
- - examples/pass-through.md
143
+ - examples/opts-blocks-require.md
144
+ - examples/opts-blocks.md
145
+ - examples/opts_output_execution.md
146
+ - examples/pass-through-arguments.md
139
147
  - examples/pause-after-execution.md
140
148
  - examples/plant.md
141
- - examples/port.md
149
+ - examples/port-blocks.md
150
+ - examples/save.md
142
151
  - examples/search.md
143
- - examples/vars.md
152
+ - examples/vars-blocks.md
144
153
  - examples/wrap.md
145
154
  - lib/ansi_formatter.rb
146
155
  - lib/array.rb
@@ -170,8 +179,10 @@ files:
170
179
  - lib/mdoc.rb
171
180
  - lib/menu.src.yml
172
181
  - lib/menu.yml
182
+ - lib/namer.rb
173
183
  - lib/object_present.rb
174
184
  - lib/option_value.rb
185
+ - lib/poly.rb
175
186
  - lib/regexp.rb
176
187
  - lib/resize_terminal.rb
177
188
  - lib/rspec_helpers.rb
@@ -179,6 +190,7 @@ files:
179
190
  - lib/saved_files_matcher.rb
180
191
  - lib/shared.rb
181
192
  - lib/std_out_err_logger.rb
193
+ - lib/streams_out.rb
182
194
  - lib/string_util.rb
183
195
  - lib/tap.rb
184
196
  homepage: https://rubygems.org/gems/markdown_exec
data/examples/vars.md DELETED
@@ -1,20 +0,0 @@
1
- ```bash :(defaults)
2
- : ${VAULT:=default}
3
- ```
4
- ```bash :show_vars +(defaults)
5
- source bin/colorize_env_vars.sh
6
- colorize_env_vars '' VAULT
7
- ```
8
- ```vars :set
9
- VAULT: 11
10
- ```
11
- ```vars :set_with_show +show_vars
12
- VAULT: 22
13
- ```
14
- ```bash :(hidden)
15
- colorize_env_vars '' NOTHING
16
- ```
17
- ```bash :show_with_set +set
18
- source bin/colorize_env_vars.sh
19
- colorize_env_vars '' VAULT
20
- ```
File without changes