Added templetor support to page creator
authordanigm <dani@danigm.net>
Sat, 25 Apr 2009 14:20:14 +0000 (16:20 +0200)
committerdanigm <dani@danigm.net>
Sat, 25 Apr 2009 14:20:14 +0000 (16:20 +0200)
modules/page/page.py
modules/page/pages/templetor [new file with mode: 0644]
modules/page/templates/add.html

index cebef19..7879db1 100644 (file)
@@ -7,6 +7,7 @@ import codecs
 
 MOD = 'page'
 markdown = kisspi.web.utils.safemarkdown
+templetor = kisspi.web.template.Template
 
 def get_page(page):
     path = kisspi.get_module_path(MOD) + 'pages/'
@@ -22,6 +23,14 @@ def get_page(page):
     msg = ''.join(msg[1:])
     return date, msg
 
+def get_html(msg):
+    if msg.startswith('#templetor'):
+        result = templetor(msg[10:])().__body__
+        html = result 
+    else:
+        html = markdown(msg)
+    return html
+
 class Show:
     title = ''
     def GET(self, page):
@@ -39,10 +48,9 @@ Page '%s' not exists
             return not_found
         last_edited = ' Last edited: %s ' % date.ctime()
 
-        return markdown(msg) + edit_button + last_edited 
+        html = get_html(msg)
 
-    def POST(self, *args):
-        return str(args)
+        return html + edit_button + last_edited 
 
 class Edit:
     title = ''
@@ -71,6 +79,8 @@ class Edit:
             kisspi.redirect('/page/'+page)
         else:
             title = 'Preview - ' + page
-            prev = markdown(newpage)
+
+            prev = get_html(newpage)
+
             return render.add(newpage, prev)
 
diff --git a/modules/page/pages/templetor b/modules/page/pages/templetor
new file mode 100644 (file)
index 0000000..f420704
--- /dev/null
@@ -0,0 +1,10 @@
+1240668863.04
+#templetor\r
+\r
+<h2>Templetor test</h2>\r
+<p>\r
+$for i in range(10):\r
+    $i<br/>\r
+\r
+<b>test</b>\r
+</p>
\ No newline at end of file
index 12a2360..7d78f6f 100644 (file)
@@ -2,6 +2,14 @@ $def with (text='', prev='')
 
 <div id="preview">$:prev</div>
 
+<p>
+Use <a href="http://daringfireball.net/projects/markdown/syntax">markdown</a> syntax.
+</p>
+
+<p>
+You can use webpy <a href="http://webpy.org/docs/0.3/templetor">templetor</a> putting as first line #templetor
+</p>
+
 <form method="POST" action="">
     <textarea rows="20" name="newpage">$text</textarea>
     <button type="submit" name="button" value="save">Save</button>