From: Jason D. <ja...@in...> - 2004-08-04 16:05:08
|
Thanks for the comments again! I have a few inline. David Goodger wrote: > [Jason Diamond] > > Below is a surprisingly short module I hacked together that makes it > > possible to create "template" directives. > > I'm wary of adding any direct templating functionality to > Docutils/reStructuredText. I've added a FAQ entry explaining why: > 2.19 of <http://docutils.sf.net/FAQ.html> (some text taken from an old > to-do list entry). I understand your position and agree with it. Let me explain my scenario and maybe you or others can make some suggestions that can steep my on the right path. I'm developing a wiki/blog-like web application using Quixote, Cheetah, and Docutils. (I know there's too many of these types of apps already out there but I'm doing this mainly as an exercise for myself in using all three of these libraries.) Cheetah is used for the core templating. The headers, menus, footers, all the stuff outside the HTML generated by Docutils is generated using Cheetah templates. (An an interesting twist, I'm storing the Cheetah templates as wiki pages (with formatting turned off) so that I can change the look of the site while it's running.) I want the "home" page of the wiki/blog to look like the index page for most blogs where it shows the title of the recent posts, the dates they were posted, and a brief summary. So instead of hard-coding the home page to some chunk of Python code, I decided to make it a page just like every other page. But I want to dynamically generate content on it so I need some sort of recent-changes directive. I could hard-code the Docutils nodes that this directive generates (like I did with my calendar directive--something I'm also using in the wiki/blog) but I thought I might want to customize the look and feel of the home page by changing the home page and without editing any Python code. One advantage to this is that I could create a snapshot of the site as HTML or any other format Docutils supports. Maybe it's unrealistic but I thought it sounded like a fun challenge to try to solve. While I've been typing this up, I think I just thought of another solution: Have the template directives use the Cheetah syntax in their content. Re-join the content passed to the directive as one big string and then use Cheetah to generate reStructuredText. Then use nested_parse to parse that. I *really* like that idea now that it's hit me. And all it took for me to come up with it was to bore the mailing list with a long rant about why I needed templates. :-) > With the latest code you posted (changed call to "template2" to > "template"), it works for me: Sorry about that! > > I'd appreciate any comments about what I'm doing that I shouldn't be > > doing (maybe I'm relying on details that might change in future > > releases--it's hard to tell with Python). > > Python is pretty stable. The Docutils API is more likely to change, > especially the internals. > Oops. I wasn't implying that Python or Docutils was unstable! I was slyly commenting on the fact that Python doesn't use any sort of formal access modifier keywords like public/protected/private. So it's sometimes difficult to know when an attribute is meant to be used by external clients or is considered a private implementation detail that they shouldn't be touching. Generally, if there's an underscore prefix, I think really hard about accessing the attribute directly but not every library follows that convention. -- Jason |