Now that I have Textile support integrated into Zope 3 for my application, I decided to add support for different source types to said application. This didn't really require much on top of the previous work. First, I added a new field to the IPost interface and a new default class attribute to the Post implementation for the Post's "description_type". On the interface, I added the field as a Choice stemming from the "SourceTypes" vocabulary:
description_type = zope.schema.Choice( title=u"Description Format", description=u"Type of the description text.", default="textism.textile", required=True, vocabulary="SourceTypes", )
Then I updated the 'renderDescription' method of the PostView class to get the description type from the adapted object and use that to get the renderer. Now the method looks like this:
def renderDescription(self): """Renders the description from textile source.""" description = self.context.description description_type = self.context.description_type source = zapi.createObject(description_type, description) view = zapi.getMultiAdapter((source, self.request)) return view.render()
Notice another one of those types - "Source Code". I created that type for my code snippet content, with a renderer that wraps up text in HTML 'pre' tags and quotes some common trouble entities (angle brackets, ampersands).