Changes between Version 14 and Version 15 of EggCookingTutorialTrac0.11


Ignore:
Timestamp:
Jan 29, 2010, 6:41:47 PM (5 years ago)
Author:
eallik@…
Comment:

Fixed grammar mistakes and a few wordings.

Legend:

Unmodified
Added
Removed
Modified
  • EggCookingTutorialTrac0.11

    v14 v15  
    1919To develop a plugin you need to create a few directories to keep things together.
    2020
    21 So let's create following directories:
     21So let's create the following directories:
    2222{{{
    2323./helloworld-plugin/
     
    6464}}}
    6565
    66 To help 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.
     66To 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.
    6767
    6868== Make it a module ==
     
    108108Copy this .egg file to /[your trac env]/plugins directory. Restart the trac server. If you're using mod_python you have to restart Apache.
    109109
    110 Now you should see ''Hello World'' link at far right in main navigation bar when accessing your site. Click it.
     110Now you should see a ''Hello World'' link on the far right in the main navigation bar when accessing your site. Click it.
    111111
    112112== Aftermath ==
     
    118118After you read [wiki:EggCookingTutorialTrac0.11#BasicEggcooking Basic Egg Cooking] and created your first egg, it's time to make it a bit better.
    119119
    120 First we integrate our output to other Trac layout in form of Genshi template.
    121 
    122 == Adding template ==
     120First we integrate our output to other Trac layout in the form of a Genshi template.
     121
     122== Adding a template ==
    123123
    124124To 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.
     
    129129}}}
    130130
    131 In that directory create a new file ''helloworld.html'':
     131In that directory create a file called ''helloworld.html'':
    132132{{{
    133133#!text/html
     
    159159Trac doesn't know where your template is so you have to tell it. This is done by implementing the ITemplateProvider interface in ''helloworld.py''.
    160160
    161 So you change few lines as following:
     161So you change a few lines as following:
    162162
    163163Line 7 is changed from
     
    182182}}}
    183183
    184 Starting from line 24 old ''process_request'' method is replaced by
     184Starting from line 24 the old ''process_request'' method is replaced by
    185185{{{
    186186#!python
     
    192192}}}
    193193
    194 And to end of file you need to tell where your template is located
     194And near the end of the file you need to define where your template is located
    195195{{{
    196196#!python
     
    243243}}}
    244244
    245 == Copy template to egg ==
    246 
    247 Finally you have to include the new template directory in an egg.
     245== Copy the template to the egg ==
     246
     247Finally you have to include the new template directory in the egg.
    248248
    249249So change ''setup.py'' to be like:
     
    252252from setuptools import find_packages, setup
    253253
    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.
    255255# name that is used in packages is the one that is used in the trac.ini file.
    256256# use package name as entry_points
     
    276276== Aftermath ==
    277277
    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 cook high-end egg.
     278Now 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.
    279279
    280280= Cooking high-end eggs (Hello World 3) =
    281281
    282 Now you have pretty neat plugin already but let's add final twist and serve some static content like stylesheet and image.
    283 
    284 == Important thing to check ==
    285 
    286 First step is to ensure that your ''trac.ini'' doesn't have ''htdocs_location'' set otherwise Trac can't serve static data.
     282Now 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
     286The first step is to ensure that your ''trac.ini'' doesn't have ''htdocs_location'' set, otherwise Trac can't serve static data.
    287287== Directory Listing for Hello World 3 ==
    288288{{{
     
    305305== More directories ==
    306306
    307 Since we don't have enough directories in our simple plugin let's make few more:
     307Since we don't have enough directories in our simple plugin let's create some more:
    308308{{{
    309309./helloworld-plugin/helloworld/htdocs/
     
    314314== Style is everything ==
    315315
    316 We want to use our own stylesheet to give some color to our fine content. For that we need cascaded stylesheet.
     316We want to use our own styles to give some color to our fine content. For that we need a CSS file.
    317317
    318318Create ''helloworld.css'' in ''./helloworld-plugin/helloworld/htdocs/css/'':
     
    324324}}}
    325325
    326 == Image tells more than thousand words ==
     326== An image says more than a thousand words ==
    327327
    328328Images are always nice.
    329329
    330 Put small image named ''helloworld.jpg'' in ''./helloworld-plugin/helloworld/htdocs/images/''.
    331 
    332 Note: Since it's not practical to show jpg contents here you should find one image by yourself somewhere.
    333 
    334 == Egg grows ==
    335 
    336 Even natural eggs doesn't grow Python eggs does.
     330Put a small image named ''helloworld.jpg'' in ''./helloworld-plugin/helloworld/htdocs/images/''.
     331
     332Note: Since it's not practical to show JPEG contents here you should find one image by yourself somewhere.
     333
     334== The egg grows ==
     335
     336Natural eggs don't dron, Python ones do.
    337337
    338338Modify ''setup.py'' to include our static data:
     
    357357}}}
    358358
    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'' which
    364 implements {{{get_htdocs_dir()}}} to tell the static data path information for this plugin
     359== Have Trac now about our static content ==
     360
     361Trac doesn't know where our stylesheet and image are located. So you have to let Trac now.
     362
     363Add the following code near the end of ''helloworld.py'' which
     364implements {{{get_htdocs_dir()}}} to define the static data path information for this plugin
    365365with identical prefix 'hw'.
    366366{{{
     
    381381}}}
    382382
    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
     385To make Trac to load our stylesheet you need to modify ''process_request'' method starting from line 24 to the following:
    386386{{{
    387387#!python
     
    393393        return 'helloworld.html', data, None
    394394}}}
    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''.
     395Note that the prefix path 'hw/' that was specified by {{{get_htdocs_dirs()}}} should be used.
     396
     397And also add an import of {{{add_stylesheet}}} at the beginning of ''helloworld.py''.
    398398{{{
    399399#!python
     
    404404'''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`.
    405405
    406 == Complete version of code ==
     406== A complete version of our code ==
    407407The whole of final code is here:
    408408{{{
     
    462462== Back to images ==
    463463
    464 We need to add our image to template to see it.
     464We need to add our image to the template to see it.
    465465
    466466Our new ''helloworld.html'':
     
    499499== Aftermath ==
    500500
    501 Now you have successfully completed nice simple plugin that uses it's own template and serves some static data.
     501Now you have successfully completed a simple plugin that uses its own template and serves some static data.
    502502
    503503=== Remove the plugin ===