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

Changes between Version 8 and Version 9 of ExtendingQuickstart


Ignore:
Timestamp:
06/24/07 18:34:00 (12 years ago)
Author:
Chris Arndt
Comment:

migration notice

Legend:

Unmodified
Added
Removed
Modified
  • ExtendingQuickstart

    v8 v9  
    1 With TurboGears 0.9 (or svn rev 106) quickstart now uses PasteScript and therefore supports user templates. 
    2  
    3 == Why? == 
    4  
    5 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.   
    6  
    7 Also, if you already have a project started, you can run quickstart on it again (perhaps with your new template!) and see how the current project differs, and maybe apply some of the changes. 
    8  
    9 == How? == 
    10  
    11 So let's go ahead and create our own template! 
    12  
    13 Let's say that you have a default.css file that you always include in your webapp. 
    14  
    15 Let's start creating some files and dirs. 
    16  
    17     mytemplate/ 
    18  
    19     mytemplate/setup.py 
    20  
    21     mytemplate/mytemplate/__init__.py 
    22  
    23     mytemplate/mytemplate/template/+package+/static/css/default.css 
    24  
    25 First we will edit the setup.py 
    261{{{ 
    27 #!python 
    28 from setuptools import setup, find_packages 
    29 from turbogears import finddata 
    30  
    31 setup(name='mytemplate', 
    32       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), 
    33       zip_safe=False, 
    34       package_data=finddata.find_package_data(), 
    35       entry_points=""" 
    36           [paste.paster_create_template] 
    37               mytemplate = mytemplate:MyTemplate 
    38         """ 
    39       ) 
     2#!rst 
     3.. note:: This page has been migrated to http://docs.turbogears.org/1.0/ExtendingQuickstart. 
    404}}} 
    41  
    42 This setup basically tells pastescript that there is a template called mytemplate and its class is MyTemplate in the mytemplate module 
    43  
    44 Now let's edit {{{__init__.py}}} 
    45  
    46 {{{ 
    47 #!python 
    48 from paste.script import templates 
    49 import pkg_resources 
    50  
    51 class MyTemplate(templates.Template): 
    52  
    53     egg_plugins = ['MyTemplate'] 
    54     _template_dir = pkg_resources.resource_filename("mytemplate", "template") 
    55     summary = "my own cute template" 
    56  
    57 }}} 
    58  
    59 Now all you have to do is add documentation templates, testing frameworks... to the template dir. 
    60  
    61 Now you can run: 
    62   
    63 tg-admin quickstart -t mytemplate and there should be a default.css file in your static/css/ dir! 
    64  
    65 See http://pythonpaste.org/script/developer.html#templates for more info 
    66  
    67 /elvelind grandin 
    68  
    69 == Notes == 
    70  
    71 If you're indeed extending `quickstart` and not creating a fresh template, you may want to add `use_cheetah = True` as an attribute of your template class, as `quickstart` makes use of Cheetah for IdentityManagement, though it might not be necessary in 0.8. 
    72  
    73 == Advanced Topics == 
    74  
    75 === Removing Inherited Files === 
    76  
    77 Sometimes you'll want to use a quickstart template, but perhaps you don't like one part. In this case your template's `__init__.py` might look like this: 
    78  
    79 {{{ 
    80 #!python 
    81 from paste.script import templates 
    82 import pkg_resources 
    83 import os 
    84  
    85 class AdvancedStart(templates.Template): 
    86  
    87     egg_plugins = ['AdvancedStart'] 
    88     _template_dir = pkg_resources.resource_filename('advancedstart', 'template') 
    89     summary = 'TurboGears Advanced project template' 
    90     required_templates = ['turbogears'] 
    91     use_cheetah = True 
    92  
    93     def post(self, command, output_dir, vars): 
    94         templates.Template.post(self, command, output_dir, vars) 
    95         try: 
    96             path = os.path.join(output_dir, vars['package'] + '/controllers.py') 
    97             os.remove(path) 
    98             print 'Removing', path 
    99         except OSError: 
    100             pass 
    101 }}} 
    102  
    103 Note: the above was made for use with TurboGears 0.9's `quickstart` template.