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>')
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>' )
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>' )
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)))} )
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))), })
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. bar'), (u'foo — bar', u'foo — bar'), (u'foo -- bar', u'foo — bar'), ] for got, wanted in checks: self.assertEquals(util.wikify(got), wanted)
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. bar'), (u'foo — bar', u'foo — bar'), (u'foo -- bar', u'foo — bar'), ] for got, wanted in checks: self.assertEquals(util.wikify(got), wanted)
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))), })
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>')