Source

muyhomepage2 / muyhomepage2 / pagehandlers / tagglobal.py

Full commit
John Mulligan d0dd076 


































from muyhomepage2.pagehandlers import handler
from muyhomepage2.text import wikirst
from muyhomepage2 import util

MIN = 100
MAX = 300

class TagGlobalHandler(handler.PageHandler):
    def content(self):
        return wikirst.format(self.page.body)

    def template(self):
        return 'tagglobal.html'

    def extension(self, website, config):
        tmap = dict(website.tagmap)
        tagcount = len(tmap)
        tagpct = dict((tag, scale(len(tmap[tag]), tagcount, MIN, MAX))
            for tag in tmap)
        tagcloud = [(tagpct[tag], util.encodetitle(tag), tag) for tag in sorted(tmap)]
        def _pinfo(page):
            url = './%s' % handler.PageHandler(page).finalname()
            return (url, page.title)
        tagdetails = [(util.encodetitle(tag), tag, [_pinfo(p) for p in pages])
            for tag, pages in sorted(tmap.iteritems())]
        return {
            'tagcount': tagcount,
            'tagcloud': tagcloud,
            'tagdetails': tagdetails,
            }

def scale(num, total, min, max):
    num = float(num)
    return int((((num - 1) / total) * (max - min)) + min)