Skip to content

ebrehault/superformatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

The world's simplest Python template engine

Implements a very basic template engine based on the standard Python formatting feature.

Disclaimer

The objective is mostly to have fun with Python and demonstrate what the standard Formatter class is able to do.

If you have any funny idea to improve the current implementation (remember: we want to keep it short), pull requests are welcome :).

Usage

>>> sf = SuperFormatter()

It does everything the regular format() method does (and that's already a lot, see https://pyformat.info/)

But it also ca:

  • call methods:
>>> sf.format('My name is {name.upper:call}', name="eric")
'My name is ERIC'
  • make loops:
>>> sf = SuperFormatter()
>>> sf.format('''Table of contents:
... {chapters:repeat:Chapter {{item}}
... }''', chapters=["I", "II", "III", "IV"])
'''Table of contents:
Chapter I
Chapter II
Chapter III
Chapter IV
'''
  • manage conditions:
>>> sf = SuperFormatter()
>>> sf.format('Action: Back / Logout {manager:if:/ Delete {id}}', manager=True, id=34)
'Action: Back / Logout / Delete 34'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages