Пример #1
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>'
Пример #2
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)
Пример #3
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.
Пример #4
0
def render_content(doc, topic, content, create, results):
    hr()
    if results:  # Don't link "Results for..."
        h1(topic, id='topic')
    elif create:  # When editing, clicking on topic h1 cancels edit operation.
        a(h1(topic, id='topic'), href='/{}'.format(topic), cls='topic-h1')
    else:  # When viewing, clicking on topic h1 opens edit form.
        a(h1(topic, id='topic'), href='/{}/edit'.format(topic), cls='topic-h1')
    if create:
        div(render_content_form(topic, content), id='content-edit')
    else:
        div(render_markdown(str(content)), id='content-display')
Пример #5
0
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))
Пример #6
0
def generate_html():
    doc = Doc('html')
    with body():
        h1('Ha!')
    return str(doc)
Пример #7
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>'
Пример #8
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>'