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>'
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)
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.
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')
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))
def generate_html(): doc = Doc('html') with body(): h1('Ha!') return str(doc)
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>'
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>'