def main(cmd_args=None): """The main entry point for running the Markdoc CLI.""" if cmd_args is not None: args = parser.parse_args(cmd_args) else: args = parser.parse_args() if args.command != 'init': try: args.config = os.path.abspath(args.config) if os.path.isdir(args.config): config = Config.for_directory(args.config) elif os.path.isfile(args.config): config = Config.for_file(args.config) else: raise ConfigNotFound("Couldn't locate Markdoc config.") except ConfigNotFound as exc: parser.error(str(exc)) else: config = None logging.getLogger('markdoc').setLevel(getattr(logging, args.log_level)) command = getattr(commands, args.command.replace('-', '_')) return command(config, args)
def main(cmd_args=None): """The main entry point for running the Markdoc CLI.""" if cmd_args is not None: args = parser.parse_args(cmd_args) else: args = parser.parse_args() if args.command != 'init': try: args.config = os.path.abspath(args.config) if os.path.isdir(args.config): config = Config.for_directory(args.config) elif os.path.isfile(args.config): config = Config.for_file(args.config) else: raise ConfigNotFound("Couldn't locate Markdoc config.") except ConfigNotFound, exc: parser.error(str(exc))
def get_temporary_config(): """ Return a temporary Markdoc configuration. The contents of the wiki will be copied from the example Markdoc wiki. After you're done with this, you should call `clean_temporary_config()` on the config object. """ own_config_dir = p.join(p.dirname(p.abspath(__file__)), 'example') + p.sep temp_config_dir = p.join(tempfile.mkdtemp(), 'example') shutil.copytree(own_config_dir, temp_config_dir) return Config.for_directory(temp_config_dir)
# -*- coding: utf-8 -*- import os import os.path as p import operator import re from datetime import datetime from markdoc.cache import DocumentCache, RenderCache, read_from from markdoc.config import Config from markdoc.render import make_relative Config.register_default('listing-filename', '_list.html') Config.register_default('disqus-sitename', '') class Builder(object): """An object to handle all the parts of the wiki building process.""" doc_metas = {} #The result of all markdown.MetaExtension def __init__(self, config): self.config = config self.globals = { 'current_year': datetime.now().strftime('%Y'), 'disqus_sitename': self.config['disqus-sitename'], } self.doc_cache = DocumentCache(base=self.config.wiki_dir) def render_func(path, doc):
# -*- coding: utf-8 -*- import os import os.path as p import operator import re from markdoc.cache import DocumentCache, RenderCache, read_from from markdoc.config import Config from markdoc.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)
# -*- coding: utf-8 -*- from markdoc.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"],
# -*- coding: utf-8 -*- from markdoc.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'], server_name=config['server.name'], request_queue_size=config['server.request-queue-size'], timeout=config['server.timeout'])
# -*- coding: utf-8 -*- import os.path as p import jinja2 import markdoc from markdoc.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(markdoc.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)
# -*- coding: utf-8 -*- from markdoc.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'],
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)
__FILENAME__ = builder # -*- coding: utf-8 -*- import os import os.path as p import operator import re from markdoc.cache import DocumentCache, RenderCache, read_from from markdoc.config import Config from markdoc.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,
# -*- coding: utf-8 -*- import os import os.path as p import operator import re from datetime import datetime from markdoc.cache import DocumentCache, RenderCache, read_from from markdoc.config import Config from markdoc.render import make_relative Config.register_default('listing-filename', '_list.html') Config.register_default('disqus-sitename', '') class Builder(object): """An object to handle all the parts of the wiki building process.""" doc_metas = {} #The result of all markdown.MetaExtension def __init__(self, config): self.config = config self.globals = { 'current_year': datetime.now().strftime('%Y'), 'disqus_sitename': self.config['disqus-sitename'], }
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)
# -*- coding: utf-8 -*- import os import os.path as p import operator import re from markdoc.cache import DocumentCache, RenderCache, read_from from markdoc.config import Config from markdoc.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)
# -*- coding: utf-8 -*- import os.path as p from markdoc.config import Config import markdown 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', 'xhtml1') 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('/'): link.attrib['href'] = self.make_relative(link.attrib['href'])
__FILENAME__ = builder # -*- coding: utf-8 -*- import os import os.path as p import operator import re from markdoc.cache import DocumentCache, RenderCache, read_from from markdoc.config import Config from markdoc.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)
# -*- coding: utf-8 -*- import os import os.path as p from markdoc.config import Config import markdown 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', 'xhtml1') Config.register_default('document-extensions', frozenset(['.md', '.mdown', '.markdown', '.wiki', '.text'])) Config.register_default('use-ugly-paths', False) class RelativeLinksTreeProcessor(markdown.treeprocessors.Treeprocessor): """A Markdown tree processor to relativize wiki links.""" def __init__(self, config, curr_path='/'): self.curr_path = curr_path self.config = config def make_relative(self, href): return make_relative(self.config, self.curr_path, href) def run(self, tree): links = tree.getiterator('a')
# -*- coding: utf-8 -*- import os.path as p import jinja2 import markdoc from markdoc.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(markdoc.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) return config._template_env