2005-07-21

Subterranean exploration, part 1

Join me as I journey into the underground so that I may mine a shiny red gem from the depths of the Subway project.

Looking around, something sparkly has caught my eye. What could it be? Why it's ( *rolls dice* ) docstring view templates using the @subway.method_view decorator!

This jewel of a feature allows us to use the docstrings from the methods in our controllers as our view templates. Here's a simple example which shows this treasure off a bit:

    
@subway.method_view
def echo(word="subway", count=3):
"""
<html><body>
#for $echo in $echoes
<p>$echo</p>
#end for
</body></html>
"""
echoes = [word] * int(count)
return echo.view()

Doesn't this seem like a quick and easy way to get a view written? Yes, I think that's the case. However, be warned that it doesn't support all the features that a real view provides. For example, the #extends feature from Cheetah isn't supported, while it is supported by a regular view.

Tune in next time for...something else!

Technorati Tags: ,

No comments: