Skip to content

Add compiler setting titleCaseClassNames - #74

Open
hilman2 wants to merge 2 commits into
CheetahTemplate3:masterfrom
hilman2:title-case-class-names
Open

Add compiler setting titleCaseClassNames#74
hilman2 wants to merge 2 commits into
CheetahTemplate3:masterfrom
hilman2:title-case-class-names

Conversation

@hilman2

@hilman2 hilman2 commented Aug 26, 2026

Copy link
Copy Markdown

Closes #67.

With the setting on, my_template.tmpl compiles to class MyTemplate, and #extends my_base does from my_base import MyBase. The name in #extends stays the module name. A name that is already in title case comes through unchanged, so Cheetah.Templates.SkeletonPage.SkeletonPage still imports SkeletonPage, and a class imported explicitly is not touched.

Template.compile() and loadTemplateClass() ask the compiler for the class name it used instead of assuming it equals the module name. A compilerClass of one's own does not have to implement the new method.

The setting is read once, before parsing, so a #compiler-settings directive does not reach it. Reading it live would rename the base class in the #extends import but not the class of the template itself. --settings, compilerSettings= and _CHEETAH_compilerSettings all work, and the docs say so.

Default is off.

21 new tests in Cheetah/Tests/ClassNames.py, among them one that compiles a base and a derived template and renders it, and one for loadTemplateClass. Full suite passes on 2.7, 3.6 and 3.12, flake8 clean, docs build clean.

@hilman2
hilman2 force-pushed the title-case-class-names branch from 44e8cca to 9c1a3ab Compare August 26, 2026 16:04
manuelhilgert and others added 2 commits August 26, 2026 18:20
The class name of a compiled template is its module name, so
my_template.tmpl defines the class my_template. With the setting
turned on it defines MyTemplate.

The implicit import of #extends follows the setting: `#extends
my_base` does `from my_base import MyBase`. The name in the directive
is still the module name. A name that is already in title case comes
through unchanged, so `Cheetah.Templates.SkeletonPage.SkeletonPage`
still imports SkeletonPage, and a class imported explicitly is left
alone.

Template.compile() and loadTemplateClass() now ask for the class name
the compiler used instead of assuming it equals the module name. A
compilerClass of one's own need not implement the new method.

A name that would turn into a Python keyword gets a trailing
underscore, since class None(Template) is a syntax error.

The setting is read once, before parsing, so a #compiler-settings
directive has no effect on it. Reading it live would rename the base
class in the #extends import but not the class of the template itself.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@hilman2
hilman2 force-pushed the title-case-class-names branch from 9c1a3ab to 4b66157 Compare August 26, 2026 16:20
@phdru

phdru commented Aug 29, 2026

Copy link
Copy Markdown
Member

Hello! Thank you for the hard work on Cheetah! Unfortunately I have personal problems that prevent me to look deeper. I'm preparing for eye surgery. I hope to recover in October. Will be back when I will have better eyesight.

@hilman2

hilman2 commented Aug 29, 2026 via email

Copy link
Copy Markdown
Author

@phdru

phdru commented Aug 30, 2026

Copy link
Copy Markdown
Member

Hello Oleg, thank you for the update and for all your work on Cheetah. I’m sorry to hear you are going through personal health challenges, and I hope the eye surgery goes smoothly and that your recovery in October is steady and comfortable. Wishing you all the best during this time.

Thank you very much!

In the meantime, would they prefer that I take over any responsibilities related to this PR, or should I simply wait until you are back and able to review things again?

There're not much of "they" left in the project. I'm afraid I'm the only reviewer here.

Manuel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Having a more standard class name from pre-compiled template

3 participants