Exemple #1
0
    def test_parse_yaml(self):
        inp = (u'index.markdown\n')
        sitemap = self.__parse_sitemap(inp)
        self.__create_md_file(
            'index.markdown',
            (u'---\n'
             'title: A random title\n'
             'symbols: [symbol_1, symbol_2]\n'
             '...\n'
             '# My documentation\n'))

        self.tree.parse_sitemap(sitemap)

        pages = self.tree.get_pages()
        page = pages.get('index.markdown')

        out, _ = cmark.ast_to_html(page.ast, None)

        self.assertEqual(
            out,
            u'<h1>My documentation</h1>\n')

        self.assertEqual(page.title, u'A random title')

        self.assertEqual(
            page.symbol_names,
            OrderedSet(['symbol_1',
                        'symbol_2']))
Exemple #2
0
    def format(self, formatter, link_resolver, output):
        """
        Banana banana
        """

        if not self.title and self.source_file:
            title = os.path.splitext(self.source_file)[0]
            self.title = os.path.basename(title).replace('-', ' ')

        self.formatted_contents = u''

        if self.ast:
            out, diags = cmark.ast_to_html(self.ast, link_resolver)
            for diag in diags:
                warn(
                    diag.code,
                    message=diag.message,
                    filename=self.source_file)

            self.formatted_contents += out
        else:
            self.__format_page_comment(formatter, link_resolver)

        self.output_attrs = defaultdict(lambda: defaultdict(dict))
        formatter.prepare_page_attributes(self)
        Page.formatting_signal(self, formatter)
        self.__format_symbols(formatter, link_resolver)
        self.detailed_description =\
            formatter.format_page(self)[0]

        if output:
            formatter.write_page(self, output)
Exemple #3
0
    def test_parse_yaml(self):
        inp = (u'index.markdown\n')
        sitemap = self.__parse_sitemap(inp)
        self.__create_md_file(
            'index.markdown',
            (u'---\n'
             'title: A random title\n'
             'symbols: [symbol_1, symbol_2]\n'
             '...\n'
             '# My documentation\n'))

        doc_tree = DocTree(self.__priv_dir, self.include_paths)
        doc_tree.parse_sitemap(self.change_tracker, sitemap)

        pages = doc_tree.get_pages()
        page = pages.get('index.markdown')
        self.assertEqual(
            cmark.ast_to_html(page.ast, None),
            u'<h1>My documentation</h1>\n')

        self.assertEqual(page.title, u'A random title')

        self.assertEqual(
            page.symbol_names,
            OrderedSet(['symbol_1',
                        'symbol_2']))
Exemple #4
0
    def format(self, formatter, link_resolver, output):
        """
        Banana banana
        """

        if not self.title and self.source_file:
            title = os.path.splitext(self.source_file)[0]
            self.title = os.path.basename(title).replace('-', ' ')

        self.formatted_contents = u''

        self.build_path = os.path.join(formatter.get_output_folder(self),
                                       self.link.ref)

        if self.ast:
            out, diags = cmark.ast_to_html(self.ast, link_resolver)
            for diag in diags:
                warn(diag.code,
                     message=diag.message,
                     filename=self.source_file)

            self.formatted_contents += out

        if not self.formatted_contents:
            self.__format_page_comment(formatter, link_resolver)

        self.output_attrs = defaultdict(lambda: defaultdict(dict))
        formatter.prepare_page_attributes(self)
        self.__format_symbols(formatter, link_resolver)
        self.detailed_description =\
            formatter.format_page(self)[0]

        if output:
            formatter.cache_page(self)
Exemple #5
0
    def test_parse_yaml(self):
        conf = {'project_name': 'test',
                'project_version': '1.0'}
        inp = (u'index.markdown\n')
        conf['sitemap'] = self.__write_sitemap(inp)
        conf['index'] = self.__create_md_file(
            'index.markdown',
            (u'---\n'
             'title: A random title\n'
             '...\n'
             '# My documentation\n'))

        conf = self.__make_config(conf)
        self.app.parse_config(conf)
        self.app.run()

        pages = self.app.project.tree.get_pages()
        page = pages.get('index.markdown')

        out, _ = cmark.ast_to_html(page.ast, None)

        self.assertEqual(
            out,
            u'<h1>My documentation</h1>\n')

        self.assertEqual(page.title, u'A random title')
Exemple #6
0
    def format(self, formatter, link_resolver, output):
        """
        Banana banana
        """
        if self.ast:
            self.formatted_contents =\
                cmark.ast_to_html(self.ast, link_resolver)

        elif self.comment:
            if self.comment.short_description:
                ast = cmark.gtkdoc_to_ast(self.comment.short_description,
                                          link_resolver)
                self.short_description =\
                    cmark.ast_to_html(ast, link_resolver).strip()
                if self.short_description.startswith('<p>'):
                    self.short_description = self.short_description[3:-4]
            if self.comment.title:
                ast = cmark.gtkdoc_to_ast(self.comment.title,
                                          link_resolver)
                self.title =\
                    cmark.ast_to_html(ast, link_resolver).strip()
                if self.title.startswith('<p>'):
                    self.title = self.title[3:-4]
                description = u'# %s\n\n%s\n' % (self.comment.title,
                                                 self.comment.description)
            else:
                description = self.comment.description
                self.title = self.source_file

            ast = cmark.gtkdoc_to_ast(description, link_resolver)
            self.formatted_contents =\
                cmark.ast_to_html(ast, link_resolver)

        if not self.title and self.source_file:
            self.title = os.path.splitext(self.source_file)[0]

        self.output_attrs = defaultdict(lambda: defaultdict(dict))
        formatter.prepare_page_attributes(self)
        Page.formatting_signal(self, formatter)
        self.__format_symbols(formatter, link_resolver)
        self.detailed_description =\
            formatter.format_page(self)[0]

        if output:
            formatter.write_page(self, output)
Exemple #7
0
 def test_modified_link(self):
     inp = u"this : #foo is a link !"
     ast, _ = self.assertOutputs(
         inp, '<p>this : <a href="here.com">foo</a> is a link !</p>\n')
     self.link_resolver.upsert_link(Link("there.com", "ze_foo", "foo"),
                                    overwrite_ref=True)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     self.assertEqual(
         out, u'<p>this : <a href="there.com">ze_foo</a> is a link !</p>\n')
Exemple #8
0
    def ast_to_html(self, ast, link_resolver):
        """
        See the documentation of `to_ast` for
        more information.

        Args:
            ast: PyCapsule, a capsule as returned by `to_ast`
            link_resolver: hotdoc.core.links.LinkResolver, a link
                resolver instance.
        """
        return cmark.ast_to_html(ast, link_resolver)
Exemple #9
0
 def test_modified_link(self):
     inp = u"this : #foo is a link !"
     ast, _ = self.assertOutputs(
         inp, '<p>this : <a href="here.com">foo</a> is a link !</p>\n')
     self.link_resolver.upsert_link(
         Link("there.com", "ze_foo", "foo"),
         overwrite_ref=True)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     self.assertEqual(
         out,
         u'<p>this : <a href="there.com">ze_foo</a> is a link !</p>\n')
Exemple #10
0
    def __format_content(self, formatter, link_resolver):
        if self.ast:
            out, diags = cmark.ast_to_html(self.ast, link_resolver)
            for diag in diags:
                warn(
                    diag.code,
                    message=diag.message,
                    filename=self.source_file or self.name)
            self.formatted_contents += out

        if not self.formatted_contents:
            self.__format_page_comment(formatter, link_resolver)
    def ast_to_html(self, ast, link_resolver):
        """
        See the documentation of `to_ast` for
        more information.

        Args:
            ast: PyCapsule, a capsule as returned by `to_ast`
            link_resolver: hotdoc.core.links.LinkResolver, a link
                resolver instance.
        """
        out, _ = cmark.ast_to_html(ast, link_resolver)
        return out
Exemple #12
0
    def test_extension_override(self):
        self.__create_md_file('source_a.test.markdown', (u'# My override\n'))
        _ = self.__create_test_layout()
        page = self.tree.get_pages()['source_a.test']

        self.assertEqual(page.symbol_names,
                         OrderedSet(['symbol_1', 'symbol_2']))

        self.assertEqual(os.path.basename(page.source_file),
                         'source_a.test.markdown')

        out, _ = cmark.ast_to_html(page.ast, None)

        self.assertEqual(out, u'<h1>My override</h1>\n')
Exemple #13
0
    def test_extension_implicit_override(self):
        self.__create_md_file(
            'source_b.test.markdown',
            (u'---\nsymbols:\n  - symbol_2\n...\n# My override\n'))
        _ = self.__create_test_layout()

        source_b = self.tree.get_pages()['source_b.test']
        self.assertEqual(os.path.basename(source_b.source_file),
                         'source_b.test.markdown')
        self.assertEqual(source_b.symbol_names, ['symbol_2', 'symbol_4'])

        source_a = self.tree.get_pages()['source_a.test']
        self.assertEqual(source_a.symbol_names, ['symbol_1'])

        out, _ = cmark.ast_to_html(source_b.ast, None)

        self.assertEqual(out, u'<h1>My override</h1>\n')
Exemple #14
0
    def test_extension_override(self):
        self.__create_md_file(
            'source_a.test.markdown',
            (u'# My override\n'))
        doc_tree, _ = self.__create_test_layout()
        page = doc_tree.get_pages()['source_a.test']

        self.assertEqual(
            page.symbol_names,
            OrderedSet(['symbol_1',
                        'symbol_2']))

        self.assertEqual(
            os.path.basename(page.source_file),
            'source_a.test.markdown')

        self.assertEqual(
            cmark.ast_to_html(page.ast, None),
            u'<h1>My override</h1>\n')
Exemple #15
0
    def format(self, formatter, link_resolver, root, output):
        """
        Banana banana
        """

        if not self.title and self.source_file:
            title = os.path.splitext(self.source_file)[0]
            self.title = os.path.basename(title).replace('-', ' ')

        self.formatted_contents = u''

        self.build_path = os.path.join(
            os.path.relpath(formatter.get_output_folder(),
                            'html').lstrip('./'),
            self.link.ref)
        Link.relativize_link_signal.connect(self.__relativize_link_cb)

        if self.ast:
            out, diags = cmark.ast_to_html(self.ast, link_resolver)
            for diag in diags:
                warn(
                    diag.code,
                    message=diag.message,
                    filename=self.source_file)

            self.formatted_contents += out
        else:
            self.__format_page_comment(formatter, link_resolver)

        self.output_attrs = defaultdict(lambda: defaultdict(dict))
        formatter.prepare_page_attributes(self)
        Page.formatting_signal(self, formatter)
        self.__format_symbols(formatter, link_resolver)
        self.detailed_description =\
            formatter.format_page(self)[0]

        Link.relativize_link_signal.disconnect(self.__relativize_link_cb)

        if output:
            formatter.write_page(self, root, output)
Exemple #16
0
 def assertOutputs(self, inp, expected):
     ast, _ = cmark.gtkdoc_to_ast(inp, self.link_resolver)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     self.assertEqual(out, expected)
Exemple #17
0
 def render(self, inp):
     ast = cmark.hotdoc_to_ast(inp, None)
     out = cmark.ast_to_html(ast, None)[0]
     return ast, out
Exemple #18
0
 def render(self, inp):
     ast = cmark.hotdoc_to_ast(inp, self.include_resolver)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     return ast, out
Exemple #19
0
 def assertOutputs(self, inp, expected):
     ast = cmark.hotdoc_to_ast(inp, self.include_resolver)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     self.assertEqual(out, expected)
     return out, ast
Exemple #20
0
 def assertOutputs(self, inp, expected):
     ast, _ = cmark.gtkdoc_to_ast(inp, self.link_resolver)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     self.assertEqual(out, expected)
Exemple #21
0
 def assertOutputs(self, inp, expected):
     ast, diagnostics = cmark.gtkdoc_to_ast(inp, self.link_resolver, None,
                                            None)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     self.assertEqual(out, expected)
     return ast, diagnostics
Exemple #22
0
 def render(self, inp):
     ast = cmark.hotdoc_to_ast(inp, None)
     out = cmark.ast_to_html(ast, None)[0]
     return ast, out
Exemple #23
0
 def render(self, inp):
     ast = cmark.hotdoc_to_ast(inp, self.include_resolver)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     return ast, out
Exemple #24
0
 def assertOutputs(self, inp, expected):
     ast = cmark.hotdoc_to_ast(inp, self.include_resolver)
     out = cmark.ast_to_html(ast, self.link_resolver)[0]
     self.assertEqual(out, expected)
     return out, ast