[Zope3-dev] Need help planning Zope X3 1.0

Shane Hathaway shane at zope.com
Mon Feb 9 14:15:30 EST 2004


On Mon, 9 Feb 2004, Casey Duncan wrote:

> To me this sort of thing is like inline styles in HTML. Do I ever use
> inline styles? Yes I do, but very rarely and (hopefully) only when there
> is no other effective way to do what I want with the stylesheet (perhaps
> too dynamic), or I just plain can't change the stylesheet (or the
> document <head></head>). Do I feel a little dirty when I decide to use
> them? Yes. Sometimes I use them temporarily just to sketch something,
> knowing that I will create a stylesheet and do it the "right way" later.

Inline code is attractive because it lets you accomplish a task without
switching context.  Inline code is unmanageable, however, because it
allows you to specify arbitrary complexity in an anonymous code block.  
In general, complex things need a name in order to be manageable.

A possible compromise is to make it easy to move inline code to a Python
module.  In fact, maybe moving inline code to a module could be automated.  
That way, you might not even have to feel dirty when you write inline
code.

Further, one way to make inline code portable is to treat inline code as a
module, rather than as a collection of anonymous code blocks.  For
example:

<html>
<head><title>Shane's Example</title>
<script type="text/server-python">
import time
def showtime():
    return time.asctime()
</script>
</head>
<body>
Date and time: <span tal:content="code/showtime">(time)</span>.
</body>
</html>

An automated procedure could move that snippet to a library called
"shanesexample" and transform the script tag to:

<script type="text/server-python" src="library/shanesexample" />

The module "shanesexample" would be obvious:

import time
def showtime():
    return time.asctime()


Another way to make the snippets portable, though messier, is to require
that all scripts have a name.  For example:

<body>
Date and time: 
<script type="text/server-python" name="showtime">
import time
print time.asctime()
</script>.
</body>

This is much less portable because the module representation would have to
munge the code.  The converted code would have to be indented, 
and somehow it has to collect the output of print statements and 
return the results:

def showtime():
    import time
    print time.asctime()
    return print_collector()  # Yuck

That's similar to the transformation Zope 2 does to Python scripts.

Shane



More information about the Zope3-dev mailing list