From 894babd9250c02adb5e713d2f54c8ea6af02f3ca Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 23 Mar 2024 19:21:30 +0000 Subject: Use inflection --- model.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'model.py') diff --git a/model.py b/model.py index 3f52115..a69ed99 100644 --- a/model.py +++ b/model.py @@ -2,6 +2,7 @@ import sqlite3 from datetime import datetime import re +import inflection import markdown @@ -40,9 +41,13 @@ class Page(object): def render(self): return markdown.markdown(self.content) + def validate(self): + if self.name != inflection.camelize(self.name): + raise ValueError("Invalid page name, must be CamelCase") + @property def title(self): - pretty = " ".join(re.findall(r"[A-Z](?:[a-z]+|[A-Z]*(?=[A-Z]|$))", self.name)) + pretty = inflection.titleize(self.name) if self.history: pretty = f"{pretty} (history)" return pretty -- cgit v1.2.3