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