Changes between Version 34 and Version 35 of EggCookingTutorial/BasicEggCooking


Ignore:
Timestamp:
Jan 25, 2016, 8:15:53 PM (8 years ago)
Author:
figaro
Comment:

Cosmetic changes

Legend:

Unmodified
Added
Removed
Modified
  • EggCookingTutorial/BasicEggCooking

    v34 v35  
    11[[TOC(heading=Egg Cooking Tutorial, EggCookingTutorial/BasicEggCooking, EggCookingTutorial/AdvancedEggCooking, EggCookingTutorial/AdvancedEggCooking2, EggCookingTutorial/publish)]]
    22
    3 = Egg cooking =
    4 
    5 Since Trac 0.9 it has been possible to write plugins for Trac to extend Trac functionality.  Even better, you can deploy plugins as [http://peak.telecommunity.com/DevCenter/PythonEggs Python eggs], which really makes plugin development fun and easy.
     3= Egg cooking
    64
    75This tutorial shows how to make and load an egg in Trac. In the advanced parts you'll learn how to serve templates and static content from an egg.
    86
    9 You should be familiar with [trac:TracDev/ComponentArchitecture component architecture] and [trac:TracDev/PluginDevelopment plugin development]. This plugin is based on the example in the plugin development article. Here we extend it a bit further.
     7You should be familiar with Trac's [trac:TracDev/ComponentArchitecture component architecture] and [trac:TracDev/PluginDevelopment plugin development]. This plugin is based on the example in the plugin development article. Here we extend it a bit further.
    108
    11 == Required items ==
     9== Required items
    1210
    1311First you need ''setuptools''. For instructions and files see [http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install EasyInstall] page.
    1412
    15 You also need '''Trac'''.  Download it from the [http://projects.edgewall.com/trac/wiki/TracDownload TracDownload] page.
     13You also need a running version of '''Trac'''. Download it from the [trac:TracDownload] page.
    1614
    17 == Directories ==
     15== Directories
    1816
    19 To develop a plugin you need to create a few directories to keep things together.
    20 
    21 So let's create following directories:
    22 {{{
     17To develop a plugin you need to create a few directories to keep things together. So let's create the following directories:
     18{{{#!sh
    2319./helloworld-plugin/
    2420./helloworld-plugin/helloworld/
    2521}}}
    2622
    27 == Main plugin ==
     23== Main plugin
    2824
    29 The first step is to generate the main module for this plugin.  We will construct a simple plugin that will display "Hello world!" on the screen when accessed through the /helloworld URL. The plugin also provides a "Hello" button that is, by default, rendered on the far right in the main navigation bar.
     25The first step is to generate the main module for this plugin. We will construct a simple plugin that will display "Hello world!" on the screen when accessed through the /helloworld URL. The plugin also provides a "Hello" button that is, by default, rendered on the far right in the main navigation bar.
    3026
    3127So create ''helloworld.py'' in ''./helloworld-plugin/helloworld/'':
    32 {{{
    33 #!python
     28{{{#!python
    3429# Helloworld plugin
    3530
     
    6560To help understand how that works, read the [http://projects.edgewall.com/trac/browser/branches/0.9-stable/trac/web/chrome.py#L53 INavigationContributor] and [http://projects.edgewall.com/trac/browser/branches/0.9-stable/trac/web/api.py#L224 IRequestHandler] interface specifications.
    6661
    67 == Make it a module ==
     62== Make it a module
    6863
    6964To make the plugin a module, you simply create an ''_''____''_init_''____''_.py'' in ''./helloworld-plugin/helloworld/'':
    70 {{{
    71 #!python
     65{{{#!python
    7266# Helloworld module
    7367from helloworld import *
    7468}}}
    7569
    76 == Make it an egg ==
     70== Make it an egg
    7771
    7872Now it's time to make it an egg. For that we need a chicken called ''setup.py'' in ''./helloworld-plugin/'':
    79 {{{
    80 #!python
     73{{{#!python
    8174from setuptools import setup
    8275
     
    9184}}}
    9285
    93 You will also have to add special [http://peak.telecommunity.com/DevCenter/EggFormats#project-metadata egg metadata] to cater to Trac's plugin loader.  First create the directory
    94 ''./helloworld-plugin/TracHelloworld.egg-info'', where the name of the ''.egg-info'' file corresponds to ''PACKAGE''.
     86You will also have to add special [http://peak.telecommunity.com/DevCenter/EggFormats#project-metadata egg metadata] to cater to Trac's plugin loader.  First create the directory ''./helloworld-plugin/TracHelloworld.egg-info'', where the name of the ''.egg-info'' file corresponds to ''PACKAGE''.
    9587
    9688Put the following text in a file named ''trac_plugin.txt'' in ''./helloworld-plugin/TracHelloworld.egg-info'':
     
    10092}}}
    10193
    102 == First deployment ==
     94== First deployment
    10395
    10496Now try to build the plugin. Run the command {{{python setup.py bdist_egg}}} in the directory where you created it. If everything went OK, you should have a .egg file in ''./dist'' directory.
    10597
    106 Copy this ''.egg'' file to ''/[your trac env]/plugins'' directory. Restart the trac server. If you're using mod_python you have to restart Apache.
     98Copy this ''.egg'' file to ''/[your trac env]/plugins'' directory. Restart the Trac server. If you're using mod_python you have to restart Apache.
    10799
    108100Now you should see ''Hello'' link at far right in the main navigation bar when accessing your site. Click it.
    109101
    110 == Aftermath ==
     102== Aftermath
    111103
    112 Now that you have successfully created your first egg, you can continue by reading [wiki:EggCookingTutorial/AdvancedEggCooking EggCookingTutorial/AdvancedEggCooking] to learn how to use templates in your plugins, and make its output look like other Trac pages.
     104Now that you have successfully created your first egg, you can continue by reading [wiki:EggCookingTutorial/AdvancedEggCooking] to learn how to use templates in your plugins, and make its output look like other Trac pages.