Flourish API: flourish.generators
The generators in Flourish are responsible for turning one or more source objects into output HTML.
Subclassing the generators
If you need to alter the way a page or pages are being generated, it should normally be possible to subclass one of the default generators and modify only a small part of it.
The included generators
BaseGenerator— the base class of all Flourish generatorsSourceGenerator— the class for generating individual source pagesIndexGenerator— the class for generating lists of source pagesPaginatedIndexGenerator— the class for generating paginated lists of source pagesAtomGenerator— the class for generating an Atom feedSassGenerator— the class for generating CSS files from SASS-formatted sourcesCalendarGenerator— classes for generating date-based indexes
The included mixins
PageContextMixin
Adds the first of self.source_objects to the template context as page as
well as all key values from that object. For example, a TOML source of:
title = 'About this site'
tag = ['about', 'information']
noindex = true
would make all of {{page}}, {{title}}, {{tags}}, and {{noindex}}
values available for use in templates.
PageIndexContextMixin
Adds the list of source objects to the template context as pages.
Stopping generation
Sometimes you may want to not generate a page (for example, due to a lack of
content). To do this, raise DoNotGenerate and the generator will skip that
page without it counting as an error.
def get_objects(self, tokens):
sources = self.get_filtered_sources().filter(**tokens)
if sources.count() == 0:
raise self.DoNotGenerate