markdown_exec 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/Gemfile.lock +2 -2
  4. data/Rakefile +3 -3
  5. data/bats/block-types.bats +13 -7
  6. data/bats/import.bats +6 -0
  7. data/bats/markup.bats +6 -15
  8. data/bats/options-collapse.bats +26 -0
  9. data/bats/options.bats +1 -1
  10. data/bats/table.bats +8 -0
  11. data/bats/test_helper.bash +74 -49
  12. data/bats/variable-expansion.bats +46 -0
  13. data/bin/tab_completion.sh +1 -1
  14. data/docs/dev/bats-document-configuration.md +8 -1
  15. data/docs/dev/block-type-bash.md +1 -1
  16. data/docs/dev/block-type-opts.md +1 -5
  17. data/docs/dev/block-type-vars.md +4 -0
  18. data/docs/dev/import-missing.md +2 -0
  19. data/docs/dev/menu-cli.md +1 -1
  20. data/docs/dev/options-collapse.md +47 -0
  21. data/docs/dev/requiring-blocks.md +3 -0
  22. data/docs/dev/specs.md +2 -1
  23. data/docs/dev/table-crash.md +39 -0
  24. data/docs/dev/table-indent.md +26 -0
  25. data/docs/dev/text-decoration.md +2 -5
  26. data/docs/dev/variable-expansion.md +2 -4
  27. data/examples/bash-blocks.md +1 -1
  28. data/examples/block-names.md +1 -1
  29. data/examples/block-types.md +1 -1
  30. data/examples/data-files.md +1 -1
  31. data/examples/document_options.md +2 -2
  32. data/examples/indent.md +1 -1
  33. data/examples/interrupt.md +1 -1
  34. data/examples/link-blocks-vars.md +1 -1
  35. data/examples/linked.md +1 -1
  36. data/examples/linked1.md +1 -1
  37. data/examples/nickname.md +1 -1
  38. data/examples/opts-blocks-require.md +1 -1
  39. data/examples/opts-blocks.md +1 -1
  40. data/examples/opts_output_execution.md +1 -1
  41. data/examples/pass-through-arguments.md +1 -1
  42. data/examples/pause-after-execution.md +1 -1
  43. data/examples/port-blocks.md +1 -1
  44. data/examples/save.md +1 -1
  45. data/examples/text-markup.md +1 -1
  46. data/examples/variable-expansion.md +6 -2
  47. data/examples/vars-blocks.md +1 -1
  48. data/examples/wrap.md +1 -1
  49. data/lib/block_types.rb +4 -0
  50. data/lib/cached_nested_file_reader.rb +7 -4
  51. data/lib/collapser.rb +302 -0
  52. data/lib/constants.rb +10 -0
  53. data/lib/evaluate_shell_expressions.rb +0 -3
  54. data/lib/fcb.rb +13 -17
  55. data/lib/format_table.rb +11 -7
  56. data/lib/hash_delegator.rb +461 -272
  57. data/lib/hierarchy_string.rb +5 -1
  58. data/lib/markdown_exec/version.rb +1 -1
  59. data/lib/markdown_exec.rb +16 -32
  60. data/lib/mdoc.rb +100 -35
  61. data/lib/menu.src.yml +124 -17
  62. data/lib/menu.yml +102 -16
  63. data/lib/ww.rb +75 -22
  64. metadata +12 -9
  65. data/lib/append_to_bash_history.rb +0 -303
  66. data/lib/ce_get_cost_and_usage.rb +0 -23
  67. data/lib/doh.rb +0 -190
  68. data/lib/layered_hash.rb +0 -143
  69. data/lib/poly.rb +0 -171
data/lib/fcb.rb CHANGED
@@ -64,7 +64,8 @@ module MarkdownExec
64
64
  def for_menu!(
65
65
  block_calls_scan: @delegate_object[:block_calls_scan],
66
66
  block_name_match: @delegate_object[:block_name_match],
67
- block_name_nick_match: @delegate_object[:block_name_nick_match]
67
+ block_name_nick_match: @delegate_object[:block_name_nick_match],
68
+ id: ''
68
69
  )
69
70
  call = @attrs[:call] = @attrs[:start_line]&.match(
70
71
  Regexp.new(block_calls_scan)
@@ -83,7 +84,7 @@ module MarkdownExec
83
84
  bm && bm[1] ? bm[:title] : titlexcall
84
85
  end
85
86
  @attrs[:title] = @attrs[:oname] = oname
86
-
87
+ @attrs[:id] = id
87
88
  @attrs[:dname] = HashDelegator.indent_all_lines(
88
89
  (yield oname, BLOCK_TYPE_COLOR_OPTIONS[@attrs[:type]]),
89
90
  @attrs[:indent]
@@ -107,17 +108,10 @@ module MarkdownExec
107
108
  def method_missing(method, *args, &block)
108
109
  method_name = method.to_s
109
110
  if @attrs.respond_to?(method_name)
110
- if method_name == 'fetch'
111
- ww args[0]
112
- end
113
111
  @attrs.send(method_name, *args, &block)
114
112
  elsif method_name[-1] == '='
115
- # ww caller.take(3) if method_name == 'label='
116
- ww method_name
117
113
  @attrs[method_name.chop.to_sym] = args[0]
118
114
  else
119
- # ww caller.take(3) if method_name == 'label'
120
- ww method_name
121
115
  @attrs[method_name.to_sym]
122
116
  end
123
117
  rescue StandardError => err
@@ -158,20 +152,22 @@ ww method_name
158
152
  @attrs.to_yaml
159
153
  end
160
154
 
161
- # Expand in body and dname
162
- def variable_expansion!(pattern, replacement_dictionary)
155
+ # Expand variables in `dname` and `body` attributes
156
+ def expand_variables_in_attributes!(pattern, replacements)
163
157
  ### update name, nickname, title, label ???
164
- @attrs[:dname] = @attrs[:dname].gsub(pattern) { |match|
165
- replacement_dictionary[match]
166
- }
158
+
159
+ # Replace variables in `dname` using the replacements dictionary
160
+ @attrs[:dname] = @attrs[:dname].gsub(pattern) do |match|
161
+ replacements[match]
162
+ end
163
+
164
+ # Replace variables in each line of `body` if `body` is present
167
165
  if @attrs[:body]
168
166
  @attrs[:body] = @attrs[:body].map do |line|
169
167
  if line.empty?
170
168
  line
171
169
  else
172
- line.gsub(pattern) do |match|
173
- replacement_dictionary[match]
174
- end
170
+ line.gsub(pattern) { |match| replacements[match] }
175
171
  end
176
172
  end
177
173
  end
data/lib/format_table.rb CHANGED
@@ -74,11 +74,11 @@ module MarkdownTableFormatter
74
74
  end
75
75
  end
76
76
 
77
- def format_row_line(
77
+ def format_row_line__hs(
78
78
  row, alignment_indicators, column_widths, decorate,
79
79
  text_sym: :text, style_sym: :color
80
80
  )
81
- return '' if row.cells.nil?
81
+ return HierarchyString.new if row.cells.nil?
82
82
 
83
83
  border_style = decorate && decorate[:border]
84
84
  HierarchyString.new(
@@ -103,16 +103,20 @@ module MarkdownTableFormatter
103
103
  { text_sym => ' |', style_sym => border_style }].compact,
104
104
  style_sym: style_sym,
105
105
  text_sym: text_sym
106
- ).decorate
106
+ )
107
107
  end
108
108
 
109
- def format_rows(rows, alignment_indicators, column_widths, decorate)
109
+ def format_rows__hs(rows, alignment_indicators, column_widths, decorate)
110
110
  rows.map do |row|
111
- format_row_line(row, alignment_indicators, column_widths, decorate)
111
+ format_row_line__hs(row, alignment_indicators, column_widths, decorate)
112
112
  end
113
113
  end
114
114
 
115
- def format_table(lines:, column_count:, decorate: nil)
115
+ def format_table(**kwargs)
116
+ format_table__hs(**kwargs).map(&:decorate)
117
+ end
118
+
119
+ def format_table__hs(lines:, column_count:, decorate: nil)
116
120
  unless column_count.positive?
117
121
  return lines.map do |line|
118
122
  HierarchyString.new([{ text: line }])
@@ -125,7 +129,7 @@ module MarkdownTableFormatter
125
129
  alignment_indicators, column_widths =
126
130
  calculate_column_alignment_and_widths(rows, column_count)
127
131
 
128
- format_rows(rows, alignment_indicators, column_widths, decorate)
132
+ format_rows__hs(rows, alignment_indicators, column_widths, decorate)
129
133
  end
130
134
 
131
135
  def insert_every_other(array, obj)