markdown_exec 2.7.5 → 2.8.1

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/fcb.rb CHANGED
@@ -5,6 +5,29 @@
5
5
  require 'digest'
6
6
  require_relative 'namer'
7
7
 
8
+ def parse_yaml_of_ux_block(
9
+ data,
10
+ menu_format: nil,
11
+ prompt: nil,
12
+ validate: nil
13
+ )
14
+ export = data['export']
15
+ export = data if export.nil?
16
+ name = export['name']
17
+ raise "Invalid data: #{data.inspect}" unless name.present?
18
+
19
+ OpenStruct.new(
20
+ allowed: export['allowed'],
21
+ default: export['default'],
22
+ exec: export['exec'],
23
+ menu_format: export['menu_format'] || menu_format,
24
+ name: name,
25
+ prompt: export['prompt'] || prompt,
26
+ transform: export['transform'],
27
+ validate: export['validate'] || validate
28
+ )
29
+ end
30
+
8
31
  module MarkdownExec
9
32
  class Error < StandardError; end
10
33
 
@@ -33,10 +56,6 @@ module MarkdownExec
33
56
  title: '',
34
57
  type: ''
35
58
  }.merge(options)
36
- # @attrs[:raw_body] ||= @attrs[:body]
37
- # @attrs[:raw_dname] ||= @attrs[:dname]
38
- # @attrs[:raw_s0printable] ||= @attrs[:s0printable]
39
- # @attrs[:raw_s1decorated] ||= @attrs[:s1decorated]
40
59
  end
41
60
 
42
61
  def code_name_included?(*names)
@@ -69,34 +88,6 @@ module MarkdownExec
69
88
  end
70
89
  end
71
90
 
72
- # def body=(value)
73
- # ww0 'body=', value
74
- # # binding.irb
75
- # @attrs[:raw_body] ||= value
76
- # @attrs[:body] = value
77
- # end
78
-
79
- # def dname=(value)
80
- # ww0 'dname=', value
81
- # binding.irb if value == ' | Species| Not specified'
82
- # @attrs[:raw_dname] ||= value
83
- # @attrs[:dname] = value
84
- # end
85
-
86
- # def s0printable=(value)
87
- # ww0 's0printable=', value
88
- # # binding.irb
89
- # @attrs[:raw_s0printable] ||= value
90
- # @attrs[:s0printable] = value
91
- # end
92
-
93
- # def s1decorated=(value)
94
- # ww0 's1decorated=', value
95
- # # binding.irb
96
- # @attrs[:raw_s1decorated] ||= value
97
- # @attrs[:s1decorated] = value
98
- # end
99
-
100
91
  # Processes a block to generate its summary, modifying its attributes
101
92
  # based on various matching criteria.
102
93
  # It handles special formatting for bash blocks, extracting and setting
@@ -106,12 +97,14 @@ module MarkdownExec
106
97
  # @return [Object] The modified functional code block with updated
107
98
  # summary attributes.
108
99
  def for_menu!(
109
- block_calls_scan: @delegate_object[:block_calls_scan],
110
- block_name_match: @delegate_object[:block_name_match],
111
- block_name_nick_match: @delegate_object[:block_name_nick_match],
112
- id: ''
100
+ block_calls_scan:,
101
+ block_name_match:,
102
+ block_name_nick_match:,
103
+ id: '',
104
+ menu_format:,
105
+ prompt:,
106
+ table_center:
113
107
  )
114
- # binding.irb
115
108
  call = @attrs[:call] = @attrs[:start_line]&.match(
116
109
  Regexp.new(block_calls_scan)
117
110
  )&.fetch(1, nil)
@@ -130,6 +123,23 @@ module MarkdownExec
130
123
  end
131
124
  @attrs[:title] = @attrs[:oname] = oname
132
125
  @attrs[:id] = id
126
+
127
+ if @attrs[:type] == BlockType::UX
128
+ case data = YAML.load(@attrs[:body].join("\n"))
129
+ when Hash
130
+ export = parse_yaml_of_ux_block(
131
+ data,
132
+ menu_format: menu_format,
133
+ prompt: prompt
134
+ )
135
+
136
+ @attrs[:center] = table_center
137
+ oname = @attrs[:oname] = format(export.menu_format, export.to_h)
138
+ else
139
+ raise "Invalid data type: #{data.inspect}"
140
+ end
141
+ end
142
+
133
143
  @attrs[:dname] = HashDelegator.indent_all_lines(
134
144
  (yield oname, BLOCK_TYPE_COLOR_OPTIONS[@attrs[:type]]),
135
145
  @attrs[:indent]
data/lib/format_table.rb CHANGED
@@ -65,12 +65,15 @@ module MarkdownTableFormatter
65
65
 
66
66
  def format_cell(cell, align, width, truncate: true)
67
67
  plain_string = cell.gsub(/\033\[[\d;]+m|\033\[0m/, '')
68
+ exceeded = plain_string.length > width
68
69
  truncated = false
69
70
  ret = TrackedString.new(
70
71
  case
71
- when truncate && plain_string.length > width
72
+ when truncate && exceeded
72
73
  truncated = true
73
- plain_string[0, width]
74
+ plain_string[0, width] ### s/trim decorated text
75
+ when exceeded
76
+ cell
74
77
  when align == :center
75
78
  cell.center(width)
76
79
  when align == :right
@@ -79,6 +82,7 @@ module MarkdownTableFormatter
79
82
  cell.ljust(width)
80
83
  end
81
84
  )
85
+ ret.exceeded = exceeded
82
86
  ret.truncated = truncated
83
87
  ret
84
88
  end
@@ -152,11 +156,8 @@ module MarkdownTableFormatter
152
156
  alignment_indicators, column_widths =
153
157
  calculate_column_alignment_and_widths(rows, column_count)
154
158
 
155
- # ww0 'table_width', table_width
156
- # ww0 'truncate', truncate
157
-
158
159
  unless table_width.nil?
159
- sum_column_widths = column_widths.sum
160
+ sum_column_widths = column_widths.sum + ((column_count * 3) + 5)
160
161
  if sum_column_widths > table_width
161
162
  ratio = table_width.to_f / sum_column_widths
162
163
  column_widths.each_with_index do |width, i|
@@ -168,7 +169,7 @@ module MarkdownTableFormatter
168
169
  format_rows__hs(
169
170
  rows, alignment_indicators, column_widths, decorate,
170
171
  truncate: truncate
171
- ).tap { |ret| binding.irb if ret.class == TrackedString }
172
+ )
172
173
  end
173
174
 
174
175
  def insert_every_other(array, obj)