powertom 0.9.0 → 0.9.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/powertom/adapter/ruby_pptx_adapter.rb +25 -4
- data/lib/powertom/render.rb +1 -0
- data/lib/powertom/table_loop.rb +41 -12
- data/lib/powertom/validator.rb +1 -0
- data/lib/powertom/version.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a96e7237376a779625f1706110f17909e79ea1b9c7ea7de5fd5485825ed5a621
|
|
4
|
+
data.tar.gz: bac54a66f3dc5a183e6569412bead77b6416206cd10ef1def0744573edfd94e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c548d5257b9bc1e3a672ddf74b0764dc0570b666f7c1ad1a9657b839d42a70aa26bc609ff86f75dca6ca21da04b379f76810344e3ac1b7cad3e4efefd28cc985
|
|
7
|
+
data.tar.gz: 7a8b332d70090533b51298441665be76cc9f078f44dc21f2196575d9c5d4be2f0b916d67dbba0eac4030657ed0c20f48cb8a1644c9ab5a4145eea637a1c0fbae
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,25 @@ and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.9.1] - 2026-11-20
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Table block merged-cell validation now follows the documented rule
|
|
14
|
+
(design §9.4.4): a merge is allowed on a static row's fixed columns and is
|
|
15
|
+
rejected only when it intersects a column band or a row block. Previously
|
|
16
|
+
the presence of any column band rejected a merge on *any* row, so a valid
|
|
17
|
+
template with a merged total/footer row outside the band could not pass
|
|
18
|
+
`check` or render. The adapter now reports per-row merged column spans, so
|
|
19
|
+
the decision is precise; callers that do not supply these spans keep the old
|
|
20
|
+
conservative behavior.
|
|
21
|
+
- A nested `{{#rows}}` block whose relative path still contains `[]` (for
|
|
22
|
+
example `{{#rows a[].b[].c}}` under `{{#rows a}}`) is now a
|
|
23
|
+
`TemplateSyntaxError` pointing at the nested-block form. Such a path passed
|
|
24
|
+
structure validation but always failed at render with a confusing
|
|
25
|
+
"missing child array 'b[].c'" error, because `PathResolver` only supports
|
|
26
|
+
`field` and `field[index]`, not `field[]`.
|
|
27
|
+
|
|
9
28
|
## [0.9.0] - 2026-11-19
|
|
10
29
|
|
|
11
30
|
### Fixed
|
|
@@ -603,7 +603,8 @@ module PowerTom
|
|
|
603
603
|
|
|
604
604
|
# 表格结构(表格行循环用):逐页每张表的行与单元格文本,以及合并单元格分布
|
|
605
605
|
# 返回 [{slide_no:, shape:, columns:, element:, frame:, rows: [[cell_text, ...], ...],
|
|
606
|
-
# merged_rows: [bool, ...]}]
|
|
606
|
+
# merged_rows: [bool, ...], merged_spans: [[[first_col, last_col], ...], ...]}]
|
|
607
|
+
# merged_spans 逐行给出水平合并覆盖的列区间(含被跨过的列),供列带冲突判定精确到列。
|
|
607
608
|
def table_contexts(prs)
|
|
608
609
|
list = []
|
|
609
610
|
prs.slides.each_with_index do |slide, i|
|
|
@@ -611,6 +612,9 @@ module PowerTom
|
|
|
611
612
|
next unless shape.respond_to?(:table?) && shape.table?
|
|
612
613
|
|
|
613
614
|
table = shape.table
|
|
615
|
+
spans = table.rows.map do |row|
|
|
616
|
+
row_spans_for(row)
|
|
617
|
+
end
|
|
614
618
|
list << {
|
|
615
619
|
slide_no: i + 1,
|
|
616
620
|
shape: shape.name,
|
|
@@ -618,15 +622,32 @@ module PowerTom
|
|
|
618
622
|
element: table_element(shape),
|
|
619
623
|
frame: shape.element,
|
|
620
624
|
rows: table.rows.map { |row| row.cells.map { |cell| cell.text.to_s } },
|
|
621
|
-
merged_rows:
|
|
622
|
-
|
|
623
|
-
end
|
|
625
|
+
merged_rows: spans.map { |cols| !cols.empty? },
|
|
626
|
+
merged_spans: spans
|
|
624
627
|
}
|
|
625
628
|
end
|
|
626
629
|
end
|
|
627
630
|
list
|
|
628
631
|
end
|
|
629
632
|
|
|
633
|
+
# 一行的水平合并区间:[first_col, last_col]。合并原点用 span_width 覆盖跨列,
|
|
634
|
+
# 被跨过的 spanned 单元格不再单独计区间,避免重复。
|
|
635
|
+
def row_spans_for(row)
|
|
636
|
+
cells = row.cells
|
|
637
|
+
spans = []
|
|
638
|
+
covered = {}
|
|
639
|
+
cells.each_with_index do |cell, c|
|
|
640
|
+
next if covered[c]
|
|
641
|
+
next unless cell.merge_origin? || cell.spanned?
|
|
642
|
+
|
|
643
|
+
width = cell.merge_origin? ? cell.span_width : 1
|
|
644
|
+
last = [c + width - 1, cells.size - 1].min
|
|
645
|
+
(c..last).each { |index| covered[index] = true }
|
|
646
|
+
spans << [c, last]
|
|
647
|
+
end
|
|
648
|
+
spans
|
|
649
|
+
end
|
|
650
|
+
|
|
630
651
|
# 克隆第 row_index 行为 count 份(插在原位置),再删除模板行;
|
|
631
652
|
# 同步 graphicFrame 高度,避免行数变化后被外框裁剪。
|
|
632
653
|
def expand_table_row(table_element, frame_element, row_index, count)
|
data/lib/powertom/render.rb
CHANGED
|
@@ -461,6 +461,7 @@ module PowerTom
|
|
|
461
461
|
# 结构错误(表内行号)补上页码与形状名,方便设计师定位
|
|
462
462
|
def table_plan(table)
|
|
463
463
|
TableLoop.plan(table[:rows], merged_rows: table[:merged_rows],
|
|
464
|
+
merged_spans: table[:merged_spans],
|
|
464
465
|
columns: table[:columns])
|
|
465
466
|
rescue TemplateSyntaxError => e
|
|
466
467
|
raise TemplateSyntaxError, "slide #{table[:slide_no]} table '#{table[:shape]}': #{e.message}"
|
data/lib/powertom/table_loop.rb
CHANGED
|
@@ -28,11 +28,13 @@ module PowerTom
|
|
|
28
28
|
|
|
29
29
|
# rows: [[cell_text, ...], ...]
|
|
30
30
|
# merged_rows: [bool](该行是否含合并单元格)
|
|
31
|
+
# merged_spans: [[[first_col, last_col], ...], ...](逐行的水平合并列区间;
|
|
32
|
+
# 仅用于列带冲突精确到列。nil → 回退到"有合并即拒绝"的保守口径)
|
|
31
33
|
# columns: 表格列数(nil → 不校验 grid 的两列模板约束)
|
|
32
34
|
# 返回 nil / {kind: :simple, ...} / {kind: :nested, ...} / {kind: :grid, ...} /
|
|
33
35
|
# {kind: :blocks, blocks:, cols:}
|
|
34
|
-
def plan(rows, merged_rows: [], columns: nil)
|
|
35
|
-
return blocks_plan(rows, merged_rows) if block_syntax?(rows)
|
|
36
|
+
def plan(rows, merged_rows: [], columns: nil, merged_spans: nil)
|
|
37
|
+
return blocks_plan(rows, merged_rows, merged_spans) if block_syntax?(rows)
|
|
36
38
|
|
|
37
39
|
grid_markers = collect_grid_markers(rows)
|
|
38
40
|
row_markers = collect_row_markers(rows)
|
|
@@ -432,7 +434,7 @@ module PowerTom
|
|
|
432
434
|
end
|
|
433
435
|
end
|
|
434
436
|
|
|
435
|
-
def blocks_plan(rows, merged_rows)
|
|
437
|
+
def blocks_plan(rows, merged_rows, merged_spans)
|
|
436
438
|
row_tags, col_tags, if_tags = collect_block_tags(rows)
|
|
437
439
|
band = parse_column_band(rows, row_tags, col_tags)
|
|
438
440
|
col_ifs, row_ifs = split_ifs(if_tags, band)
|
|
@@ -446,7 +448,7 @@ module PowerTom
|
|
|
446
448
|
end
|
|
447
449
|
|
|
448
450
|
check_block_ifs!(blocks)
|
|
449
|
-
check_block_merges!(merged_rows, blocks, band)
|
|
451
|
+
check_block_merges!(merged_rows, blocks, band, merged_spans)
|
|
450
452
|
stacks = build_row_stacks(blocks)
|
|
451
453
|
check_block_labels!(rows, stacks, band)
|
|
452
454
|
{ kind: :blocks, blocks: blocks, cols: band }
|
|
@@ -662,7 +664,15 @@ module PowerTom
|
|
|
662
664
|
"table row #{item[:row] + 1}: {{#rows #{path}}} must start with #{prefix} " \
|
|
663
665
|
"(parent block #{parent[:path]})"
|
|
664
666
|
end
|
|
665
|
-
|
|
667
|
+
relative = path.delete_prefix("#{prefix}.")
|
|
668
|
+
# 子块只展开一层数组;relative 再含 [] 时下游 PathResolver 无法解析(field[] 不受支持)。
|
|
669
|
+
# 多层数组必须写成多级嵌套区块,而不是在一条路径里塞多个 []。
|
|
670
|
+
if relative.include?("[]")
|
|
671
|
+
raise TemplateSyntaxError,
|
|
672
|
+
"table row #{item[:row] + 1}: {{#rows #{path}}} nests more than one array level; " \
|
|
673
|
+
"use a nested row block instead (for example {{#rows #{prefix}.items}})"
|
|
674
|
+
end
|
|
675
|
+
block[:relative] = relative
|
|
666
676
|
elsif path.include?("[]")
|
|
667
677
|
raise TemplateSyntaxError,
|
|
668
678
|
"table row #{item[:row] + 1}: a top-level row block path has no [] (for example {{#rows classes}})"
|
|
@@ -761,21 +771,40 @@ module PowerTom
|
|
|
761
771
|
first_col: open[:col], last_col: close[:col], width: width }
|
|
762
772
|
end
|
|
763
773
|
|
|
764
|
-
|
|
765
|
-
|
|
774
|
+
# 合并判定遵循设计 §9.4.4:合并允许出现在静态行/固定列,但不得与列带或行区块相交。
|
|
775
|
+
# 行区块的合并是整行克隆,任何列都冲突;列带只克隆 [first_col, last_col],
|
|
776
|
+
# 因此有列级 merged_spans 时只拒绝与该区间相交的合并,放行纯固定列的静态合并。
|
|
777
|
+
def check_block_merges!(merged_rows, blocks, band, merged_spans = nil)
|
|
778
|
+
stacks = build_row_stacks(blocks)
|
|
779
|
+
merged_rows.each_with_index do |merged, r|
|
|
780
|
+
next unless merged
|
|
781
|
+
next if stacks[r].nil?
|
|
782
|
+
|
|
783
|
+
raise TemplateSyntaxError, "table row #{r + 1}: row blocks do not support merged cells; split them first"
|
|
784
|
+
end
|
|
785
|
+
return unless band
|
|
786
|
+
|
|
787
|
+
if merged_spans
|
|
788
|
+
check_band_merge_spans!(merged_spans, stacks, band)
|
|
789
|
+
else
|
|
766
790
|
row = merged_rows.index(true)
|
|
767
791
|
if row
|
|
768
792
|
raise TemplateSyntaxError,
|
|
769
793
|
"table row #{row + 1}: column band loops do not support merged cells; split them first"
|
|
770
794
|
end
|
|
771
795
|
end
|
|
796
|
+
end
|
|
772
797
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
798
|
+
# 逐行判断水平合并区间是否与列带的列区间相交;行区块行已由上层拒绝,不重复报。
|
|
799
|
+
def check_band_merge_spans!(merged_spans, stacks, band)
|
|
800
|
+
first = band[:first_col]
|
|
801
|
+
last = band[:last_col]
|
|
802
|
+
merged_spans.each_with_index do |spans, r|
|
|
803
|
+
next if stacks[r]
|
|
804
|
+
next unless spans&.any? { |c1, c2| c1 <= last && c2 >= first }
|
|
777
805
|
|
|
778
|
-
raise TemplateSyntaxError,
|
|
806
|
+
raise TemplateSyntaxError,
|
|
807
|
+
"table row #{r + 1}: merged cells cannot intersect a column band; split them first"
|
|
779
808
|
end
|
|
780
809
|
end
|
|
781
810
|
|
data/lib/powertom/validator.rb
CHANGED
|
@@ -133,6 +133,7 @@ module PowerTom
|
|
|
133
133
|
failed_tables = Set.new
|
|
134
134
|
table_structures.each do |table|
|
|
135
135
|
plan = TableLoop.plan(table[:rows], merged_rows: table[:merged_rows],
|
|
136
|
+
merged_spans: table[:merged_spans],
|
|
136
137
|
columns: table[:columns])
|
|
137
138
|
table_plans[[table[:slide_no], table[:shape]]] = plan if plan
|
|
138
139
|
rescue TemplateSyntaxError => e
|
data/lib/powertom/version.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module PowerTom
|
|
4
|
+
# 0.9.1:表格区块的两处结构校验修复——列带冲突精确到列(放行静态行固定列合并),
|
|
5
|
+
# 子块路径 relative 禁止再含 [](改写成多级嵌套区块)。
|
|
4
6
|
# 0.9.0:Windows 文件锁修复(rubyzip 句柄泄漏 + Tempfile finalizer 竞态)、
|
|
5
7
|
# check 契约修复(不抛异常,与 render 共享同一套规则集)、
|
|
6
8
|
# ruby_pptx 0.3.1 版本门控;并含 0.8.0 的受限聚合与 AssetResolver
|
|
7
|
-
VERSION = "0.9.
|
|
9
|
+
VERSION = "0.9.1"
|
|
8
10
|
end
|