def test_markup(self): ul = Ul() with ul: with Li(): Text('First Item') with Li(): Text('Second Item') self.assertEqual( dedent("""\ <ul> <li>First Item <li>Second Item </ul> """), ul.markup(width=80))
def test_markup_when_sibling_is_a_comment(self): ul = Ul() with ul: with Li(): Text('First Item') Comment('foobar') with Li(): Text('Second Item') self.assertEqual( dedent("""\ <ul> <li>First Item</li> <!-- foobar --> <li>Second Item </ul> """), ul.markup(width=80))
def test_markup_for_long_content_when_sibling_is_a_comment(self): lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' ul = Ul() with ul: with Li(): Text(lorem) Comment('foobar') with Li(): Text(lorem) self.assertEqual( dedent("""\ <ul> <li> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </li> <!-- foobar --> <li> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </ul> """), ul.markup(width=80))
def package( name: str, version: str, package: str, source: str, project: str, description: str, ): with Section(class_names=['package']): H1(f'{name} {version}') P(description) with Ul(class_names=['collection']): with Li(class_names=['item']): with A(package): Img('./package-32x32.png', 'package icon', class_names=['favicon']) Strong('package') with Li(class_names=['item']): with A(source): Img('./source-32x32.png', 'source icon', class_names=['favicon']) Strong('source') with Li(class_names=['item']): with A(project): Img('./project-32x32.png', 'project icon', class_names=['favicon']) Strong('project')
def item( title: str, href: str, subtitle: Optional[str] = None, favicon: Optional[str] = None, external: bool = False, ): class_names = ['item'] + (['external'] if external else []) with Li(class_names=class_names): with A(href=href): if favicon: Img(class_names=['favicon'], src=favicon, alt=f'{title} icon') Strong(title) if subtitle: Br() Em(subtitle)
def link( modifier: str, title: str, href: str, authors: Sequence[str] = (), date: Optional[str] = None, checked: bool = False ): with Li(class_names=[modifier]): A(href=href, text=title, class_names=['title']) if authors: Text(', ') Span(class_names=['authors'], text=join_authors(list(authors))) if date: Text(', ') Time(datetime=date) if checked: Text(' ✓')
def random_words(): with Directory('random_words'): with Page('Random Words', name='index') as page: page.add_stylesheet('random_words.css') page.add_script('random_words.js') with Section(class_names=['overview']): H1('Random Words') P(""" <em>Random Words</em> is a small program that chooses random entries from <a href=https://github.com/elasticdog/yawl>YAWL</a>, a public domain list of 264,097 English words. """) with Section(class_names=['generator']): H1('Results') P(id='random_words') with Form(action='./', method='GET'): with P(): Label('Number of Words:', for_id='count') Input(id='count', type='number', value='0') with P(): Label('Format:') Input(id='format_sentence', name='format', type='radio', value='sentence', checked=True) Label('Sentence', for_id='format_sentence') Input(id='format_list', name='format', type='radio', value='list') Label('List', for_id='format_list') with P(): Button('Go') with Section(id='implementation'): H1('Implementation') with P(): Text(""" <em>Random Words</em> is written in JavaScript and runs in the browser. To avoid the need to fetch the whole 2.7 MB YAWL <a href=word.list><code>word.list</code></a> file, I've converted <code>word.list</code> into a <a href=words.table>table</a> where each word is padded with spaces to 45 characters, the length of the """) A( 'https://en.wikipedia.org/wiki/Pneumonoultramicroscopicsilicovolcanoconiosis', 'longest word') Text(""" in the list. """) with P(): Text(""" The program uses the """) A( 'https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues', '<code>getRandomValues()</code>') Text(""" function to generate a random number in the range [0, 264097) to select a word, then uses the HTTP """) A('https://tools.ietf.org/html/rfc7233#section-3.1', 'Range header') Text(""" to fetch only that word from the table. """) with P(): with Ul(): with Li(): A('random_words.js', 'The JavaScript code') with Li(): A('word.list', 'The YAWL word list') with Li(): A('make_table.py', 'The Python script to generate the words table') with Li(): A('words.table', 'The table of padded words')