Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wonder why there is no general "template" language that you can use on any text/source file. For example, I'm writing a lot of AutoHotKey code lately, and I find myself wishing I had some of the expressive power of Python so I wouldn't have to repeat things.

I'm seriously considering writing a Python-based "Preprocessor" language which lets me drop in Python code on any file, and deals with transforming it into the final "compiled" file.



> I'm seriously considering writing a Python-based "Preprocessor" language which lets me drop in Python code on any file

You are probably interested in Pyratemp – a simple, well-designed and well-documented template engine that allows arbitrary Python expressions:

http://www.simple-is-better.org/template/pyratemp.html

BTW, I personally use the XSLT template language. It is language independent, but still extendable with user-defined functions written in the programming language of your application. Note that despite its name, XSLT does not only provide for XML output, but handles text output and HTML as well. In Python, you can find a excellent XSLT processor in the 4suite package:

http://4suite.org/docs/CoreManual.xml#xslt_engine

However, the syntax of XSLT is a bit clumsy, so I'll probably switch to XQuery in the future.


I wonder why there is no general "template" language that you can use on any text/source file

Template Toolkit is such a beast: http://template-toolkit.org/

Beyond its normal Perl (and Python) web templating usage I've also used (and abused) TT for:

* All my static websites

* CSS (dynamic and static)

* Pre-process scripts (including Javascript)

* Multi-lingual email

* Creating (end user) configurable data exports (eg. CSV).

* Websurvey language!

* And probably other things I've (hopefully!) forgotten :)

NB. See "ttree" & "tpage" in docs for standalone usage.


I'm late to the game but you should check out 'Cog' by Ned Batchelder.

http://nedbatchelder.com/code/cog/

I used it several years ago with great success.


We're going back to M4 now, but with python?


Thanks for that, never heard of that.

Link for anyone interested: http://en.wikipedia.org/wiki/M4_(computer_language).

By the way, I really think that to work (i.e. become usable, maybe even popular), this needs to be built on an existing and popular language. Otherwise it's too steep a learning curve.

Ideally, I'd like to be able to put in code in the text file wherever I want, be able to put the value of expressions in the code, and that's it.


M4 is not as unpopular as you might think.

It is the base of GNU Autoconf, so everyone who touched a configure.in / configure.ac file did in fact work on M4 code.

(... which is then expanded to a portable shell script also known as the ./configure script.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: