Example #1
0
    def test_children_listing(self):
        self.assertEquals(len(model.WikiContent.get_all()), 0)

        model.WikiContent(title='foo/bar').put()
        model.WikiContent(title='foo/baz').put()
        self.assertEquals(len(model.WikiContent.get_all()), 2)

        self.assertEquals(util.wikify('[[ListChildren:foo]]'), u'<ul class="labellist"><li><a class="int" href="/foo/bar" title="foo/bar">foo/bar</a></li><li><a class="int" href="/foo/baz" title="foo/baz">foo/baz</a></li></ul>')
        self.assertEquals(util.wikify('[[ListChildren:]]', 'foo'), u'<ul class="labellist"><li><a class="int" href="/foo/bar" title="foo/bar">foo/bar</a></li><li><a class="int" href="/foo/baz" title="foo/baz">foo/baz</a></li></ul>')
Example #2
0
 def test_page_listing(self):
     self.assertEquals(util.wikify('[[List:foo]]'), '')
     model.WikiContent(
         title='bar',
         body='labels: foo\n---\n# bar\n\nHello, world.').put()
     model.WikiContent(
         title='baz',
         body='labels: foo\n---\n# baz\n\nHello, world.').put()
     self.assertEquals(
         util.wikify('[[List:foo]]'),
         u'<ul class="labellist"><li><a class="int" href="/bar" title="bar">bar</a></li><li><a class="int" href="/baz" title="baz">baz</a></li></ul>'
     )
Example #3
0
    def test_children_listing(self):
        self.assertEquals(len(model.WikiContent.get_all()), 0)

        model.WikiContent(title='foo/bar').put()
        model.WikiContent(title='foo/baz').put()
        self.assertEquals(len(model.WikiContent.get_all()), 2)

        self.assertEquals(
            util.wikify('[[ListChildren:foo]]'),
            u'<ul class="labellist"><li><a class="int" href="/foo/bar" title="foo/bar">foo/bar</a></li><li><a class="int" href="/foo/baz" title="foo/baz">foo/baz</a></li></ul>'
        )
        self.assertEquals(
            util.wikify('[[ListChildren:]]', 'foo'),
            u'<ul class="labellist"><li><a class="int" href="/foo/bar" title="foo/bar">foo/bar</a></li><li><a class="int" href="/foo/baz" title="foo/baz">foo/baz</a></li></ul>'
        )
Example #4
0
def list_pages(pages):
    logging.debug(u"Listing %u pages." % len(pages))

    def link_line(title):
        return (
            ("    " * title.count("/"))
            + "- "
            + ("[" + title + "](/" + title + ")" if ":" in title else "[[" + title + "]]")
        )

    lines = []
    for page in pages:
        title = page.title
        if "/" in title:
            parent = title[: title.rfind("/")]
            if not lines or lines[-1][0] != parent:
                parent_path = parent.split("/")
                for depth in xrange(1, len(parent_path) + 1):
                    target = "/".join(parent_path[:depth])
                    if not lines or not lines[-1][0].startswith(target):
                        lines.append((target, link_line(target)))
        lines.append((title, link_line(title)))
    return render(
        "index.html", {"pages": pages, "html": util.wikify(util.parse_markdown("\n".join(line[1] for line in lines)))}
    )
Example #5
0
def list_pages(pages):
    logging.debug(u'Listing %u pages.' % len(pages))

    def link_line(title):
        return ('    ' * title.count('/')) + '- ' + (
            '[' + title + '](/' + title + ')' if ':' in title else '[[' +
            title + ']]')

    lines = []
    for page in pages:
        title = page.title
        if '/' in title:
            parent = title[:title.rfind('/')]
            if not lines or lines[-1][0] != parent:
                parent_path = parent.split('/')
                for depth in xrange(1, len(parent_path) + 1):
                    target = '/'.join(parent_path[:depth])
                    if not lines or not lines[-1][0].startswith(target):
                        lines.append((target, link_line(target)))
        lines.append((title, link_line(title)))
    return render(
        'index.html', {
            'pages':
            pages,
            'html':
            util.wikify(
                util.parse_markdown('\n'.join(line[1] for line in lines))),
        })
Example #6
0
 def test_wikify(self):
     checks = [
         ('foo bar', 'foo bar'),
         # Basic linking.
         ('[[foo bar]]',
          '<a class="int missing" href="/w/edit?page=foo_bar" title="foo bar (create)">foo bar</a>'
          ),
         ('[[foo|bar]]',
          '<a class="int missing" href="/w/edit?page=foo" title="foo (create)">bar</a>'
          ),
         # Interwiki linking.
         ('[[google:hello]]',
          u'<a class="iw iw-google" href="http://www.google.ru/search?q=hello" target="_blank">hello</a>'
          ),
         ('[[missing:hello]]',
          '<a class="int missing" href="/w/edit?page=missing%3Ahello" title="missing:hello (create)">hello</a>'
          ),
         # Multiple links on the same line.
         ('[[foo]], [[bar]]',
          '<a class="int missing" href="/w/edit?page=foo" title="foo (create)">foo</a>, <a class="int missing" href="/w/edit?page=bar" title="bar (create)">bar</a>'
          ),
         # Check the typography features.
         ('foo. bar', 'foo. bar'),
         ('foo.  bar', 'foo.&nbsp; bar'),
         (u'foo  —  bar', u'foo&nbsp;— bar'),
         (u'foo  --  bar', u'foo&nbsp;— bar'),
     ]
     for got, wanted in checks:
         self.assertEquals(util.wikify(got), wanted)
Example #7
0
 def test_wikify(self):
     checks = [
         ('foo bar', 'foo bar'),
         # Basic linking.
         ('[[foo bar]]', '<a class="int missing" href="/w/edit?page=foo_bar" title="foo bar (create)">foo bar</a>'),
         ('[[foo|bar]]', '<a class="int missing" href="/w/edit?page=foo" title="foo (create)">bar</a>'),
         # Interwiki linking.
         ('[[google:hello]]', u'<a class="iw iw-google" href="http://www.google.ru/search?q=hello" target="_blank">hello</a>'),
         ('[[missing:hello]]', '<a class="int missing" href="/w/edit?page=missing%3Ahello" title="missing:hello (create)">hello</a>'),
         # Multiple links on the same line.
         ('[[foo]], [[bar]]', '<a class="int missing" href="/w/edit?page=foo" title="foo (create)">foo</a>, <a class="int missing" href="/w/edit?page=bar" title="bar (create)">bar</a>'),
         # Check the typography features.
         ('foo. bar', 'foo. bar'),
         ('foo.  bar', 'foo.&nbsp; bar'),
         (u'foo  —  bar', u'foo&nbsp;— bar'),
         (u'foo  --  bar', u'foo&nbsp;— bar'),
     ]
     for got, wanted in checks:
         self.assertEquals(util.wikify(got), wanted)
Example #8
0
def list_pages(pages):
    logging.debug(u'Listing %u pages.' % len(pages))
    def link_line(title):
        return ('    ' * title.count('/')) + '- ' + ('[' + title + '](/' + title + ')' if ':' in title else '[[' + title + ']]')
    lines = []
    for page in pages:
        title = page.title
        if '/' in title:
            parent = title[:title.rfind('/')]
            if not lines or lines[-1][0] != parent:
                parent_path = parent.split('/')
                for depth in xrange(1, len(parent_path)+1):
                    target = '/'.join(parent_path[:depth])
                    if not lines or not lines[-1][0].startswith(target):
                        lines.append((target, link_line(target)))
        lines.append((title, link_line(title)))
    return render('index.html', {
        'pages': pages,
        'html': util.wikify(util.parse_markdown('\n'.join(line[1] for line in lines))),
    })
Example #9
0
 def test_page_listing(self):
     self.assertEquals(util.wikify('[[List:foo]]'), '')
     model.WikiContent(title='bar', body='labels: foo\n---\n# bar\n\nHello, world.').put()
     model.WikiContent(title='baz', body='labels: foo\n---\n# baz\n\nHello, world.').put()
     self.assertEquals(util.wikify('[[List:foo]]'), u'<ul class="labellist"><li><a class="int" href="/bar" title="bar">bar</a></li><li><a class="int" href="/baz" title="baz">baz</a></li></ul>')