Content Generators in Tapestry are classes that take an input template file and output a number of generated files. Content Generators are loaded by a template file via its Front Matter. For example:
generator: - PaginationGenerator
In cases where multiple generators are attached to a File, they are then executed in the order that they are set within the Front Matter. The output of the first generator will then be used as the input to the next. This is useful for paginating taxonomy archives.
The Collection Item Generator was written as part of making Tapestry blog aware. By design it is supposed to be used with a Content Type's template to allow a blog post page to know which post came before and after it.
It is added to a template via the following Front Matter:
generator: - CollectionItemGenerator
When executed it will identify a files previous and next sibling within the files Content Type and assign to the file an instance of the Paginator class to the variable
By default unless explicitly declared via filename or Front Matter methods a File in tapestry will have its date property set to the last edit time of that source file.
This means that only Collections containing files that have had their date's set via either the filename or front matter methods will have deterministic ordering of their items. For example the Collection associated with the blog Content Type.
The Taxonomy Archive Generator expects to be invoked on a page that has requested a Content Types taxonomy Collection. For example:
use: - blog_categories generator: - TaxonomyArchiveGenerator
It will generate one File for each taxonomy classification found and inject into it the classifications name set to the variable
$taxonomyName and an array of ViewFiles for the Files found within that classification.
Once the generated files have been through the Compile task the following output file structure will be generated:
source/ └── a-folder/ └── categories.phtml build_local/ └── a-folder/ ├── fish/ | └── index.html ├── mammals/ | └── index.html ├── birds/ | └── index.html └── insects/ └── index.html
The Pagination Generator is the only Generator to ship with Tapestry that also requires configuration. It operates upon a collection that the input file has requested and also requires to be told which collection and how many items per page via Front Matter settings. For example:
use: - blog_categories generator: - TaxonomyArchiveGenerator - PaginationGenerator pagination: provider: blog_categories perPage: 3
The pagination generator is configured via the pagination Front Matter key, defining the collection to be worked on via
provider and items per page via
In the case of the above example once the generated file have been through the Compile task, the following output file structure will be generated:
source/ └── a-folder/ └── categories.phtml build_local/ └── blog/ ├── fish/ | ├── 3.html | ├── 2.html | └── index.html ├── mammals/ | └── index.html ├── birds/ | ├── 2.html | └── index.html └── insects/ ├── 4.html ├── 3.html ├── 2.html └── index.html