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(_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_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
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 render_nav(doc): with nav(): [li(a(k, href=v), cls='navli') for k, v in NAV.items()]