Changes between Version 34 and Version 35 of EggCookingTutorial/BasicEggCooking
- Timestamp:
- Jan 25, 2016, 8:15:53 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
EggCookingTutorial/BasicEggCooking
v34 v35 1 1 [[TOC(heading=Egg Cooking Tutorial, EggCookingTutorial/BasicEggCooking, EggCookingTutorial/AdvancedEggCooking, EggCookingTutorial/AdvancedEggCooking2, EggCookingTutorial/publish)]] 2 2 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 6 4 7 5 This 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. 8 6 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.7 You 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. 10 8 11 == Required items ==9 == Required items 12 10 13 11 First you need ''setuptools''. For instructions and files see [http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install EasyInstall] page. 14 12 15 You also need '''Trac'''. Download it from the [http://projects.edgewall.com/trac/wiki/TracDownloadTracDownload] page.13 You also need a running version of '''Trac'''. Download it from the [trac:TracDownload] page. 16 14 17 == Directories ==15 == Directories 18 16 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 {{{ 17 To develop a plugin you need to create a few directories to keep things together. So let's create the following directories: 18 {{{#!sh 23 19 ./helloworld-plugin/ 24 20 ./helloworld-plugin/helloworld/ 25 21 }}} 26 22 27 == Main plugin ==23 == Main plugin 28 24 29 The first step is to generate the main module for this plugin. 25 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. 30 26 31 27 So create ''helloworld.py'' in ''./helloworld-plugin/helloworld/'': 32 {{{ 33 #!python 28 {{{#!python 34 29 # Helloworld plugin 35 30 … … 65 60 To 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. 66 61 67 == Make it a module ==62 == Make it a module 68 63 69 64 To make the plugin a module, you simply create an ''_''____''_init_''____''_.py'' in ''./helloworld-plugin/helloworld/'': 70 {{{ 71 #!python 65 {{{#!python 72 66 # Helloworld module 73 67 from helloworld import * 74 68 }}} 75 69 76 == Make it an egg ==70 == Make it an egg 77 71 78 72 Now 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 81 74 from setuptools import setup 82 75 … … 91 84 }}} 92 85 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''. 86 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 ''./helloworld-plugin/TracHelloworld.egg-info'', where the name of the ''.egg-info'' file corresponds to ''PACKAGE''. 95 87 96 88 Put the following text in a file named ''trac_plugin.txt'' in ''./helloworld-plugin/TracHelloworld.egg-info'': … … 100 92 }}} 101 93 102 == First deployment ==94 == First deployment 103 95 104 96 Now 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. 105 97 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.98 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. 107 99 108 100 Now you should see ''Hello'' link at far right in the main navigation bar when accessing your site. Click it. 109 101 110 == Aftermath ==102 == Aftermath 111 103 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.104 Now 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.