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 ++++++- requirements.txt | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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 diff --git a/requirements.txt b/requirements.txt index 2f2b486..5e15d40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ bottle markdown +inflection -- cgit v1.2.3