コード例 #1
0
ファイル: main.py プロジェクト: bekacho/zbox_wiki
def wp_edit(req_path):
    full_path = req_path_to_full_path(req_path)

    if conf.button_mode_path:        
        buf = commons.text_path2button_path("/%s" % req_path)
        title = commons.md2html(buf)
    else:
        title = req_path        

    create_new = False
    
    if os.path.isfile(full_path):
        content = commons.cat(full_path)

    elif os.path.isdir(full_path):
        content = get_dot_idx_content_by_full_path(full_path)

    elif not os.path.exists(full_path):
        create_new = True
        content = ""

    else:
        raise Exception("invalid path '%s'" % req_path)

    static_files = get_global_static_files(auto_toc = False,
                            highlight = False,
                            reader_mode = False)

    return tpl_render.editor(req_path, title, content, create_new = create_new, static_files = static_files)
コード例 #2
0
ファイル: main.py プロジェクト: milkmeat/zbox_wiki
def wp_read(req_path, show_full_path, auto_toc, highlight, pages_path,
            show_quick_links, show_source_button):
    full_path = req_path_to_full_path(req_path)

    if conf.button_mode_path:
        buf = commons.text_path2btns_path("/%s" % req_path)
        button_path = commons.md2html(buf)
    else:
        button_path = None

    if os.path.isfile(full_path):
        work_full_path = os.path.dirname(full_path)
        static_file_prefix = os.path.join("/static/pages", os.path.dirname(req_path))

        content = commons.cat(full_path)
        content = commons.strip_bom(content)

        HOME_PAGE = "home"
        if req_path == HOME_PAGE:
            button_path = None
        else:
            show_quick_links = False

    elif os.path.isdir(full_path):
        work_full_path = full_path
        static_file_prefix = os.path.join("/static/pages", req_path)

        buf1 = get_dot_idx_content_by_full_path(full_path) or ""
        buf2 = get_page_file_list_by_req_path(req_path)

        if buf2:
            buf2 = sequence_to_unorder_list(buf2.split("\n"), show_full_path = show_full_path)
        else:
            buf2 = ""

        content = buf1 + "\n" + "----" + "\n" + buf2

    else:
        if req_path == "home" and (not os.path.exists(full_path)):
            return web.seeother("~all")
        else:
            return web.seeother("/%s?action=edit" % req_path)

    content = zw_macro2md(text = content, show_full_path = show_full_path, pages_path = pages_path)

    content = commons.md2html(text = content,
                              work_full_path = work_full_path,
                              static_file_prefix = static_file_prefix)

    static_files = get_the_same_folders_cssjs_files(req_path)
    if not static_files:
        static_files = get_global_static_files(auto_toc = auto_toc, highlight = highlight) + "\n"

    return tpl_render.canvas(conf = conf,
                           req_path = req_path,
                           button_path = button_path,
                           content = content,
                           static_files = static_files,
                           show_quick_links = show_quick_links,
                           show_source_button = show_source_button)
コード例 #3
0
ファイル: main.py プロジェクト: bekacho/zbox_wiki
def wp_source(req_path):
    full_path = req_path_to_full_path(req_path)

    if os.path.isdir(full_path):
        web.header("Content-Type", "text/plain; charset=UTF-8")
        return "folder doesn't providers source code in Markdown"

    elif os.path.isfile(full_path):
        web.header("Content-Type", "text/plain; charset=UTF-8")
        return commons.cat(full_path)

    else:
        raise web.BadRequest()
コード例 #4
0
ファイル: main.py プロジェクト: bekacho/zbox_wiki
def get_wiki_page_title_by_req_path(req_path):
    full_path = req_path_to_full_path(req_path)
    buf = commons.cat(full_path)
    if buf:
        buf = commons.strip_bom(buf)

    p = '^#\s*(?P<title>.+?)\s*$'
    p_obj = re.compile(p, re.UNICODE | re.MULTILINE)
    match_obj = p_obj.search(buf)

    if match_obj:
        title = match_obj.group('title')
    elif '/' in req_path:
        title = req_path.split('/')[-1].replace('-', ' ')
    else:
        title = "Untitled"

    return title
コード例 #5
0
ファイル: main.py プロジェクト: bekacho/zbox_wiki
    def GET(self):
        path = os.path.join(conf.pages_path, "robots.txt")
        content = commons.cat(path)

        web.header("Content-Type", "text/plain")
        return content
コード例 #6
0
ファイル: main.py プロジェクト: bekacho/zbox_wiki
def get_dot_idx_content_by_full_path(full_path):
    dot_idx_full_path = os.path.join(full_path, ".index.md")
    return commons.cat(dot_idx_full_path)