wiki:ExtendingQuickstart
Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 4 (modified by anonymous, 9 years ago) (diff)

spelling

With TurboGears 0.9 (or svn rev 106) quickstart now uses PasteScript and therefor supports user templates.

Why?

Why would you want to do this? Well, if you have your own conventions for applications, this is a way to add those to new TurboGears projects -- documentation templates, testing frameworks, whatever.

Also, if you already have a project started, you can apply run quickstart on it again (perhaps with your new template!) and see how the current project differs, and maybe apply some of the changes.

How?

So let's go ahead and create our own template!

Let's say that you have a default.css file that you always include in your webapp.

Let's start creating some files and dirs.

mytemplate/ mytemplate/setup.py mytemplate/mytemplate/init.py mytemplate/mytemplate/template/+package+/static/css/default.css

First we will edit the setup.py

from setuptools import setup, find_packages
from turbogears import finddata

setup(name='mytemplate',
      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
      zip_safe=False,
      package_data=finddata.find_package_data(),
      entry_points="""
          [paste.paster_create_template]
              mytemplate = mytemplate:MyTemplate
        """
      )

This setup basically tells pastescript that there is an template called mytemplate and its class is MyTemplate? in the mytemplate module

Now let's edit init.py

from paste.script import templates
import pkg_resources

class MyTemplate(templates.Template):

    egg_plugins = ['MyTemplate']
    _template_dir = pkg_resources.resource_filename("mytemplate", "template")
    summary = "my own cute template"

Now all you have to do is add anything to the template dir.

Now you can run tg-admin quickstart -t mytemplate and there should be a default.css file in your static/css/ dir!

See  http://pythonpaste.org/script/developer.html#templates for more info

/elvelind grandin