Пример #1
0
# -*- coding: utf-8 -*-

import os
import os.path as p
import re

from phdoc.cache import DocumentCache, RenderCache, read_from
from phdoc.config import Config
from phdoc.render import make_relative


Config.register_default('listing-filename', '_list.html')


class Builder(object):

    """An object to handle all the parts of the wiki building process."""

    def __init__(self, config):
        self.config = config

        self.doc_cache = DocumentCache(base=self.config.wiki_dir)

        def render_func(path, doc):
            #level = len(path.lstrip('/').split('/')) - 1
            return self.config.markdown(curr_path=path).convert(doc)
        self.render_cache = RenderCache(render_func, self.doc_cache)

        render_doc_func = lambda path, doc: self.render_document(path, cache=False)
        self.document_render_cache = RenderCache(render_doc_func, self.render_cache)
Пример #2
0
# -*- coding: utf-8 -*-

import os.path as p

import jinja2
import phdoc
from phdoc.config import Config


Config.register_default('use-default-templates', True)


def build_template_env(config):
    """Build a Jinja2 template environment for a given config."""
    
    load_path = []
    
    if p.isdir(config.template_dir):
        load_path.append(config.template_dir)
    
    if config['use-default-templates']:
        load_path.append(phdoc.default_template_dir)
    
    environment = jinja2.Environment(loader=jinja2.FileSystemLoader(load_path))
    environment.globals['config'] = config
    return environment


def template_env(config):
    if not getattr(config, '_template_env', None):
        config._template_env = build_template_env(config)
Пример #3
0

def wiki_dir(config):
    return p.abspath(p.join(config['meta.root'], config.get('wiki-dir', 'wiki')))


def temp_dir(config):
    return p.abspath(p.join(config['meta.root'],
        config.get('temp-dir', config['hide-prefix'] + 'tmp')))


def template_dir(config):
    return p.abspath(p.join(config['meta.root'],
        config.get('template-dir', config['hide-prefix'] + 'templates')))


Config.register_default('hide-prefix', '.')
Config.register_default('use-default-static', True)
Config.register_default('cvs-exclude', True)
Config.register_func_default('html-dir', lambda cfg, key: html_dir(cfg))
Config.register_func_default('static-dir', lambda cfg, key: static_dir(cfg))
Config.register_func_default('wiki-dir', lambda cfg, key: wiki_dir(cfg))
Config.register_func_default('temp-dir', lambda cfg, key: temp_dir(cfg))
Config.register_func_default('template-dir', lambda cfg, key: template_dir(cfg))

Config.html_dir = property(html_dir)
Config.static_dir = property(static_dir)
Config.wiki_dir = property(wiki_dir)
Config.temp_dir = property(temp_dir)
Config.template_dir = property(template_dir)
Пример #4
0
# -*- coding: utf-8 -*-

from phdoc.config import Config


Config.register_default('server.bind', '127.0.0.1')
Config.register_default('server.port', 8008)
Config.register_default('server.num-threads', 10)
Config.register_default('server.name', None)
Config.register_default('server.request-queue-size', 5)
Config.register_default('server.timeout', 10)


def server_maker(config, **extra_config):
    
    """
    Return a server-making callable to create a CherryPy WSGI server.
    
    The server-making callable should be passed a WSGI application, and it
    will return an instance of `cherrypy.wsgiserver.CherryPyWSGIServer`.
    
    You can optionally override any of the hardwired configuration
    parameters by passing in keyword arguments which will be passed along to
    the `CherryPyWSGIServer` constructor.
    """
    
    from cherrypy.wsgiserver import CherryPyWSGIServer
    
    bind_addr = (config['server.bind'], config['server.port'])
    kwargs = dict(
        numthreads=config['server.num-threads'],
Пример #5
0
# -*- coding: utf-8 -*-

import os.path as p

from phdoc.config import Config
import markdown
import phdoc.mdx_mathjax
import phdoc.mdx_fold

Config.register_default('markdown.extensions', ())
Config.register_func_default('markdown.extension-configs', lambda cfg, key: {})
Config.register_default('markdown.safe-mode', False)
Config.register_default('markdown.output-format', 'html5')
Config.register_default('document-extensions',
                        frozenset(['.md', '.mdown', '.markdown', '.wiki',
                                   '.text']))


class RelativeLinksTreeProcessor(markdown.treeprocessors.Treeprocessor):
    """A Markdown tree processor to relativize wiki links."""

    def __init__(self, curr_path='/'):
        self.curr_path = curr_path

    def make_relative(self, href):
        return make_relative(self.curr_path, href)

    def run(self, tree):
        links = tree.getiterator('a')
        for link in links:
            if link.attrib['href'].startswith('/'):