Skip to content

Commit

Permalink
add configurable date
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenpieters committed Sep 14, 2023
1 parent b4b94bf commit 9ab1227
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
7 changes: 5 additions & 2 deletions rules_doc_generator/__main__.py
Expand Up @@ -9,9 +9,12 @@

# Parse command line arguments.
parser = ArgumentParser()
parser.add_argument("-a", "--annotated", default=False, help="also generate annotated version with highlights of new parts", action="store_true")
parser.add_argument("-a", "--annotated", default=False, help="Also generate annotated version with highlights of new parts", action="store_true")
parser.add_argument("-y", "--year", default="2023", help="Effective year", action="store")
parser.add_argument("-m", "--month", default="08", help="Effective month", action="store")
parser.add_argument("-d", "--day", default="07", help="Effective day", action="store")
args = parser.parse_args()
config = Config(args.annotated)
config = Config(args.annotated, args.year, args.month, args.day)

print("- Config -")
print("- Annotated: " + str(config.annotated))
Expand Down
31 changes: 30 additions & 1 deletion rules_doc_generator/config.py
@@ -1,8 +1,37 @@
from dataclasses import dataclass

short_month_to_full = {
'XX': 'XX',
'01': 'January',
'02': 'February',
'03': 'March',
'04': 'April',
'05': 'May',
'06': 'June',
'07': 'July',
'08': 'August',
'09': 'September',
'10': 'October',
'11': 'November',
'12': 'December',
}

@dataclass
class Config:
annotated: bool
effective_year: str
effective_month: str
effective_day: str

def not_annotated(self):
return Config(False)
return Config(False, self.effective_year, self.effective_month, self.effective_day)

def version_string(self):
return f'{self.effective_year[2:]}.{self.effective_month}'

def effective_date_str(self):
if not self.effective_month in short_month_to_full:
raise Exception(f'Not a valid month string: {self.effective_month}')
return f'{self.effective_day} {short_month_to_full[self.effective_month]} {self.effective_year}'


2 changes: 1 addition & 1 deletion rules_doc_generator/model/section.py
Expand Up @@ -362,7 +362,7 @@ def to_latex(self, config: Config, id_map: RefDict) -> str:
latex_content = latex_content.replace("%__CHANGELOG_PLACEHOLDER__%", f'\\1 {changelog_content}')

document_content = ''.join(map(lambda x: x.to_latex(config, id_map), self.chapters))
date_content = f'This version of the Comprehensive Rules document is effective \\textbf{{07 August 2023}}.'
date_content = f'This version of the Comprehensive Rules document is effective \\textbf{{{config.effective_date_str()}}}.'
latex_content = latex_content.replace("%__DATE_PLACEHOLDER__%", date_content)
latex_content = latex_content.replace("%__DOCUMENT_PLACEHOLDER__%", document_content)

Expand Down

0 comments on commit 9ab1227

Please sign in to comment.