Skip to main content

Simple object-based string templating in python

Project description

Simplate

Python Simple Object-Based String Templating

##Usage From formatted strings create re-usable template objects and implementation objects. The Simplate class (Simplate.Simplate) allows you to dynamically create new Template classes with the string you initialize with, and (optionally) a title for the template which becomes the name of your new class.

import Simplate

mySimpleTemplate = Simplate.Simplate( "Hello {friend} how's your {pet}?", title="FriendlyLetter" )
print mySimpleTemplate.ImplementationClass
<class 'Simplate.Simplate.FriendlyLetter'>
newLetterToJohn = mySimpleTemplate.implement()
type(newLetterToJohn)
<class 'Simplate.Simplate.FriendlyLetter'>
newLetterToJohn.friend = "John"
newLetterToJohn.pet = "cute puppy"
str(newLetterToJohn)
"Hello John how's your cute puppy?"

Every call to Simplate.implement() will return a new instance of the dynamically-created template class, and the parameters on the template string become the instance variables on the new instances of this new template class, while the template itself is a shared class variable amongst all instances of this template.

An optional third argument when initializing a Simplate is "defaults", which is what the default values are for the instance variables of the template object. By default, defaults is an empty string.

##Examples

import Simplate
emailString = "Dear {name}, thank you for your {item}, unfortunately its sold, sincerely {author}."
emailTemplate = Simplate.Simplate(emailString, "EmailToCustomer")
emailToBob = emailTemplate.implement()
emailToBob.author = "Kyle Kimery"
emailToBob.name = "Bob"
emailToBob.item = "Baseball Merchandise"
print emailToBob
Dear Bob, thank you for your inquiry regarding Weaboo Merchandise, I regret to inform you that it's gone, sincerely Kyle Kimery.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Simplate-1.0.0.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Simplate-1.0.0-py2-none-any.whl (3.5 kB view details)

Uploaded Python 2

File details

Details for the file Simplate-1.0.0.tar.gz.

File metadata

  • Download URL: Simplate-1.0.0.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.16

File hashes

Hashes for Simplate-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f6ed4d9148647a62f369d0e2c2d043b2fcf6c98c924db4e2d59607c76cb0d06c
MD5 cf6939a27b0b1f5c6ec5355922970df3
BLAKE2b-256 fc2dc1628fdb9b7179720a706a7f4dd9e19c0bdd0d2c96887a33aeac4f21fe53

See more details on using hashes here.

File details

Details for the file Simplate-1.0.0-py2-none-any.whl.

File metadata

  • Download URL: Simplate-1.0.0-py2-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.16

File hashes

Hashes for Simplate-1.0.0-py2-none-any.whl
Algorithm Hash digest
SHA256 c6bd9fcb9ecd39b008c7f05d7ab3c4d98ab24a781b645ae8611cbbee96bfb5d2
MD5 db5623050569f488049437835df9f71b
BLAKE2b-256 655e6d7d66c1bc05f9a63f83bf5223e8382face42e192de42046a854caf0f2ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page