Changes between Version 14 and Version 15 of EggCookingTutorialTrac0.11
- Timestamp:
- Jan 29, 2010, 5:41:47 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
EggCookingTutorialTrac0.11
v14 v15 19 19 To develop a plugin you need to create a few directories to keep things together. 20 20 21 So let's create following directories:21 So let's create the following directories: 22 22 {{{ 23 23 ./helloworld-plugin/ … … 64 64 }}} 65 65 66 To helpunderstand how that works, read the [http://trac.edgewall.org/browser/trunk/trac/web/chrome.py#L183 INavigationContributor] and [http://trac.edgewall.org/browser/trunk/trac/web/api.py#L517 IRequestHandler] interface specifications.66 To better understand how that works, read the [http://trac.edgewall.org/browser/trunk/trac/web/chrome.py#L183 INavigationContributor] and [http://trac.edgewall.org/browser/trunk/trac/web/api.py#L517 IRequestHandler] interface specifications. 67 67 68 68 == Make it a module == … … 108 108 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. 109 109 110 Now you should see ''Hello World'' link at far right inmain navigation bar when accessing your site. Click it.110 Now you should see a ''Hello World'' link on the far right in the main navigation bar when accessing your site. Click it. 111 111 112 112 == Aftermath == … … 118 118 After you read [wiki:EggCookingTutorialTrac0.11#BasicEggcooking Basic Egg Cooking] and created your first egg, it's time to make it a bit better. 119 119 120 First we integrate our output to other Trac layout in form ofGenshi template.121 122 == Adding template ==120 First we integrate our output to other Trac layout in the form of a Genshi template. 121 122 == Adding a template == 123 123 124 124 To have a template we need a directory and of course the template itself. We will keep the same simple "Hello world!" text, but this time we will integrate our fine words into a Trac layout. … … 129 129 }}} 130 130 131 In that directory create a new file''helloworld.html'':131 In that directory create a file called ''helloworld.html'': 132 132 {{{ 133 133 #!text/html … … 159 159 Trac doesn't know where your template is so you have to tell it. This is done by implementing the ITemplateProvider interface in ''helloworld.py''. 160 160 161 So you change few lines as following:161 So you change a few lines as following: 162 162 163 163 Line 7 is changed from … … 182 182 }}} 183 183 184 Starting from line 24 old ''process_request'' method is replaced by184 Starting from line 24 the old ''process_request'' method is replaced by 185 185 {{{ 186 186 #!python … … 192 192 }}} 193 193 194 And to end of file you need to tellwhere your template is located194 And near the end of the file you need to define where your template is located 195 195 {{{ 196 196 #!python … … 243 243 }}} 244 244 245 == Copy t emplate toegg ==246 247 Finally you have to include the new template directory in anegg.245 == Copy the template to the egg == 246 247 Finally you have to include the new template directory in the egg. 248 248 249 249 So change ''setup.py'' to be like: … … 252 252 from setuptools import find_packages, setup 253 253 254 # name can be any name. This name will be used to create .egg file.254 # name can be any name. This name will be used to create the .egg file. 255 255 # name that is used in packages is the one that is used in the trac.ini file. 256 256 # use package name as entry_points … … 276 276 == Aftermath == 277 277 278 Now that you have added a basic template for your plugin let's add the final twist, putting some static content like a stylesheet and an image. Continue to next section to cookhigh-end egg.278 Now that you have added a basic template for your plugin let's add the final twist, putting some static content like a stylesheet and an image. Continue to the next section to cook a high-end egg. 279 279 280 280 = Cooking high-end eggs (Hello World 3) = 281 281 282 Now you have pretty neat plugin already but let's add final twist and serve some static content like stylesheet andimage.283 284 == Important thing to check ==285 286 First step is to ensure that your ''trac.ini'' doesn't have ''htdocs_location'' setotherwise Trac can't serve static data.282 Now you have a pretty neat plugin already but let's add that final twist and serve some static content like a stylesheet and an image. 283 284 == An important thing to check == 285 286 The first step is to ensure that your ''trac.ini'' doesn't have ''htdocs_location'' set, otherwise Trac can't serve static data. 287 287 == Directory Listing for Hello World 3 == 288 288 {{{ … … 305 305 == More directories == 306 306 307 Since we don't have enough directories in our simple plugin let's make fewmore:307 Since we don't have enough directories in our simple plugin let's create some more: 308 308 {{{ 309 309 ./helloworld-plugin/helloworld/htdocs/ … … 314 314 == Style is everything == 315 315 316 We want to use our own styles heet to give some color to our fine content. For that we need cascaded stylesheet.316 We want to use our own styles to give some color to our fine content. For that we need a CSS file. 317 317 318 318 Create ''helloworld.css'' in ''./helloworld-plugin/helloworld/htdocs/css/'': … … 324 324 }}} 325 325 326 == Image tells more thanthousand words ==326 == An image says more than a thousand words == 327 327 328 328 Images are always nice. 329 329 330 Put small image named ''helloworld.jpg'' in ''./helloworld-plugin/helloworld/htdocs/images/''.331 332 Note: Since it's not practical to show jpgcontents here you should find one image by yourself somewhere.333 334 == Egg grows ==335 336 Even natural eggs doesn't grow Python eggs does.330 Put a small image named ''helloworld.jpg'' in ''./helloworld-plugin/helloworld/htdocs/images/''. 331 332 Note: Since it's not practical to show JPEG contents here you should find one image by yourself somewhere. 333 334 == The egg grows == 335 336 Natural eggs don't dron, Python ones do. 337 337 338 338 Modify ''setup.py'' to include our static data: … … 357 357 }}} 358 358 359 == Tell it to Trac too==360 361 Trac doesn't know where our fine stylesheet and image is located. So you have to tell it to Trac.362 363 Add the following code at the tail in file''helloworld.py'' which364 implements {{{get_htdocs_dir()}}} to tellthe static data path information for this plugin359 == Have Trac now about our static content == 360 361 Trac doesn't know where our stylesheet and image are located. So you have to let Trac now. 362 363 Add the following code near the end of ''helloworld.py'' which 364 implements {{{get_htdocs_dir()}}} to define the static data path information for this plugin 365 365 with identical prefix 'hw'. 366 366 {{{ … … 381 381 }}} 382 382 383 == Remember to load stylesheet ==384 385 To make Trac to load our stylesheet you need to modify ''process_request'' method starting from line 24 to following:383 == Remember to load the stylesheet == 384 385 To make Trac to load our stylesheet you need to modify ''process_request'' method starting from line 24 to the following: 386 386 {{{ 387 387 #!python … … 393 393 return 'helloworld.html', data, None 394 394 }}} 395 Note that prefix path 'hw/'specified by {{{get_htdocs_dirs()}}} should be used.396 397 And also import {{{add_stylesheet()}}} at the beginning of ''helloworld.py''.395 Note that the prefix path 'hw/' that was specified by {{{get_htdocs_dirs()}}} should be used. 396 397 And also add an import of {{{add_stylesheet}}} at the beginning of ''helloworld.py''. 398 398 {{{ 399 399 #!python … … 404 404 '''Note:''' When you develop a `Component` that implements `IAdminPanelProvider` you have to insert `add_stylesheet(...)` to the method `render_admin_panel`. You don't need to implement `IRequestHandler`. 405 405 406 == Complete version ofcode ==406 == A complete version of our code == 407 407 The whole of final code is here: 408 408 {{{ … … 462 462 == Back to images == 463 463 464 We need to add our image to t emplate to see it.464 We need to add our image to the template to see it. 465 465 466 466 Our new ''helloworld.html'': … … 499 499 == Aftermath == 500 500 501 Now you have successfully completed nice simple plugin that uses it's own template and serves some static data.501 Now you have successfully completed a simple plugin that uses its own template and serves some static data. 502 502 503 503 === Remove the plugin ===