Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python template engines and implementation in Indico Marius Damarackas (Vilnius University)

Similar presentations


Presentation on theme: "Python template engines and implementation in Indico Marius Damarackas (Vilnius University)"— Presentation transcript:

1 Python template engines and implementation in Indico Marius Damarackas (Vilnius University)

2 About me Software engineering student Doing 3 months long internship in CERN Improving Indico template system 2

3 Outline 1.History of Indico templates 2.Why change the current system? 3.Main tasks Research about available template systems Integration of the new engine Replacing XSLT with normal templates 4.Remaining work 3

4 History of Indico templates First generation 4 >>> ' %(param)s ' % {'param' : 'Value'} ' Value '

5 History of Indico templates Second generation 5 foobar foobar

6 Why change the current system? Maintenance costs Slow when including other templates No cache No HTML escaping Strange usage of the colon symbols: 6

7 1. Research Some of the candidates ▫Genshi ▫Mako ▫Cheetah ▫Jinja2 7

8 1. Research Genshi ▫Claims to be the fastest XML template engine ▫Used by Trac ▫XML and Text versions ▫Features like caching, XSS protections ▫Slow ▫Very difficult to translate Indico templates 8

9 1. Research Mako ▫Used by python.org and reddit.com ▫Very fast: compiles to Python modules ▫Allows to disable Unicode (a plus for Indico) ▫Template inheritance mechanism ▫Syntax could be better, more unified 9

10 1. Research Jinja2 ▫Quite fast ▫Template inheritance ▫Strong separation of logic and presentation ▫Difficult to adapt to Indico Cheetah ▫Manual compilation to Python modules  Mako does it automatically ▫Personally I did not like the syntax 10

11 2. Integration Replace old engine code with TemplateLookup Problem: more than 800.tpl files to translate 11

12 2. Integration Using a script to convert files Mainly based on regexps Some things needed to be changed by hand 12

13 2. Testing integration Basic idea to test the integration: ▫use *both* old Indico and new Mako templates Generate outputs and do diff If there are significant differences, save them Analyze differences and fix the script 13

14 2. Testing integration Coverage: 450+ out of 800 templates 56%, but higher if we count only active files Allowed to catch some bugs in the script 14

15 3. Replacing XSLT 15

16 3. Replacing XSLT Generates XML, then applies transformations Slow Different from other parts of the system Lots of code duplication Difficult to maintain 16

17 3. Replacing XSLT Maintenance problems 17 … if (chatInfoState]]> <![CDATA[').dom.className = "CRDisplayMoreInfo"; … if (chatInfoState]]> <![CDATA[').dom.className = "CRDisplayMoreInfo"; …

18 3. Replacing XSLT Same code in human language 18 … if (chatInfoState${id}) { IndicoUI.Effect.slide('collaborationInfoLine${id}', height${id}); $E('CRMoreInfo${id}').set('More info'); $E('CRMoreInfo${id}').dom.className = "CRDisplayMoreInfo"; … if (chatInfoState${id}) { IndicoUI.Effect.slide('collaborationInfoLine${id}', height${id}); $E('CRMoreInfo${id}').set('More info'); $E('CRMoreInfo${id}').dom.className = "CRDisplayMoreInfo"; …

19 3. Replacing XSLT Performance: ▫Changing the way parameters are passed ▫No XML Maintenance: ▫Most of the styles are similar ▫Using Mako template inheritance 19

20 Remaining work Think of a smart way to restructure event styles Fix the i18n script to support the new syntax 20

21 Thank you 21


Download ppt "Python template engines and implementation in Indico Marius Damarackas (Vilnius University)"

Similar presentations


Ads by Google