Example #1
0
    def __init__(
            self,
            source: str,
            parent: Optional[Directory] = None,
            **kwargs,
    ):
        with open(source) as f:
            contents = f.read()
            page_file = parse(contents)

        basename = os.path.basename(source)
        name = basename.split('.')[0]

        super().__init__(
            title=page_file.title,
            name=name,
            parent=parent,
            **kwargs,
        )

        self.source = source
        self.page_file = page_file
        with self.body_content:
            with Section(class_names=['overview']):
                H1(page_file.full_title)
                for note in page_file.notes:
                    P(note)
            for section in page_file.sections:
                with Section(class_names=['links']):
                    H1(section.title)
                    for note in section.notes:
                        P(note)
                    with Ul():
                        for link in section.links:
                            self.link(link)
 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)
     )
 def test_markup_for_empty_body(self):
     p = P()
     self.assertEqual(
         dedent(
             """\
             <p>
             """
         ),
         p.markup(width=80)
     )
 def test_markup(self):
     p = P('A sentence.')
     self.assertEqual(
         dedent(
             """\
             <p>
                 A sentence.
             """
         ),
         p.markup(width=80)
     )
 def test_markup_for_a_long_sentence(self):
     sentence = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
     p = P(sentence)
     self.assertEqual(
         dedent(
             """\
             <p>
                 Lorem ipsum dolor sit amet,
                 consectetur adipiscing elit, sed do
                 eiusmod tempor incididunt ut labore
                 et dolore magna aliqua.
             """
         ),
         p.markup(width=40)
     )
 def test_markup_for_a_sentence_with_leading_and_trailing_space(self):
     p = P(
         dedent("""
         A sentence.
         """)
     )
     self.assertEqual(
         dedent(
             """\
             <p>
                 A sentence.
             """
         ),
         p.markup(width=80)
     )
Example #7
0
def science_fiction():
    with Directory('science_fiction'):
        with Page('Science Fiction', name='index'):
            with Section(class_names=['overview']):
                H1('Science Fiction')
                P("""
                    Science fiction has been a staple of my reading diet since I was
                    very young.  I gravitate towards space opera; multi-book,
                    galaxy-spanning sagas are my bread and butter.
                """)
            with Ul(class_names=['collection']):
                item('Iain M Banks', '/science_fiction/iain_m_banks.html')
                item('Lois McMaster Bujold',
                     '/science_fiction/lois_mcmaster_bujold.html')
                item('James SA Corey', '/science_fiction/james_sa_corey.html')
                item('Alastair Reynolds', '/science_fiction/alastair_reynolds.html')
                item('David Weber', '/science_fiction/david_weber.html')
                item('Walter Jon Williams', '/science_fiction/walter_jon_williams.html')
 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)
     )
Example #9
0
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')
Example #10
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.'
            )
Example #11
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')