473,545 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A new text templating system for python!

Hi All,

I'm proud to announce that after almost a year's development, the first
public release of Twiddler is available!

Twiddler is a simple but flexible templating system for dynamically
generating textual output.

The key features are:

- No need to learn a templating language.

- As simple as possible while still catering for all possible templating
operations.

- Configurable input parsing so source can be html, xml, plain text or
anything you write an input parser for.

- Configurable output rendering so output can be rendered to a unicode
string, an email, or anything you write an output renderer for.

You can find out more and download from here:

http://www.simplistix.co.uk/software/python/twiddler

If you wish to ask questions, pass judgement or get help, please do so
in the following mailing list:

http://groups.google.com/group/twiddler

This is the first public release, so I'm looking for help with the
following:

- Finding anything that should be possible in a templating system but
isn't with Twiddler

- Packaging it up for easier distribution. I know nothing about eggs,
distutils, etc, and so could do with help to package Twiddler so that
it can be more easily installed.

Finally, here's a couple of quick examples:
>>from twiddler import Twiddler
t = Twiddler('''<bo dy>
.... <div id="title">A title</div>
.... <select name="items">
.... <option id="item">An item</option>
.... </select>
.... </body>''')
>>t['title'].replace('My title')
r = t['item'].repeater()
for i in range(1,4):
.... r.repeat('Item '+str(i),value= i,name=False)
>>print t.render()
<body>
<div id="title">My title</div>
<select name="items">
<option id="item" value="1">Item 1</option>
<option id="item" value="2">Item 2</option>
<option id="item" value="3">Item 3</option>
</select>
</body>
>>from twiddler.input. plaintext import PlainText
t = Twiddler('''To: $to
.... <item>An item</item>
.... ''',input=Plain Text)
>>t['to'].replace('John Smith')
r = t['item'].repeater()
for i in range(1,4):
.... r.repeat('Item '+str(i),value= i,name=False)
>>print t.render()
To: John Smith
Item 1
Item 2
Item 3

Thanks for reading this far, I hope you enjoy it!

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
Dec 16 '06 #1
0 934

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2083
by: Roger Jack | last post by:
I have just finished reading Code Generation In Action which uses Ruby for code generation. I would like to use Python instead. Is Cheetah the best tool to use for templating source code files and then generating code? Is there something more mature or better? Thanks! -- Roger Jack Elegance Technologies, Inc.
31
2047
by: Leif K-Brooks | last post by:
I'm planning to start on a fairly large web application, most likely using mod_python. I recently wrote a fairly small (but real-world useful) web app with it, and all of those req.write()s made for really ugly code. Would a templating engine solve that? Does anyone have any suggestions about which one to use?
3
1427
by: Chris Stiles | last post by:
Hi -- Does anyone have any recommendations for simple web templating systems for python that also allow execution of python code within the the templates themselves ? So far I'm using Albatross, and it's nice, though it would be nicer still if it had proper support for 'code tags' ala <? ?>. --
18
4946
by: pkassianidis | last post by:
Hello everybody, I am in the process of writing my very first web application in Python, and I need a way to generate dynamic HTML pages with data from a database. I have to say I am overwhelmed by the plethora of different frameworks, templating engines, HTML generation tools etc that exist. After some thought I decided to leave the...
13
1380
by: qscomputing | last post by:
Hi, I'm creating a small application in Python that uses lists and dictionaries to create a rudimentary database. I'd like to create some "fill-in-the-blanks" reports from this data, ideally by taking an RTF or plaintext file as a template and replacing placeholder tags with my data. Are there any good pre-written systems that would allow...
6
1173
by: Paolo Pantaleo | last post by:
I am working on this: I have a text file, containig certain section in the form <?py python code here py?> I parse the text file and substitute the python code with its result . It something like php or embedded perl.
7
1610
by: Paul | last post by:
I have been coding apps with PHP for several years. But I am getting more involved in larger and more complicated PHP applications and want to use best practices. I use Eclipse's PHP IDE. I doubt I am using it to its full extent but I want to learn more about, and compare and contrast, frameworks versus IDE versus templating systems and...
5
895
by: Thomas Troeger | last post by:
Dear all, I've written a program that parses a string or file for embedded python commands, executes them and fills in the returned value. The input might look like this: process id: $$return os.getpid()$$ current date: $$return time.ctime()$$ superuser: $$ if os.geteuid():
10
1696
by: Terrence Brannon | last post by:
Hello, The most common way of dynamically producing HTML is via template engines like genshi, cheetah, makotemplates, etc. These engines are 'inline' --- they intersperse programming constructs with the HTML document itself. An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by...
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7923
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.