htmltmpl-support Mailing List for htmltmpl - templating engine (Page 4)
Brought to you by:
jakubvrana,
tripiecz
You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
|
Dec
(1) |
| 2004 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
(2) |
Jul
(1) |
Aug
(1) |
Sep
(2) |
Oct
|
Nov
(2) |
Dec
|
| 2005 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2007 |
Jan
(2) |
Feb
(1) |
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
(2) |
Apr
(6) |
May
|
Jun
(1) |
Jul
(2) |
Aug
(1) |
Sep
(8) |
Oct
(10) |
Nov
(1) |
Dec
(28) |
| 2009 |
Jan
(3) |
Feb
(15) |
Mar
(15) |
Apr
(21) |
May
(43) |
Jun
(18) |
Jul
(35) |
Aug
(4) |
Sep
(2) |
Oct
|
Nov
|
Dec
(14) |
| 2010 |
Jan
(8) |
Feb
(2) |
Mar
(4) |
Apr
|
May
(3) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(4) |
Jul
|
Aug
(2) |
Sep
(2) |
Oct
(1) |
Nov
|
Dec
|
| 2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
(1) |
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: anders p. <an...@co...> - 2004-05-10 22:08:07
|
On 2004-05-05 13:04:36 +0200, Daniel Lichtenberger wrote: > Hi, >=20 > I'm using htmltmpl in a medium-sized web site and I'm delighted with its = ease=20 > of use and flexibility. This is a trivial patch against htmltmpl-1.22 tha= t=20 > greatly helps htmltmpl's performance on pages with very long and/or neste= d=20 > loops (e.g. a table containing hundreds of rows).=20 awesome. it seems to work well. i've merged the patch with my own (see: http://sourceforge.net/mailarchive/forum.php?thread_id=3D3877432&forum_id= =3D8741) http://thraxil.org/code/htmltmpl/combined.patch and a copy of the code pre-patched:=20 http://thraxil.org/code/htmltmpl/htmltmpl.tar.gz --=20 anders pearson : http://www.columbia.edu/~anders/ C C N M T L : http://www.ccnmtl.columbia.edu/ weblog : http://thraxil.org/ |
|
From: Daniel L. <dan...@gm...> - 2004-05-05 11:05:10
|
Hi,
I'm using htmltmpl in a medium-sized web site and I'm delighted with its ease
of use and flexibility. This is a trivial patch against htmltmpl-1.22 that
greatly helps htmltmpl's performance on pages with very long and/or nested
loops (e.g. a table containing hundreds of rows). Those pages tend to spend a
lot of time in htmltmpl's function "process" where the individual tokens are
analyzed and concatenated. It's the string concatenation that detracts from
htmltmpl's performance: it uses a single output string (out) and simply
appends to it every time a new token is processed. This is fine for smaller
pages, but doing string concatenation 1000s of times is inefficient because
Python strings are immutable, so each "out += something" actually creates a
new string, thus killing performance. A more efficient possibility is to
store all tokens in a list, then join the list using string.join. This way
the string is created only once. I saw performance go up by 50-70% on pages
spending most time in TemplateProcessor.process with no problems until now
(the test suite is passed, too).
Here's the diff:
diff -u htmltmpl-1.22/htmltmpl.py htmltmpl/htmltmpl.py
--- htmltmpl-1.22/htmltmpl.py 2001-12-15 23:11:28.000000000 +0100
+++ htmltmpl/htmltmpl.py 2004-05-05 12:57:25.000000000 +0200
@@ -574,7 +574,7 @@
tokens = template.tokens()
len_tokens = len(tokens)
- out = "" # buffer for processed output
+ out = [] # buffer for processed output
# Recover position at which we ended after processing of last part.
i = self._current_pos
@@ -605,7 +605,7 @@
if DISABLE_OUTPUT not in output_control:
value = str(self.find_value(var, loop_name,
loop_pass,
loop_total, globalp))
- out += self.escape(value, escape)
+ out += [self.escape(value, escape)]
self.DEB("VAR: " + str(var))
elif token == "<TMPL_LOOP":
@@ -731,21 +731,21 @@
# when it was not replaced by the parser.
skip_params = 1
filename = tokens[i + PARAM_NAME]
- out += """
+ out += ["""
<br />
<p>
<strong>HTMLTMPL WARNING:</strong><br />
Cannot include template: <strong>%s</strong>
</p>
<br />
- """ % filename
+ """ % filename]
self.DEB("CANNOT INCLUDE WARNING")
elif token == "<TMPL_GETTEXT":
skip_params = 1
if DISABLE_OUTPUT not in output_control:
text = tokens[i + PARAM_GETTEXT_STRING]
- out += gettext.gettext(text)
+ out += [gettext.gettext(text)]
self.DEB("GETTEXT: " + text)
else:
@@ -756,7 +756,7 @@
# Raw textual template data.
# If output of current block is not disabled, then
# append template data to the output buffer.
- out += token
+ out += [token]
i += 1
# end of the big while loop
@@ -764,7 +764,7 @@
# Check whether all opening statements were closed.
if loop_name: raise TemplateError, "Missing </TMPL_LOOP>."
if output_control: raise TemplateError, "Missing </TMPL_IF> or
</TMPL_UNLESS>"
- return out
+ return "".join(out)
Take care,
Daniel
|
|
From: Richard F. <bl...@fe...> - 2004-02-24 01:29:27
|
All, I started using the blog aggregator planeplanet scripts a few days ago that take advantage of your htmltmpl scripts. I made some additions and thought you guys might like them too. I needed some extended IF functionality so I added a new tag <TMPL_IF_MATCH>. It allows you to do regular expression searching on the value of the variable. here is an example <TMPL_IF_MATCH title REGEX=3D"^Planet.*"> .. </TMPL_IF_MATCH> I also had to modify the tokenizer expression to allow the pass through of the regular expression special characters. -- Richard Ferguson |
|
From: anders p. <an...@co...> - 2004-01-27 20:22:49
|
attached is a patch for html-tmpl-1.22 python library that has a few
improvements:
- tags are case insensitive, so you can do <TMPL_VAR> or <tmpl_var>,
etc.
- it handles linebreaks within tags, so <tmpl_var
name="foo"> is valid.
- you can specify an include directory other than "inc" by passing
an include_dir param to TemplateManager's constructor.
- a set_dict() method that allows you to set multiple template
variables at once
it still passes all the unit tests, and i've been using it on production
apps for a while now, so it should be pretty safe.
--
anders pearson : http://www.columbia.edu/~anders/
C C N M T L : http://www.ccnmtl.columbia.edu/
weblog : http://thraxil.org/
|
|
From: Johan S. <jo...@sv...> - 2004-01-15 11:43:00
|
* Jan 15 04:55 anders pearson <an...@co...>:
[...]
> python's built in 'print' always adds a newline to the end. is that
> what you're talking about?
Yeah, I first didn't realize that the template proccess already added a
'\n' at the end.
sys.stdout.write(tp.process(tm))
Solves it ofcourse.
--
Johan Svedberg, jo...@sv..., http://johan.svedberg.pp.se/
|
|
From: Johan S. <jo...@sv...> - 2003-12-23 14:19:27
|
Hi!
First of all, thanks for making htmltmpl, it's great!
Now to the subject. I've written a small thingie in Python were my
template looks like this:
<p><a href="<TMPL_VAR channel_link>"><TMPL_VAR channel_title></a></p>
<ul>
<TMPL_LOOP Items>
<li><a href="<TMPL_VAR link>"><TMPL_VAR title></a></li>
</TMPL_LOOP>
</ul>
When I print the proccessed template like this:
print tp.process(tm)
The result comes out just fine, however, there is a mysterious trailing
empty line (which isn't in the template file) that's also printed.
Although the empty line goes away when I instead write the output to a
file with the following code:
def write_template(self, output):
try:
f = open(output, "w")
try:
f.write(tp.process(tm))
finally:
f.close()
except Exception, e:
sys.exit(e)
Does someone know what's going on here?
PS. Please Cc me since I'm not subscribed, thanks.
--
Johan Svedberg, jo...@sv..., http://johan.svedberg.pp.se/
|
|
From: Wayne W. <ww...@br...> - 2003-09-29 15:29:40
|
While die_on_bad_params is sometimes useful but mostly I turn it off, I'd really like the opposite. I want to be told when I fail to populate a tmpl_var or tmpl_loop. Does something like this exist? If not, are there objections to adding it? I think it could be a unpopulated() method, that you may call just before output() to see if something is missing. Comments? -- Wayne Walker www.broadq.com :) Bringing digital video and audio to the living room |
|
From: <pet...@bi...> - 2003-09-19 19:59:24
|
Hi All A tips when making the template dont forget that you need minimum one newline before the <HTML> so that the webserver can distinguish between header and html. I didnt, and It took me a while to figure it out. Maybe = a note in the docs at the sourceforge site as well ? Also big thanks to You Tomas for doing this great python implementation. I was very happy when I found it. //Peter bitrunner Andra L=E5nggatan 28 41327 G=F6teborg 0708-460260 www.bitrunner.com |
|
From: Wayne W. <ww...@br...> - 2003-09-15 07:13:32
|
I would like to see a list of unpopulated parameters from a template. This is quite the opposite of die_on_bad_params(). I guess I want warn_on_unset_params(). Any easy way to do this? I tried searching but apparently didn't use the right words... -- Wayne Walker www.broadq.com :) Bringing digital video and audio to the living room |
|
From: Wayne W. <ww...@br...> - 2003-09-10 13:50:25
|
I just wrote myself into a corner.
I am writing an application w/ HTML::Template and Class::DBI.
I just got to the first "populate the template" method. I need an array
of hashrefs. I like the clean accessors that Class::DBI gives me,
but really don't want to do something like (incomplete, but you get the
picture):
@Users = Foo::DBI::Users->retrieve_all();
@good_for_template =
map { $_, $Users->$_ }
map {$_->{column_name} } Foo::DBI::Users->columns();
Any then accessing columns in an object pulled in via has_a() further
complicates this.
Recommendations?
--
Wayne Walker
www.broadq.com :) Bringing digital video and audio to the living room
|
|
From: anders p. <an...@co...> - 2003-05-06 22:13:28
|
i've been programming in Perl for years and have recently been doing more and more work in python. as a Perl programmer, i'm totally hooked on HTML::Template. so when i started coding more and more python, i considered just writing a python copy of the module. first, i decided to do a quick google search on the off chance that someone else out there was of a similar mind. obviously i wasn't alone! Tomas Styblo has saved me quite a bit of time. thank you. anyway, i have a lot of existing applications that were built with Perl and HTML::Template that i would like to integrate with or totally replace with python. i'd rather not have to spend much time re-writing template files (and documentation that uses the perl syntax), so i'm very interested in getting htmltmpl.py to accept *exactly* the same syntax as the perl version. specifically:=20 - case insensitivity. i find it much easier to type lowercase so all of my template files are written like <tmpl_var name=3D"foo"> rather than <TMPL_VAR NAME=3D"foo">.=20 - allow lowercase names for loop variables. eg, <tmpl_loop name=3D"foo">=20 should be legal.=20 - allow linebreaks inside tags. <tmpl_var name=3D"foo"> should be parsed the same as <tmpl_var name=3D"foo"> i did a bit of quick hacking and wrote a patch that handles the first two. i'll probably start on the third sometime next week, but it's not as high priority for me. the patch is available at:=20 http://thraxil.org/htmltmpl/html-tmpl-2003-05-06_01.patch.gz in addition to case insensitivity and allowing lowercase names for loop variables, it also adds a very simple set_dict() method to TemplateProcessor and eliminates the exception that is raised if save_precompiled() can't write to the template directory, instead just silently returning (essentially making precompile just automatically turn off instead of raising errors). set_dict() lets you do something like:=20 tproc.set_dict(some_function_that_returns_a_dict()) instead of=20 dict =3D some_function_that_returns_a_dict() for key in dict: tproc.set(key,dict[key]) now some questions:=20 1) is htmltmpl.py even being maintained? on the sourceforge page i don't see any changes since 2001. 2) what was the reasoning behind making loop names start with a capital letter?=20 3) is anyone else doing similar work on making htmltmpl.py more compatible with HTML::Template templates? again, thanks for writing htmltmpl, Tomas.=20 --=20 anders pearson : http://www.columbia.edu/~anders/ C C N M T L : http://www.ccnmtl.columbia.edu/ weblog : http://thraxil.org/ |
|
From: Chris B. <ch...@ty...> - 2003-02-03 22:46:13
|
Hey everyone, New to the list here. I've been using the Perl HTML::Template for several years and I was overjoyed to find a PHP version since I'm doing a lot of PHP development for my current employer. I have a question though regarding the ability to get parameter names. In the Perl version you can do $template->query() and get a list of the token names in the template. Or $template->query(name=>'foo') and get the type of token it is (i.e. LOOP, VAR etc.). I've been digging through the docs of this version and I haven't been able to find something similar. Is there an undocumented way I could do this? BTW what I'm trying to do is give a person the ability to assign a template token name to different pieces of code without actually editing the template itself. So say I have <TMPL_VAR foo>, I want an admin area that I can tell 'foo' to point to a certain bit of text in the database, or a bit of code that needs to be executed, etc. ... all without changing the template file itself. I know it seems a bit backwards so if someone has a better idea on how to accomplish something like that I'm open to suggestions. Thanks in advance, Chris -- Chris Brown Web Application Developer Ballistic Web Design http://ballisticwebdesign.com/ 903-533-8666 |
|
From: Andreas M. <a.m...@pe...> - 2002-04-16 20:43:42
|
Hello !
I just tried to use the htmltmpl package for Python. I wrote a small
test cgi:
--------------------------------------
#!C:\Programme\Python\Python.exe
import cgi
import cgitb; cgitb.enable()
from htmltmpl import TemplateManager, TemplateProcessor
# Compile or load already precompiled template.
template = TemplateManager().prepare("template.htm")
tproc = TemplateProcessor()
# Set the title.
tproc.set("title", "Login")
print "Content-Type: text/html\n\n"
print tproc.process(template)
--------------------------------------
But I only get this error message in my browser:
IOError Python 2.2: C:\Programme\Python\Python.exe
Tue Apr 16 22:35:03 2002
A problem occurred in a Python script. Here is the sequence of function
calls leading up to the error, in the order they occurred.
C:\apache\cgi-bin\test.py
8
9 # Compile or load already precompiled template.
10 template = TemplateManager(precompile=1).prepare("template.htm")
11 tproc = TemplateProcessor()
12
template = <function template at 0x00A38058>, TemplateManager = <class
htmltmpl.TemplateManager at 0x00A46FD8>, precompile undefined
C:\Programme\Python\lib\site-packages\htmltmpl.py in
prepare(self=<htmltmpl.TemplateManager instance at 0x00A4D160>,
file='template.htm')
202 if self.is_precompiled(file):
203 try:
204 precompiled = self.load_precompiled(file)
205 except PrecompiledError, template:
206 print >> sys.stderr, "Htmltmpl: bad
precompiled "\
precompiled undefined, self = <htmltmpl.TemplateManager instance at
0x00A4D160>, self.load_precompiled = <bound method
TemplateManager.load_precompiled of <htmltmpl.TemplateManager instance
at 0x00A4D160>>, file = 'template.htm'
C:\Programme\Python\lib\site-packages\htmltmpl.py in
load_precompiled(self=<htmltmpl.TemplateManager instance at 0x00A4D160>,
file=<open file 'template.htmc', mode 'rb' at 0x00A5A238>)
339 finally:
340 if file:
341 self.lock_file(file, LOCK_UN)
342 file.close()
343 if remove_bad and os.path.isfile(filename):
self = <htmltmpl.TemplateManager instance at 0x00A4D160>, self.lock_file
= <bound method TemplateManager.lock_file of <htmltmpl.TemplateManager
instance at 0x00A4D160>>, file = <open file 'template.htmc', mode 'rb'
at 0x00A5A238>, global LOCK_UN = 3
C:\Programme\Python\lib\site-packages\htmltmpl.py in
lock_file(self=<htmltmpl.TemplateManager instance at 0x00A4D160>,
file=<open file 'template.htmc', mode 'rb' at 0x00A5A238>, lock=3)
282 msvcrt.locking(fd, msvcrt.LK_LOCK, 1)
283 elif lock == LOCK_UN:
284 msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
285 else:
286 raise TemplateError, "BUG: bad lock in lock_file"
global msvcrt = <module 'msvcrt' (built-in)>, msvcrt.locking = <built-in
function locking>, fd = 3, msvcrt.LK_UNLCK = 0
IOError: [Errno 13] Permission denied
__doc__ = 'I/O operation failed.'
__getitem__ = <bound method IOError.__getitem__ of
<exceptions.IOError instance at 0x00A4A5E0>>
__init__ = <bound method IOError.__init__ of <exceptions.IOError
instance at 0x00A4A5E0>>
__module__ = 'exceptions'
__str__ = <bound method IOError.__str__ of <exceptions.IOError
instance at 0x00A4A5E0>>
args = (13, 'Permission denied')
errno = 13
filename = None
strerror = 'Permission denied'
--------------------------------------
When I run the skript in a shell then I receive the correct html text.
I use Apache under Windows XP, my httpd.conf looks like this:
ScriptAlias /cgi-bin/ "/apache/cgi-bin/"
#
# "c:/apache/cgi-bin" should be changed to whatever your
ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/apache/cgi-bin/">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
If I disable the precompiling (template =
TemplateManager(precompile=0).prepare("template.htm") ) then I have no
problems.
Sorry if this is a ridiculous question but I'm not very familiar with
configuring apache and writing cgi scripts.
Thank you
Andreas Martin
|