예제 #1
0
 def test_markup_for_a_long_block_with_mixed_flow_and_phrasing_content(self):
     div = Div()
     with div:
         Text('Lorem ipsum dolor sit amet, ')
         Strong('consectetur')
         Text(' adipiscing elit, ')
         with P():
             Em('sed')
             Text(' do eiusmod tempor incididunt ut ')
         Strong('labore')
         Text(' et dolore magna aliqua.')
     self.assertEqual(
         dedent(
             """\
             <div>
                 Lorem ipsum dolor sit amet,
                 <strong>consectetur</strong>
                 adipiscing elit,
                 <p>
                     <em>sed</em> do eiusmod tempor
                     incididunt ut
                 </p>
                 <strong>labore</strong> et dolore
                 magna aliqua.
             </div>
             """
         ),
         div.markup(width=40)
     )
예제 #2
0
 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))
예제 #3
0
 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))
예제 #4
0
 def __init__(
         self,
         text: str,
         parent: Optional[Node] = None,
         **kwargs,
 ):
     super().__init__(name='button', parent=parent, **kwargs)
     Text(text, parent=self)
예제 #5
0
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(' ✓')
예제 #6
0
 def __init__(
         self,
         text: str,
         for_id: Optional[str] = None,
         parent: Optional[Node] = None,
         **kwargs
 ):
     super().__init__(name='label', parent=parent, **kwargs)
     if for_id:
         self.attributes['for'] = for_id
     Text(text, parent=self)
예제 #7
0
 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))
예제 #8
0
 def test_markup_for_long_line(self):
     line = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
     assert len(line) > 40
     text = Text(line)
     self.assertEqual(
         dedent(
             """\
             Lorem ipsum dolor sit amet, consectetur
             adipiscing elit, sed do eiusmod tempor
             incididunt ut labore et dolore magna
             aliqua."""
         ),
         text.markup(width=40)
     )
예제 #9
0
 def __init__(
         self,
         text: str,
         class_names: Optional[list[str]] = None,
         parent: Optional[Node] = None,
         **kwargs,
 ):
     super().__init__(
         name='span',
         class_names=class_names,
         parent=parent,
         **kwargs,
     )
     Text(text, parent=self)
예제 #10
0
 def __init__(
         self,
         datetime: str,
         class_names: Optional[list[str]] = None,
         parent: Optional[Node] = None,
         **kwargs,
 ):
     super().__init__(
         name='time',
         class_names=class_names,
         parent=parent,
         **kwargs,
     )
     self.attributes['datetime'] = datetime
     Text(datetime, parent=self)
예제 #11
0
 def test_markup_for_a_long_sentence_with_phrasing_content(self):
     p = P()
     with p:
         Text('Lorem ipsum dolor sit amet, ')
         Strong('consectetur')
         Text(' adipiscing elit, ')
         Em('sed')
         Text(' do eiusmod tempor incididunt ut ')
         Strong('labore')
         Text(' et dolore magna aliqua.')
     self.assertEqual(
         dedent(
             """\
             <p>
                 Lorem ipsum dolor sit amet,
                 <strong>consectetur</strong>
                 adipiscing elit, <em>sed</em> do
                 eiusmod tempor incididunt ut
                 <strong>labore</strong> et dolore
                 magna aliqua.
             """
         ),
         p.markup(width=40)
     )
예제 #12
0
 def __init__(
         self,
         href: str,
         text: Optional[str] = None,
         class_names: Optional[list[str]] = None,
         parent: Optional[Node] = None,
         **kwargs,
 ):
     super().__init__(
         name='a',
         class_names=class_names,
         parent=parent,
         **kwargs,
     )
     self.attributes['href'] = href
     if text:
         Text(text, parent=self)
예제 #13
0
 def test_tokens_multiple_spaces(self):
     text = Text(' \r\n\t')
     expected = [' ']
     self.assertEqual(expected, text.tokens())
예제 #14
0
def macos_packages():
    with Directory('macos_packages'):
        with Page('macOS Packages', name='index'):
            with Section(class_names=['overview']):
                H1('Signed and Notarized Universal macOS Installer Packages')
                with P():
                    Text(
                        'These standard macOS installer packages are built using '
                    )
                    Code('pkgbuild')
                    Text(' and ')
                    Code('productbuild')
                    Text(
                        ' and are signed and notarized with my Apple developer credentials.'
                    )
                    Text(
                        ' They install universal binaries that will run on both Intel and Apple Silicon Macs.'
                    )
                P("""
                    This is a collection of command line tools that I've found useful
                    at one time or another over the years. Some of them are widely used
                    but excluded from macOS and Xcode due to GPL licenses.            
                """)
            package(
                name='jq',
                version='1.6',
                package=
                'https://github.com/donmccaughey/jq_pkg/releases/latest/download/jq-1.6.pkg',
                source='https://github.com/donmccaughey/jq_pkg',
                project='https://stedolan.github.io/jq/',
                description=
                'A lightweight and flexible command line JSON processor')
            package(
                name='nginx',
                version='1.20.2',
                package=
                'https://github.com/donmccaughey/nginx_pkg/releases/latest/download/nginx-1.20.2.pkg',
                source='https://github.com/donmccaughey/nginx_pkg',
                project='https://nginx.org',
                description='A widely used and capable HTTP and proxy server')
            package(
                name='pkg-config',
                version='0.29.2',
                package=
                'https://github.com/donmccaughey/pkg-config_pkg/releases/latest/download/pkg-config-0.29.2.pkg',
                source='https://github.com/donmccaughey/pkg-config_pkg',
                project='https://www.freedesktop.org/wiki/Software/pkg-config/',
                description=
                'A helper tool used when compiling applications and libraries.'
            )
            package(
                name='tree',
                version='2.0.1',
                package=
                'https://github.com/donmccaughey/tree_pkg/releases/latest/download/tree-2.0.1.pkg',
                source='https://github.com/donmccaughey/tree_pkg',
                project='http://mama.indstate.edu/users/ice/tree/',
                description='A recursive directory listing command.')
            package(
                name='wget',
                version='1.21.2',
                package=
                'https://github.com/donmccaughey/wget_pkg/releases/latest/download/wget-1.21.2.pkg',
                source='https://github.com/donmccaughey/wget_pkg',
                project='https://www.gnu.org/software/wget/',
                description=
                'A command line tool for retrieving files using HTTP, HTTPS, FTP and FTPS.'
            )
            package(
                name='XZ Utils',
                version='5.2.5',
                package=
                'https://github.com/donmccaughey/xz_pkg/releases/latest/download/xz-5.2.5.pkg',
                source='https://github.com/donmccaughey/xz_pkg',
                project='https://tukaani.org/xz/',
                description=
                'A general purpose data compression tool and library, and includes the <code>xz</code> command line tool.'
            )
예제 #15
0
 def test_markup_for_short_line(self):
     text = Text('This is some text.')
     self.assertEqual(
         'This is some text.',
         text.markup(width=80)
     )
예제 #16
0
 def test_tokens_with_internal_whitespace(self):
     text = Text('This is \r\n \tsome text.')
     expected = ['This', ' ', 'is', ' ', 'some', ' ', 'text.']
     self.assertEqual(expected, text.tokens())
예제 #17
0
 def test_tokens_with_trailing_whitespace(self):
     text = Text('This is some text. \r\n')
     expected = ['This', ' ', 'is', ' ', 'some', ' ', 'text.', ' ']
     self.assertEqual(expected, text.tokens())
예제 #18
0
 def test_tokens_short_sentence(self):
     text = Text('This is some text.')
     expected = ['This', ' ', 'is', ' ', 'some', ' ', 'text.']
     self.assertEqual(expected, text.tokens())
예제 #19
0
 def test_tokens_single_space(self):
     text = Text(' ')
     expected = [' ']
     self.assertEqual(expected, text.tokens())
예제 #20
0
 def __init__(self, title: str, parent: Optional[Node] = None, **kwargs):
     super().__init__(name='title', parent=parent, **kwargs)
     Text(title, parent=self)
예제 #21
0
 def test_tokens_single_word(self):
     text = Text('foobar')
     expected = ['foobar']
     self.assertEqual(expected, text.tokens())
예제 #22
0
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')