Re: First example of the showmore plugin

Wari Wahab <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <[email protected]>
Chris Moffitt wrote:

>Here's my first stab at the showmore plugin.  It works to a point, but it
>does not link directly to an entry yet.  I haven't figured out how to get
>the url.
>  
>
Darn, I didn't attach
showmore.py (text/html, 1.3 KB)
"""
If the user puts <!--MORE--> in a document, then split the output at the
label and present a link to more detailed information

The '<!--MORE-->' string is configuration in config.py:
py['showmore_seperator'] = '[[MORE]]'
"""
from Pyblosxom import tools

entry = {}

def showmore(var = 'More...'):
    global entry
    registry = tools.get_registry()
    req = registry["request"]
    data = req.getData()
    conf = req.getConfiguration()
    entries = data['entry_list']
    if entry.has_key('more') and len(entries) == 1:
        return entry['more']
    elif entry.has_key('more'):
        output = '<a href="%s/%s">%s</a>' % \
                (conf['base_url'], entry['file_path'], var)
        return output
    else:
        return ''

def cb_prepare(args):
     request = args["request"]
     data = request.getData()
     data["showmore"] = showmore

def cb_story(args):
    global entry
    entry = args['entry']

def cb_postformat(args):
    req = args['request']
    config = req.getConfiguration()
    text = str(args['entry_data']['body'])
    try:
        first, last = text.split(config.get('showmore_seperator', '<!--MORE-->'))
        args['entry_data']['body'] = first
        args['entry_data']['more'] = last
    except ValueError:
        pass # No such thing as more than more
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.