예제 #1
0
def read_tutorial(cat_id, page):
    tut = read_tutorial_page(cat_id, page)
    if tut is None:
        app.logger.info("No tutorial available for %s/%s" %
                        (cat_id, str(page)))
        return None
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub(
                '<em>{} hl_{}</em>'.format(text, idname),
                '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'
                .format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub(
                '<em>{} hlc_{}</em>'.format(text, classname),
                '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'
                .format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub(
        '</code>(\s)?</pre>',
        "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>",
        str(content))
    content = Markup(content)
    # check whether there is another tutorial in this category
    nxt = read_tutorial_page(cat_id, int(page) + 1)
    prev = read_tutorial_page(cat_id, int(page) - 1)

    out = dict()
    out['this'] = {
        'cat_id': tut.cat_title,
        'page': tut.page,
        'title': tut.title,
        'text': content
    }
    if nxt is not None:
        out['next'] = {
            'cat_id': nxt.cat_id,
            'page': nxt.page,
            'title': nxt.title
        }
    if prev is not None:
        out['prev'] = {
            'cat_id': prev.cat_id,
            'page': prev.page,
            'title': prev.title
        }

    return out
예제 #2
0
파일: tutorials.py 프로젝트: bbferka/docker
def read_tutorial(cat_id, page):
    tut = read_tutorial_page(cat_id, page)
    if tut==None:
        app.logger.info("No tutorial available for %s/%s" % (cat_id, str(page)))
        return None
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub('<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'.format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub('<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="highlightElement(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="highlightElement(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'.format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content))
    content = Markup(content)
    # check whether there is another tutorial in this category
    nxt  = read_tutorial_page(cat_id, int(page)+1)
    prev = read_tutorial_page(cat_id, int(page)-1)
    
    out = {}
    out['this'] = {
        'cat_id': tut.cat_title,
        'page': tut.page,
        'title': tut.title,
        'text': content
    }
    if(nxt != None):
        out['next'] = {
            'cat_id': nxt.cat_id,
            'page': nxt.page,
            'title': nxt.title
        }
    if(prev != None):
        out['prev'] = {
            'cat_id': prev.cat_id,
            'page': prev.page,
            'title': prev.title
        }
    
    return out
예제 #3
0
def tutorials(cat_id='getting_started', page=1):
    session['video'] = 0

    error = ""
    # determine hostname/IP we are currently using
    # (needed for accessing container)
    host_url = urlparse(request.host_url).hostname
    container_name = 'tutorials'
    show_south_pane = False
    readonly = True
    authentication = False

    tut = read_tutorial_page(cat_id, page)
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub(
                '<em>{} hl_{}</em>'.format(text, idname),
                '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'
                .format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub(
                '<em>{} hlc_{}</em>'.format(text, classname),
                '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'
                .format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub(
        '</code>(\s)?</pre>',
        "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>",
        str(content))
    content = Markup(content)

    # check whether there is another tutorial in this category
    nxt = read_tutorial_page(cat_id, int(page) + 1)
    prev = read_tutorial_page(cat_id, int(page) - 1)

    return render_template('knowrob_tutorial.html', **locals())
예제 #4
0
파일: views.py 프로젝트: macnlinux/docker
def tutorials(cat_id='getting_started', page=1):
    session['video'] = 0
    #if not ensure_application_started('knowrob/hydro-knowrob-daemon'):
    #    return redirect(url_for('user.logout'))
    
    error=""
    # determine hostname/IP we are currently using
    # (needed for accessing container)
    host_url = urlparse(request.host_url).hostname
    container_name = 'tutorials'
    show_south_pane = False
    readonly = True
    authentication = False

    tut = read_tutorial_page(cat_id, page)
    content = markdown(tut.text, fenced_code=True)

    # automatically add event handler for highlighting DOM elements
    tmp = re.findall('<em>(.*?)</em>', str(content))
    for t in tmp:
        if 'hl_' in t:
            text = t.split(' hl_')[0]
            idname = t.split(' hl_')[1]
            content = re.sub('<em>{} hl_{}</em>'.format(text, idname), '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;id&#39;, false)">{1}</em>'.format(idname, text), str(content))
        elif 'hlc_' in t:
            text = t.split(' hlc_')[0]
            classname = t.split(' hlc_')[1]
            content = re.sub('<em>{} hlc_{}</em>'.format(text, classname), '<em onmouseover="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, true)" onmouseout="knowrob.highlight_element(&#39;{0}&#39;, &#39;class&#39;, false)">{1}</em>'.format(classname, text), str(content))

    # automatically add "ask as query" links after code blocks
    content = re.sub('</code>(\s)?</pre>', "</code></pre><div class='show_code'><a href='#' class='show_code'>Ask as query</a></div>", str(content))
    content = Markup(content)

    # check whether there is another tutorial in this category
    nxt  = read_tutorial_page(cat_id, int(page)+1)
    prev = read_tutorial_page(cat_id, int(page)-1)

    return render_template('knowrob_tutorial.html', **locals())