Пример #1
0
def mathjax(tree, embed=True, params=None):
    body = tree[1]
    params = params or {}
    config_path = params.get("config")
    url = params.get("url", "http://cdn.mathjax.org/mathjax/latest/MathJax.js")

    if config_path is None:
        content = """
      MathJax.Hub.Config({
        extensions: [],
        jax: ["input/TeX", "output/HTML-CSS"],
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"] ],
          displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
          processEscapes: true
        },
        "HTML-CSS": { availableFonts: ["TeX"] }
      });
        """
    else:
        with open(config_path) as f_in:
            content = f_in.read()

    body.append(html.Script(content, type="text/x-mathjax-config"))
    body.append(html.Script(src=url))
Пример #2
0
def js_fullpath(path, embed=True):
    content = open(path).read().decode('utf-8')

    if embed:
        return html.Script(content)
    else:
        return html.Script(src=path)
Пример #3
0
def view_handler(h, p=None):
    global opts
    # Удаление комментария
    if h.method != 'GET':
        if db.delete_comment(h.id) is True:
            msg = "Комментарий успешно удален"
        else:
            msg = "При удалении комментария произошла ошибка"
    # Таблица с комментариями
    comments = db.select_comment()
    table = ''
    for comment in comments:
        table += "<tr>\r\n"
        for item in comment:
            table += "<td>%s</td>\r\n" % (item if item is not None else '-')
        table += "<td onclick=\"javascript:remove_comment(%s)\"><span>x</span></td>\r\n" % comment[
            0]
        table += "</tr>\r\n"
    headers = [
        '#', 'Фамилия', 'Имя', 'Отчество', 'Телефон', 'E-mail', 'Город',
        'Регион', 'Комментарий', 'Удалить', table
    ]
    html = view.HTMLObject('Комментарии')
    html.Script(func=view.view_script)
    html.Style(func=view.main_css, param=dict(filename=opts.css_file))
    html.Body(func=view.view_table, content=headers)
    return str(html)
Пример #4
0
def impressjs(tree, embed=True, params=None):
    head = tree[0]
    body = tree[1]

    def path(*args):
        return join_path("thirdparty", "impressjs", *args)

    # remove the default style
    #head.remove(head.find("./style"))
    add_class(body, "impress-not-supported")
    failback = html.Div(
        '<div class="fallback-message">' +
        '<p>Your browser <b>doesn\'t support the features required</b> by' +
        'impress.js, so you are presented with a simplified version of this' +
        'presentation.</p>' +
        '<p>For the best experience please use the latest <b>Chrome</b>,' +
        '<b>Safari</b> or <b>Firefox</b> browser.</p></div>')

    slides = html.Div(id="impress")

    for item in list(body):
        body.remove(item)
        slides.append(item)

    body.append(slides)

    # <script src="js/impress.js"></script>
    body.append(js(path("js", "impress.js"), embed))

    body.append(html.Script("impress().init();"))
Пример #5
0
def revealjs(tree, embed=True, params=None):
    head = tree[0]
    body = tree[1]
    params = params or {}
    theme_name = params.pop("theme", "default") + ".css"

    def path(*args):
        return join_path("thirdparty", "revealjs", *args)

    add_class(body, "reveal")
    slides = html.Div(class_="slides")

    for item in list(body):
        body.remove(item)
        slides.append(item)

    body.append(slides)

    # <link rel="stylesheet" href="css/reveal.css">
    # <link rel="stylesheet" href="css/theme/default.css" id="theme">
    head.append(css(path("css", "reveal.css"), embed))
    head.append(css(path("css", "theme", theme_name), embed))

    # <script src="lib/js/head.min.js"></script>
    # <script src="js/reveal.min.js"></script>
    body.append(js(path("lib", "js", "head.min.js"), embed))
    body.append(js(path("js", "reveal.min.js"), embed))

    head.append(css("rst2html5-reveal.css", embed))

    params['history'] = True
    param_s = json.dumps(params)
    body.append(
        html.Script("$(function () { Reveal.initialize(%s); });" % param_s))
Пример #6
0
def pretty_print_code(tree, embed=True, params=None):
    head = tree[0]
    body = tree[1]

    body.append(js(join_path("thirdparty", "prettify.js"), embed))
    body.append(html.Script("$(function () { prettyPrint() })"))

    head.append(css(join_path("thirdparty", "prettify.css")))
Пример #7
0
def comment_handler(h, p=None):
    global opts
    msg = ''
    # Добавление комментария
    if h.method != 'GET':
        try:
            db.insert_comment(p)
        except db.DBException as e:
            msg = e.message
        except:
            msg = "При добавлении комментария произошла ошибка"
        else:
            msg = "Комментарий добавлен успешно"
        msg = "alert('%s')" % msg
    html = view.HTMLObject('Оставить комментарий')
    html.Script(func=view.comment_script, content=msg)
    html.Style(func=view.main_css, param=dict(filename=opts.css_file))
    html.Body(func=view.html_form)
    return str(html)
Пример #8
0
def deckjs(tree, embed=True, params=None):
    head = tree[0]
    body = tree[1]

    def path(*args):
        return join_path("thirdparty", "deckjs", *args)

    head.remove(head.find("./style"))
    add_class(body, "deck-container")

    for section in tree.findall(".//section"):
        add_class(section, "slide")

    # Core and extension CSS files
    head.append(css(path("core", "deck.core.css"), embed))
    head.append(css(path("extensions", "goto", "deck.goto.css"), embed))
    head.append(css(path("extensions", "menu", "deck.menu.css"), embed))
    head.append(
        css(path("extensions", "navigation", "deck.navigation.css"), embed))
    head.append(css(path("extensions", "status", "deck.status.css"), embed))
    head.append(css(path("extensions", "hash", "deck.hash.css"), embed))

    # Theme CSS files (menu swaps these out)
    head.append(css(path("themes", "style", "web-2.0.css"), embed))
    head.append(
        css(path("themes", "transition", "horizontal-slide.css"), embed))

    body.append(js(path("modernizr.custom.js"), embed))
    jquery(tree, embed)

    # Deck Core and extensions
    body.append(js(path("core", "deck.core.js"), embed))
    body.append(js(path("extensions", "hash", "deck.hash.js"), embed))
    body.append(js(path("extensions", "menu", "deck.menu.js"), embed))
    body.append(js(path("extensions", "goto", "deck.goto.js"), embed))
    body.append(js(path("extensions", "status", "deck.status.js"), embed))
    body.append(
        js(path("extensions", "navigation", "deck.navigation.js"), embed))

    body.append(html.Script("$(function () { $.deck('.slide'); });"))