Changes between Version 38 and Version 39 of GenshiTutorial
- Timestamp:
- Aug 30, 2007, 7:31:51 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GenshiTutorial
v38 v39 15 15 [[PageOutline(2-3, Content, inline)]] 16 16 17 == Prerequisites == 17 == Getting Started == 18 19 === Prerequisites === 18 20 19 21 First, make sure you have !CherryPy 3.0.x installed, as well as recent versions of [http://formencode.org/ FormEncode] and obviously Genshi. You can download and install those manually, or just use [http://peak.telecommunity.com/DevCenter/EasyInstall easy_install]: … … 25 27 }}} 26 28 27 == Getting Started==29 === The !CherryPy Application === 28 30 29 31 Next, set up the basic !CherryPy application. … … 86 88 Note that we've configured !CherryPy to serve static files from the `geddit/static` directory. !CherryPy will complain that that directory does not exist, so create it, but leave it empty for now. We'll add static resources later on in the tutorial. 87 89 88 == Basic Template Rendering==90 === Basic Template Rendering === 89 91 90 92 So far the code doesn't actually use Genshi, or even any kind of templating. Let's change that. … … 171 173 }}} 172 174 173 == Data Model==175 === The Data Model === 174 176 175 177 To continue, we'll need to first add some Python classes to define the data model the application will use. As mentioned above, we're using a simple pickle file for persistence, so all we need to do here is create a couple of very simply Python classes. … … 268 270 }}} 269 271 270 == Extending the Template == 272 == Making the Application “Do Stuff” == 273 274 === Extending the Template === 271 275 272 276 Now let's change the `Root.index()` method in `geddit/controller.py` to pass the links list to the template: … … 508 512 Now, all entered values are preserved when validation errors occur. Note that the form is populated as the template is being generated, there is no reparsing and reserialization of the output. 509 513 510 == Factoring out the Templating == 514 == Enhancing the Application == 515 516 === Factoring out the Templating === 511 517 512 518 By now, we already have some repetitive code when it comes to rendering templates: both the `Root.index()` and the `Root.submit()` methods look very similar in that regard: they load a specific template, call its `generate()` method passing it some data, and then call the `render()` method of the resulting stream. As we're going to be adding more controller methods, let's factor out those things into a library module. … … 608 614 As you can see here, the code is now less repetitive: there's a simple decorator to define which template should be used, and the `render()` produces the template out stream which can then be further processed if necessary. 609 615 610 == Adding a Layout Template==616 === Adding a Layout Template === 611 617 612 618 But there's also duplication in the template files themselves: each template has to redefine the complete header and footer, and any other “decoration” markup that we may want to apply to the complete site. Now, we could simply put those commonly used markup snippets into separate HTML files and [wiki:Documentation/xml-templates.html#includes include] them in the templates where they are needed. But Genshi provides a more elegant way to apply a common structure to different templates: [wiki:Documentation/xml-templates.html#match-templates match templates]. … … 736 742 [[Image(tutorial03.png)]] 737 743 738 == Implementing Comments==744 === Implementing Comments === 739 745 740 746 TODO 741 747 742 == Allowing Markup in Comments == 748 == Advanced Topics == 749 750 === Allowing Markup in Comments === 743 751 744 752 TODO 745 753 746 == Ajaxifyied Commenting==754 === Ajaxifyied Commenting === 747 755 748 756 TODO 749 757 750 == Adding an Atom Feed==758 === Adding an Atom Feed === 751 759 752 760 TODO