コード例 #1
0
def render_footer(count):
    # Isolated fragments of doc are great for testing!
    doc = Doc()  # Note the missing doctype 'html', we skip it for fragments.
    hr()
    p('{} topic{} in wiki.'.format(count, '' if count == 1 else 's'),
      cls='footer-stats')
    return doc
コード例 #2
0
def render_index(stdout: list = None):
    doc = Doc('html')
    with head():
        meta(charset='utf-8')
        [meta(**{k: v}) for k, v in META.items()]
        title('Libiocage-GUI')
        with style():
            css.embed()
        with form(id='exec_form',
                  title='Type a command to run in a jail.',
                  ic__post__to='/exec',
                  ic__target='#stdout',
                  ic__indicator='#loading',
                  ):
            label('Execute in one-shot jail:', _for='#command', id='exec_label')
            _input(id='exec_input', name='command', autofocus=True,
                   ic__indicator='#loading',
                   )
            _input(id='exec_submit', type='submit', value='exec')
            img(src=url_for('static', filename='images/loader.gif'),
                alt='loading...', id='loading')
    with body():
        with div(id='stdout'):
            if stdout:
                render_stdout(doc, stdout)
        script(src=url_for('static', filename='js/jquery-3.3.1.min.js'),
               type='text/javascript')
        script(src=url_for('static', filename='js/intercooler-1.2.1.min.js'),
               type='text/javascript')
    return str(doc)
コード例 #3
0
def test_tag_context_2():
    from makeweb import Doc, h1, div
    doc = Doc()
    with div(id='atest'):
        h1('Hello, Test')
    h1('Hello, Test')
    assert str(doc) == \
           '<div id="atest"><h1>Hello, Test</h1></div><h1>Hello, Test</h1>'
コード例 #4
0
def test_css_embed():
    from makeweb import CSS, Doc, style
    css = CSS()
    css('body', background_color='black', color='green')
    doc = Doc()
    with style():
        css.embed()
    assert str(
        doc) == '<style>body{background-color:black;color:green}</style>'
コード例 #5
0
def render_search_results(query, results):
    doc = Doc()
    h3(render_search_form(query))
    with ul(id='search-results'):
        for topic, content in results.items():
            with li():
                h5(a(topic, href='/{}'.format(topic)))
                p(content)
    return doc
コード例 #6
0
def render_initial_timer(days, hours, minutes, seconds):
    doc = Doc()
    with span(days):
        i('days ')
    with span(hours):
        i('h ')
    with span(minutes):
        i('m ')
    with span(seconds):
        i('s ')
    return str(doc)
コード例 #7
0
def test_js_function_embed():
    from makeweb import JS, Doc, script
    js = JS()

    @js.function
    def test():
        alert('wut?')

    doc = Doc()
    with script():
        js.embed()
    assert str(doc) == '<script>function test(){alert("wut?");}</script>'
コード例 #8
0
def render_content_form(topic, content):
    doc = Doc()
    with form(action='/save', method='post'):
        _input(id='topic-box', name='topic', value=topic, hidden=True)
        div(
            textarea(content,
                     rows=10,
                     cols=35,
                     name='content',
                     id='content-box'))
        button('Save', id='content-save')
    return doc
コード例 #9
0
def test_js_script_embed():
    from makeweb import JS, Doc, script
    js = JS()

    @js.script
    def test():
        alert('wut?')

    doc = Doc()
    with script():
        js.embed()
    assert str(doc) == '<script>alert("wut?");</script>'
コード例 #10
0
async def search_fragment():
    data = await request.form
    command = data.get('command', '')
    if command:
        stdout = excute_command_in_jail(command)
    else:
        stdout = []
    doc = Doc()
    render_stdout(doc, stdout)
    # intercooler.js interprets empty response and single space as no-op,
    # send two spaces to clear target if response would be empty.
    return str(doc) or '  '
コード例 #11
0
def render_post(_title, author, published, content):
    doc = Doc(doctype='html')
    with head():
        title(_title)
        link(href='../static/retro.css', _type='text/css', rel='stylesheet')
    with body():
        with div(id='content'):
            h1(_title)
            h3(author)
            p(published)
            div(markdown(content))
    return str(doc)
コード例 #12
0
def index():
    doc = Doc('html')  # <-- html generation starts here...
    with head():
        title('Hello')
        with style():
            css.embed()
    with body():
        h1('...', id='hello_box')
        button('Hello', onclick="say_hello()")  # <-- hook up say_hello().
        with script():
            js.embed()
    return Response(str(doc))  # <-- ...and ends here.
コード例 #13
0
def test_doc():
    """
    https://html.spec.whatwg.org/multipage/syntax.html#the-doctype
    """
    # doctype must be included in generated html,
    # however, we allow Doc to generate fragments as well.
    # Therefore, doctype must be supplied at Doc init for a "full" document.
    from makeweb import Doc

    doc = Doc()
    assert str(doc) == ''

    fulldoc = str(Doc('html'))
    assert '<!doctype html>' in fulldoc
    assert '<html lang="en">' in fulldoc
    assert '</html>' in fulldoc

    with pytest.warns(UserWarning):
        Doc(doctype='zing')

    # Language can be supplied as well, default is 'en'.
    mrdoc = str(Doc('html', lang='mr'))
    assert '<!doctype html>' in mrdoc
    assert '<html lang="mr">' in mrdoc
コード例 #14
0
def render_index(_title, posts):
    doc = Doc('html')
    with head():
        title(_title)
        link(href='../static/retro.css', _type='text/css', rel='stylesheet')
    with body():
        with div(id='content'):
            for post in posts:
                with div():
                    a(h3(post['title']),
                      href='{}.html'.format(slugify(post['title'])))
                    content = post['content']
                    if len(content) > 50:
                        content = content[:50] + '...'
                    p(markdown(content))

    return str(doc)
コード例 #15
0
ファイル: hello-again.py プロジェクト: hiway/makeweb
def index():
    # First, define a variable named `doc` as an  instance of `Doc`.
    # (it is important, MakeWeb will fail if you call a tag
    # before defining a doc first).
    doc = Doc('html')
    # We also pass doctype='html' to tell Doc that
    # this is a complete html document
    # and we expect <!doctype html> and <html>, </html> tags
    # around the tags we define.
    # Omitting doctype will give us an html fragment,
    # more on it in later examples.

    # Create an h1 tag inside body.
    with body():
        h1('Hello, World Wide Web!')

    # Render the doc by calling str() on it
    # and return the generated html to browser.
    return Response(str(doc))
コード例 #16
0
def render_base(topic, content, create, count, results=False):
    # First, define a variable named `doc` as an  instance of `Doc`.
    # (it is important, MakeWeb will fail if you call a tag
    # before defining a doc first).
    doc = Doc('html')
    # With that in place, we can now generate our document structure.
    with head():
        meta(charset='utf-8')  # Define charset first.
        [meta(**{k: v}) for k, v in META.items()]  # Works with comprehensions.
        title(topic)  # Title is required for valid html.

        ## Uncomment the following line to apply a basic style.
        # link(href='/static/normalize.css', _type='text/css', rel='stylesheet')

        ## Try another, richer stylesheet? (source/credit at top of each file)
        ## Uncomment only one of these lines (or normalize.css) at a time.
        # link(href='/static/retro.css', _type='text/css', rel='stylesheet')
        # link(href='/static/air.css', _type='text/css', rel='stylesheet')
        # link(href='/static/ghpandoc.css', _type='text/css', rel='stylesheet')
        # link(href='/static/markdown.css', _type='text/css', rel='stylesheet')

        # Bare-minimum style tweaks.
        link(href='/static/app.css', _type='text/css', rel='stylesheet')
    with body(cls='markdown'):
        # Break apart pieces of template using familiarity of functions.
        # We pass `doc` to a template function that will modify
        # the `doc` we are refering to in render_base(), in place.
        render_nav(doc)
        # Higher-level structure stays within base template.
        with div(id='content-wrap'):
            # Pass in any variables along with doc
            # needed to render the template.
            render_content(doc, topic, content, create, results)
        # And now for something completely different...
        # Let us work with better isolation within the templates.
        # Below, we build a separate `doc` within render_footer()
        # and plug in the generated html straight into a div.
        # Doing so allows greater control over the overall layout from base.
        div(render_footer(count), id='footer')
    # We return rendered html by calling `str(doc)`.
    # `doc` is no longer in scope and will be removed from memory automatically.
    return str(doc)
コード例 #17
0
async def index():
    doc = Doc('html')
    with head():
        meta(name='charset', content='utf-8')
        [meta(name=k, content=v) for k, v in META.items()]
        title('Anon?Chat')
        with style():
            css.embed()
    with body():
        with div(cls='page'):
            with div(cls='incoming_wrapper'):
                with ul(id='chat_log'):
                    [li('&nbsp;') for x in range(50)]
                div('', id='bottom')
            _input(id='txt_message',
                   onkeyup="send_message(event)",
                   autofocus=True)
            button('⏎', onclick="send_message(event)", id='btn_send')
        with script():
            js.embed()
    return Response(str(doc))
コード例 #18
0
def index():
    doc = Doc('html')
    with head():
        title('Year 2038 problem')
        with style():
            css.embed()
    with body(onload='start_timer()'):
        # Exercise: calculate these numbers in advance, in Python,
        # and fill them in, letting the page be useful
        # even if a user has disabled JS
        # (with adtech giving us many good reasons to do so!).
        # As a rule, even in 2018, do not assume JS is available by default.
        div(render_initial_timer(days='0000',
                                 hours='00',
                                 minutes='00',
                                 seconds='00'),
            cls='timer j-timer')
        div(a('to January 19, 2038 03:14:07',
              href='https://en.wikipedia.org/wiki/Year_2038_problem'),
            cls='legend-wrap')
        script(src='/static/timezz.js')
        with script():  # You can comment out this block
            js.embed()  # to test render_initial_timer()
    return Response(str(doc))
コード例 #19
0
def test_text_tag():
    from makeweb import Doc, Text
    doc = Doc()
    Text("Namaskaar!")
    assert str(doc) == 'Namaskaar!'
コード例 #20
0
def test_tag_side_by_side():
    from makeweb import Doc, h1, div
    doc = Doc()
    h1('Hello, Test')
    div(id='atest')
    assert str(doc) == '<h1>Hello, Test</h1><div id="atest"></div>'
コード例 #21
0
def generate_html():
    doc = Doc('html')
    with body():
        h1('Ha!')
    return str(doc)
コード例 #22
0
def test_tag_nested():
    from makeweb import Doc, h1, div
    doc = Doc()
    div(h1('Hello, Test'), id='atest')
    assert str(doc) == '<div id="atest"><h1>Hello, Test</h1></div>'
コード例 #23
0
 def caller_func():
     doc = Doc(doctype='html')
     second_caller()
コード例 #24
0
 def caller_func():
     doc = Doc(doctype='html')
     test_magic()
コード例 #25
0
def test_tag_validation():
    from makeweb import Doc, h1, div
    doc = Doc()
    with pytest.raises(TypeError):
        div(35.2, id='atest')
    div(None)  # is ok, it is skipped from the Doc tree.
コード例 #26
0
def test_void_tag():
    from makeweb import Doc, img
    doc = Doc()
    img(alt='test')
    assert str(doc) == '<img alt="test" />'
コード例 #27
0
def render_search_form(query):
    doc = Doc()
    with form(action='/search', method='post'):
        _input(id='query', name='query', value=query)
        button('Search')
    return doc