Generate

Introduction

The Generate Extension includes the Generate controller, and provides a mechanism for generating common content from template directories. An example use case would be the ability for application developers to easily generate new plugins for their application… similar in other applications such as Chef Software’s chef generate cookbook type utilities.

The Cement Developer Tools use this extension to generate projects, plugins, extensions, scripts, etc for developers building their applications on the framework.

Documentation References:

API References:

Requirements

Cement 3.0.8+:

pip install cement[generate]

Applications using Cement <3.0.8 should continue to include pyYaml in their dependencies.

Configuration

Application Configuration Settings

This extension honors the following settings under the primary namespace (ex: [myapp]) of the application configuration:

Application Meta Options

This extension honors the following App.Meta options:

Usage

Examples

from cement import App

class MyApp(App):
    class Meta:
        label = 'myapp'
        extensions = ['generate', 'jinja2']
        template_handler = 'jinja2'


with MyApp() as app:
    app.run()

Generate Templates

The Generate Extension looks for a generate sub-directory in all defined template directory paths defined at the application level. If it finds a generate directory it treats all items within that directory as a generate template.

A Generate Template requires a single configuration YAML file called .generate.yml that looks something like:

---
ignore:
    - "^(.*)ignore-this(.*)$"
    - "^(.*)ignore-that(.*)$"

exclude:
    - "^(.*)exclude-this(.*)$"
    - "^(.*)exclude-that(.*)$"

variables:
    - name: 'my_variable_name'
      prompt: 'The Prompt Displayed to The User'

Generate Template Configuration

The following configurations are supported in a generate template’s config:

Last updated