Changes between Version 17 and Version 18 of EggCookingTutorial/AdvancedEggCooking
- Timestamp:
- Jan 25, 2016, 8:18:47 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
EggCookingTutorial/AdvancedEggCooking
v17 v18 1 1 [[TOC(heading=Egg Cooking Tutorial, EggCookingTutorial/BasicEggCooking, EggCookingTutorial/AdvancedEggCooking, EggCookingTutorial/AdvancedEggCooking2, EggCookingTutorial/publish)]] 2 2 3 = Cook even better eggs =3 = Cook even better eggs 4 4 5 After you read [wiki:EggCookingTutorial/BasicEggCooking EggCookingTutorial/BasicEggCooking] and created your first egg, it's time to make it a bit better.5 After you read [wiki:EggCookingTutorial/BasicEggCooking] and created your first egg, it's time to make it a bit better. 6 6 7 7 First we integrate our output to other Trac layout in form of !ClearSilver template. 8 8 9 == Adding template ==9 == Adding template 10 10 11 11 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. 12 12 13 13 For that we need to create one additional directory: 14 {{{ 14 {{{#!sh 15 15 ./helloworld-plugin/helloworld/templates/ 16 16 }}} 17 17 18 18 In that directory create a new file ''helloworld.cs'': 19 {{{ 20 #!text/html 19 {{{#!text/html 21 20 <?cs include "header.cs" ?> 22 21 <?cs include "macros.cs" ?> … … 31 30 Now you have created the template for the plugin. 32 31 33 == Tell Trac where t emplate is ==32 == Tell Trac where the template is 34 33 35 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''.34 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''. 36 35 37 36 So you change few lines as following: 38 37 39 Line 4 is changed from 40 {{{ 41 #!python 38 Line 4 is changed from: 39 {{{#!python 42 40 from trac.web.chrome import INavigationContributor 43 41 }}} 44 to 45 {{{ 46 #!python42 43 to: 44 {{{#!python 47 45 from trac.web.chrome import INavigationContributor, ITemplateProvider 48 46 }}} 49 47 50 Line 9 is changed from 51 {{{ 52 #!python 48 Line 9 is changed from: 49 {{{#!python 53 50 implements(INavigationContributor, IRequestHandler) 54 51 }}} 55 {{{ 56 #!python 52 53 to: 54 {{{#!python 57 55 implements(INavigationContributor, IRequestHandler, ITemplateProvider) 58 56 }}} 59 57 60 Starting from line 23 old ''process_request'' method is replaced by 61 {{{ 62 #!python 58 Starting from line 23 old ''process_request'' method is replaced by: 59 {{{#!python 63 60 def process_request(self, req): 64 61 return 'helloworld.cs', None 65 62 }}} 66 63 67 And to end of file you need to tell where your template is located 68 {{{ 69 #!python 64 And to end of file you need to tell where your template is located: 65 {{{#!python 70 66 # ITemplateProvider methods 71 67 def get_templates_dirs(self): … … 78 74 }}} 79 75 80 Complete version of ''helloworld.py'': 81 {{{ 82 #!python 76 And the complete version of ''helloworld.py'' then becomes: 77 {{{#!python 83 78 # Helloworld plugin 84 79 … … 116 111 }}} 117 112 118 == Copy template to egg ==113 == Copy template to egg 119 114 120 115 Finally you have to include the new template directory in an egg. 121 116 122 117 So change ''setup.py'' to be like: 123 {{{ 124 #!python 118 {{{#!python 125 119 from setuptools import setup 126 120 … … 136 130 }}} 137 131 138 == Building and deploying ==132 == Building and deploying 139 133 140 134 Building and deployment goes exactly the same as it did in the previous tutorial [wiki:EggCookingTutorial/BasicEggCooking#Firstdeployment EggCookingTutorial/BasicEggCooking]. … … 142 136 Now you should see a big "Hello world!" integrated into your Trac layout when you press that fancy button in the main navigation bar. 143 137 144 == Aftermath ==138 == Aftermath 145 139 146 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 [wiki:EggCookingTutorial/AdvancedEggCooking2 EggCookingTutorial/AdvancedEggCooking2]140 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 [wiki:EggCookingTutorial/AdvancedEggCooking2]. 147 141 148 149 150