mirror of
https://github.com/drewcassidy/yaclog.git
synced 2024-09-01 14:58:58 +00:00
Add to-string functions to version entries
This commit is contained in:
parent
39f6ede5f2
commit
983fff1471
@ -69,11 +69,32 @@ class VersionEntry:
|
||||
self.link_id: str = None
|
||||
self.line_no: int = -1
|
||||
|
||||
def __str__(self) -> str:
|
||||
if self.link:
|
||||
segments = [f'[{self.name}]']
|
||||
def body(self, md: bool = True) -> str:
|
||||
segments = []
|
||||
text = ''
|
||||
|
||||
for section, entries in self.sections.items():
|
||||
if section:
|
||||
if md:
|
||||
segments.append(f'## {section.title()}')
|
||||
else:
|
||||
segments.append(f'{section.upper()}:')
|
||||
|
||||
if len(entries) > 0:
|
||||
segments.append(_join_markdown(entries))
|
||||
|
||||
return _join_markdown(segments)
|
||||
|
||||
def header(self, md: bool = True) -> str:
|
||||
segments = []
|
||||
|
||||
if md:
|
||||
segments.append('##')
|
||||
|
||||
if self.link and md:
|
||||
segments.append(f'[{self.name}]')
|
||||
else:
|
||||
segments = [self.name]
|
||||
segments.append(self.name)
|
||||
|
||||
if self.date or len(self.tags) > 0:
|
||||
segments.append('-')
|
||||
@ -85,6 +106,12 @@ class VersionEntry:
|
||||
|
||||
return ' '.join(segments)
|
||||
|
||||
def text(self, md: bool = True) -> str:
|
||||
return self.body(md) + '\n\n' + self.header(md)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.header(False)
|
||||
|
||||
|
||||
class Changelog:
|
||||
def __init__(self, path: os.PathLike):
|
||||
@ -241,18 +268,11 @@ class Changelog:
|
||||
fp.write('\n\n')
|
||||
|
||||
for version in self.versions:
|
||||
fp.write(f'## {version}\n\n')
|
||||
|
||||
if version.link:
|
||||
v_links[version.name] = version.link
|
||||
|
||||
for section in version.sections:
|
||||
if section:
|
||||
fp.write(f'### {section}\n\n')
|
||||
|
||||
if len(version.sections[section]) > 0:
|
||||
fp.write(_join_markdown(version.sections[section]))
|
||||
fp.write('\n\n')
|
||||
fp.write(version.text())
|
||||
fp.write('\n\n')
|
||||
|
||||
for link_id, link in v_links.items():
|
||||
fp.write(f'[{link_id.lower()}]: {link}\n')
|
||||
|
Loading…
Reference in New Issue
Block a user