Re: Fixed txtl.py

"Mario Fernández" <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
Sure, here it is:

--- txtl.py	Wed May 14 09:12:17 2008
+++ my_txtl.py	Wed May 14 08:53:48 2008
@@ -104,7 +104,7 @@


 def verify_installation(request):
-
+
     config = request.getConfiguration()

     # First let's see if we can find the textile module.
@@ -199,18 +199,45 @@


 def cb_entryparser(args):
+    """
+    Entryparser chain callback - This plugins takes in a *.txtl file and treats
+    it like a normal blosxom entry file. Postformat callbacks are also called
+    from this entryparser.
+
+    @param args: dict containing function references for each extensions
+    @type args: dict
+    @returns: updated dict containing the reference for .txtl entryparser
+    @rtype: dict
+    """
+
     args[FILE_EXT] = readfile
     return args


 def cb_preformat(args):
+    """
+    Preformat callback chain looks for this.
+
+    @param args: a dict with 'parser' string and a list 'story'
+    @type args: dict
+    """
     if args['parser'] == PREFORMATTER_ID:
-        return parse(''.join(args['story']))
+        return parse(''.join(args['story']),args['request'])
     else:
         return ''.join(args['story'])


 def readfile(filename, request):
+    """
+    Reads a file and passes it to L{parse} to format in textile
+
+    @param filename: the file in question
+    @type filename: string
+    @param request: The request object
+    @type request: L{Pyblosxom.pyblosxom.Request} object
+    @returns: Data of the entry
+    @rtype: dict
+    """
     entryData = {}
     d = open(filename).read()

@@ -218,15 +245,9 @@
     title = d.split('\n')[0]
     body  = d[len(title):]

-    # Grab textile configuration.
-    config = request.getConfiguration()
-    head_offset = config.get('txtl_head_offset', 0)
-    validate    = config.get('txtl_validate', 0)
-    output      = config.get('txtl_output', 'ascii')
-    encoding    = config.get('txtl_encoding', 'latin-1')
+    # Parse content
+    body = parse(body,request)

-    body = textile(body, head_offset=head_offset, validate=validate,
output=output, encoding=encoding)
-
     entryData = {'title': title,
                  'body': body}

@@ -236,3 +257,24 @@
              'entry_data': entryData})

     return entryData
+
+def parse(story,request):
+    """
+    Uses textile to parse the given text
+
+    @param story: A text for conversion
+    @type story: string
+    @param request: The request object
+    @type request: L{Pyblosxom.pyblosxom.Request} object
+    @returns: formatted string
+    @rtype: string
+    """
+
+    # Grab textile configuration.
+    config = request.getConfiguration()
+    head_offset = config.get('txtl_head_offset', 0)
+    validate    = config.get('txtl_validate', 0)
+    output      = config.get('txtl_output', 'ascii')
+    encoding    = config.get('txtl_encoding', 'latin-1')
+
+    return textile(story, head_offset=head_offset, validate=validate,
output=output, encoding=encoding)


On Wed, May 14, 2008 at 7:22 AM, will <[email protected]> wrote:
> Hi Mario!
>
> Can you attach a diff from what's in SVN?
>
> /will
>
> Mario Fernández wrote:
>>
>> Hi,
>>
>> I am a fairly new user of pyblosxom. While trying to set it up, and after
>> some time wondering what was going on, I found that the plugin txtl.py
>> didn't really work, so I fixed it, and while I was at it, added some
>> comments.
>> Hope that it is useful for somebody.
>>
>> Mario
>

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.