def test_tag_context_3(): from makeweb import Doc, h1, div doc = Doc() with div(id='atest'): h1('Hello, Test') h1('Hello, Test') with div(): h1('Ohai') assert str(doc) == \ '<div id="atest"><h1>Hello, Test</h1></div>\
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 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
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 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)
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)
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)
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(' ') 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))
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))
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.
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>'