dmanty45 / bots

Automatically exported from code.google.com/p/bots
0 stars 0 forks source link

output to html/template: use 'Genshi' library #111

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Botys still used 'Kid'.
Is is not developed anymore, is succeeded by 'Genshi.
'Kid' can still be used, but is depreciated. 

Original issue reported on code.google.com by hjebb...@gmail.com on 1 Jan 2012 at 10:40

GoogleCodeExporter commented 8 years ago
Will there be an example plugin for this? Can we convert or use existing kid 
templates?

Original comment by mjg1964 on 15 Jan 2012 at 10:49

GoogleCodeExporter commented 8 years ago
I will put this in the wiki, and have a plugin for this.
kid templates can be reused, but some namespaces in the start of the templtes 
have to be renamed.

Original comment by hjebb...@gmail.com on 15 Jan 2012 at 1:47

GoogleCodeExporter commented 8 years ago
Ok, I only have 1 template so I will just try it out.

Original comment by mjg1964 on 15 Jan 2012 at 9:11

GoogleCodeExporter commented 8 years ago
attached are 2 files from test environment.

looking at these I see:
- change name space declarations
- the 'include' thing in enveloping works different
- files are call *.html
- different message type

Original comment by hjebb...@gmail.com on 15 Jan 2012 at 9:25

GoogleCodeExporter commented 8 years ago
There were no files attached to your comment above!
I did the following changes...
* Copy usersys/template to usersys/templatehtml
* replace xmlns:py="http://genshi.edgewall.org/"
* rename .kid files to .html, delete .pyc
* change my template to refer to .html not .kid
* change route and translation to specify template-html

The body of html is generated ok, I get an error in enveloping. 
Envelope template contains this code:
<body>
<div py:strip="True" py:for="message in data">
    <div py:replace="document(message)"/>
</div>
</body>
</html>

I get this error:
File 
"D:\python27\lib\site-packages\bots\usersys\grammars\templatehtml\templates\ORDE
R_PRINT_ENV.html", line 42, in <Expression u'document(message)'> <div 
py:replace="document(message)"/> File 
"D:\python27\lib\site-packages\genshi\template\eval.py", line 309, in 
lookup_name val = cls.undefined(name) File 
"D:\python27\lib\site-packages\genshi\template\eval.py", line 410, in undefined 
raise UndefinedError(key, owner=owner) UndefinedError: "document" not defined

Original comment by mjg1964 on 17 Jan 2012 at 2:07

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Got it working like this (not sure if it's the best way)

<body>
<div py:strip="True" py:for="message in data">
    <?python
        def document(message):
            with open(message,'r') as file:
                return Markup(file.read()) ?>
    <div py:replace="document(message)" />
</div>
</body>

Original comment by mjg1964 on 17 Jan 2012 at 3:31

GoogleCodeExporter commented 8 years ago
solved.
The envelope template requires 2 namespaces:
<html xmlns:py="http://genshi.edgewall.org/" 
xmlns:xi="http://www.w3.org/2001/XInclude">

the body is included like this:
<body>
<div py:strip="True" py:for="message in data">
    <xi:include href="${message}" />
</div>
</body>

Original comment by mjg1964 on 17 Jan 2012 at 11:07

GoogleCodeExporter commented 8 years ago
Added a wiki page to migrate this
http://code.google.com/p/bots/wiki/MigrateKidGenshi

Original comment by mjg1964 on 18 Jan 2012 at 3:35

GoogleCodeExporter commented 8 years ago

Original comment by hjebb...@gmail.com on 11 May 2012 at 10:32

GoogleCodeExporter commented 8 years ago

Original comment by hjebb...@gmail.com on 10 Sep 2013 at 12:45