feat(writer): add template_mapper (ParsedTemplate -> ChapterSpec)

This commit is contained in:
lhl
2026-08-13 09:31:28 +08:00
parent 8db9cbfdf7
commit c1fbcff088
2 changed files with 39 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
from types import SimpleNamespace
from genesis.writer.template_mapper import map_template
from genesis.writer.models import ChapterSpec
def _fake_parsed():
ch1 = SimpleNamespace(chapter_id="intro", title="はじめに", section_placeholder="{{section:introduction}}")
ch2 = SimpleNamespace(chapter_id="db_design", title="DB 設計", section_placeholder=None)
return SimpleNamespace(chapters=[ch1, ch2])
def test_map_template_ordered():
specs = map_template(_fake_parsed())
assert [s.chapter_id for s in specs] == ["intro", "db_design"]
assert specs[0].section_placeholder == "{{section:introduction}}"
assert specs[1].section_placeholder is None
assert all(isinstance(s, ChapterSpec) for s in specs)