def test_toc(self): pod = testing.create_pod() pod.write_yaml('/podspec.yaml', { 'markdown': { 'extensions': [{ 'kind': 'toc', }], } }) pod.write_yaml('/content/pages/_blueprint.yaml', { '$view': '/views/base.html', '$path': '/{base}/' }) pod.write_file('/content/pages/test.md', textwrap.dedent( """\ [TOC] # H1 ## H2 ### H3 ## H2 A """)) pod.write_file('/views/base.html', '{{doc.html|safe}}') pod.router.add_all() result = testing.render_path(pod, '/test/') toc_sentinel = '<div class="toc">' toclink_sentinel = '<a class="toclink"' title_sentinel = '<span class="toctitle">toc-title</span>' para_sentinel = '¶' sep_sentinel = 'h2_a' h2_sentinel = '<h2' self.assertIn(toc_sentinel, result) self.assertNotIn(title_sentinel, result) self.assertNotIn(toclink_sentinel, result) self.assertNotIn(sep_sentinel, result) self.assertNotIn(para_sentinel, result) self.assertIn(h2_sentinel, result) pod.write_yaml('/podspec.yaml', { 'markdown': { 'extensions': [{ 'kind': 'toc', 'title': 'toc-title', 'baselevel': 3, 'anchorlink': True, 'permalink': True, 'separator': '_' }], } }) pod = pods.Pod(pod.root) pod.router.add_all() result = testing.render_path(pod, '/test/') self.assertIn(title_sentinel, result) self.assertNotIn(h2_sentinel, result) self.assertIn(toclink_sentinel, result) self.assertIn(sep_sentinel, result) self.assertIn(para_sentinel, result)
def test_noclasses(self): pod = testing.create_pod() fields = { 'markdown': { 'extensions': [{ 'kind': 'sourcecode', }], } } pod.write_yaml('/podspec.yaml', fields) fields = {'$view': '/views/base.html', '$path': '/{base}/'} pod.write_yaml('/content/pages/_blueprint.yaml', fields) content = """ [sourcecode:html] <div class="test"> Hello World </div> [/sourcecode] """ pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' pod.write_file('/views/base.html', content) pod.router.add_all(use_cache=False) result = testing.render_path(pod, '/test/') style_sentinel = 'style="background: #f8f8f8"' self.assertIn(style_sentinel, result) # Verify no language. content = """ [sourcecode] <div class="test"> Hello World </div> [/sourcecode] """ pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' pod.write_file('/views/base.html', content) pod.router.add_all(use_cache=False) result = testing.render_path(pod, '/test/') style_sentinel = 'style="background: #f8f8f8"' self.assertIn(style_sentinel, result) fields = { 'markdown': { 'extensions': [{ 'kind': 'sourcecode', 'highlighter': 'plain', 'classes': True, }], } } pod.write_yaml('/podspec.yaml', fields) pod = pods.Pod(pod.root) pod.router.add_all(use_cache=False) result = testing.render_path(pod, '/test/') code_sentinel = '<div class="code"><pre>' self.assertIn(code_sentinel, result)
def test_dependency_nesting_jinja(self): # Verify that dependencies work for nested documents. pod = testing.create_pod() pod.write_yaml('/podspec.yaml', { 'localization': { 'default_locale': 'en', 'locales': [ 'de', 'en', ], } }) pod.write_yaml( '/content/pages/_blueprint.yaml', { '$path': '/{base}/', '$view': '/views/base.html', '$localization': { 'path': '/{locale}/{base}/' }, }) pod.write_file('/content/pages/page.yaml', 'partial: !g.doc /content/partials/partial.yaml') pod.write_yaml('/content/partials/_blueprint.yaml', {}) pod.write_yaml('/content/partials/partial.yaml', {}) pod.write_yaml('/content/partials/[email protected]', {}) pod.write_file( '/views/base.html', '{}{} {}'.format( '{{doc.locale}}', '{% for partial in g.docs(\'partials\') %} {{partial.locale}}{% endfor %}', '{{g.doc(\'/content/partials/partial.yaml\').locale}}', ), ) pod.router.add_all() content = testing.render_path(pod, '/page/') self.assertEqual('en en en', content) dependents = pod.podcache.dependency_graph.get_dependents( '/content/partials/partial.yaml') self.assertEqual( set([ '/content/partials/partial.yaml', '/content/pages/page.yaml', ]), dependents) content = testing.render_path(pod, '/de/page/') self.assertEqual('de de de', content) dependents = pod.podcache.dependency_graph.get_dependents( '/content/partials/[email protected]') self.assertEqual( set([ '/content/partials/[email protected]', '/content/pages/page.yaml', ]), dependents)
def test_localization_fallback(self): # Verify locales aren't clobbered when no localized path is specified. pod = testing.create_pod() pod.write_yaml('/podspec.yaml', { 'localization': { 'default_locale': 'en', 'locales': [ 'de', 'en', ], } }) pod.write_yaml('/content/pages/_blueprint.yaml', { '$path': '/{base}/', '$view': '/views/base.html', }) pod.write_yaml('/content/pages/page.yaml', {}) pod.write_file('/views/base.html', '{{doc.locale}}') pod.write_yaml( '/content/pages/_blueprint.yaml', { '$path': '/{base}/', '$view': '/views/base.html', '$localization': None, }) pod.router.add_all() content = testing.render_path(pod, '/page/') self.assertEqual('en', content) # Verify paths aren't clobbered by the default locale. pod.write_yaml( '/content/pages/page.yaml', { '$path': '/{locale}/{base}/', '$view': '/views/base.html', '$localization': { 'default_locale': 'de', 'path': '/{locale}/{base}/', 'locales': [ 'en', 'de', ], }, }) pod.podcache.reset() pod.router.routes.reset() pod.router.add_all() content = testing.render_path(pod, '/de/page/') self.assertEqual('de', content) paths = list(pod.router.routes.paths) expected = ['/de/page/', '/en/page/'] self.assertEqual(expected, paths)
def test_default_locale_override(self): pod = testing.create_pod() pod.write_yaml( '/podspec.yaml', { 'localization': { 'default_locale': 'en', 'locales': [ 'en', 'de', 'it', ] } }) pod.write_file('/views/base.html', '{{doc.foo}}') pod.write_yaml( '/content/pages/_blueprint.yaml', { '$path': '/{base}/', '$view': '/views/base.html', '$localization': { 'path': '/{locale}/{base}/', }, }) pod.write_yaml( '/content/pages/page.yaml', { '$localization': { 'default_locale': 'de', }, 'foo': 'foo-base', 'foo@de': 'foo-de', }) pod.write_yaml('/content/pages/page2.yaml', { 'foo': 'foo-base', 'foo@de': 'foo-de', }) pod.router.add_all() # Verify ability to override using the default locale. content = testing.render_path(pod, '/page/') self.assertEqual('foo-de', content) content = testing.render_path(pod, '/en/page/') self.assertEqual('foo-base', content) # Verify default behavior otherwise. content = testing.render_path(pod, '/page2/') self.assertEqual('foo-base', content) content = testing.render_path(pod, '/de/page2/') self.assertEqual('foo-de', content)
def test_noclasses(self): pod = testing.create_pod() fields = { 'markdown': { 'extensions': [{ 'kind': 'markdown.extensions.codehilite', }], } } pod.write_yaml('/podspec.yaml', fields) fields = { '$view': '/views/base.html', '$path': '/{base}/' } pod.write_yaml('/content/pages/_blueprint.yaml', fields) content = '{{doc.html|safe}}' pod.write_file('/views/base.html', content) # Verify ticks. content = textwrap.dedent( """ ```html <div class="test"> Hello World </div> ``` """) pod.write_file('/content/pages/test.md', content) pod.router.add_all() result = testing.render_path(pod, '/test/') style_sentinel = 'style="background: #f8f8f8"' self.assertIn(style_sentinel, result) fields = { 'markdown': { 'extensions': [{ 'kind': 'markdown.extensions.codehilite', 'classes': True, }], } } pod.write_yaml('/podspec.yaml', fields) pod = pods.Pod(pod.root) pod.router.routes.reset() pod.router.add_all() result = testing.render_path(pod, '/test/') class_sentinel = '<span class="nt">' self.assertIn(class_sentinel, result)
def test_utf8(self): pod = testing.create_pod() pod.write_yaml('/podspec.yaml', {'markdown': { 'extensions': [{ 'kind': 'toc', }], }}) pod.write_yaml('/content/pages/_blueprint.yaml', { '$view': '/views/base.html', '$path': '/{base}/' }) pod.write_file( '/content/pages/test.md', textwrap.dedent("""\ # Did you see the rocket launch? # 로켓 발사를 봤어? """)) pod.write_file('/views/base.html', '{{doc.html|safe}}') pod.router.add_all(use_cache=False) result = testing.render_path(pod, '/test/').decode('utf-8') header = '<h1 id="did-you-see-the-rocket-launch?">Did you see the rocket launch?</h1>' self.assertIn(header, result) header = u'<h1 id="로켓-발사를-봤어?">로켓 발사를 봤어?</h1>' self.assertIn(header, result)
def test_utf8(self): pod = testing.create_pod() pod.write_yaml('/podspec.yaml', { 'markdown': { 'extensions': [{ 'kind': 'toc', }], } }) pod.write_yaml('/content/pages/_blueprint.yaml', { '$view': '/views/base.html', '$path': '/{base}/' }) pod.write_file('/content/pages/test.md', textwrap.dedent( """\ # Did you see the rocket launch? # 로켓 발사를 봤어? """)) pod.write_file('/views/base.html', '{{doc.html|safe}}') pod.router.add_all() result = testing.render_path(pod, '/test/').decode('utf-8') header = '<h1 id="did-you-see-the-rocket-launch?">Did you see the rocket launch?</h1>' self.assertIn(header, result) header = u'<h1 id="로켓-발사를-봤어?">로켓 발사를 봤어?</h1>' self.assertIn(header, result)
def test_url_link(self): """Plain url reference works.""" content = '[Link]([url(\'/content/pages/test1.md\')])' self.pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' self.pod.write_file('/views/base.html', content) self.pod.router.add_all(use_cache=False) result = testing.render_path(self.pod, '/test/') self.assertIn('href="/test1/"', result)
def test_url_link(self): """Plain url reference works.""" content = '[Link]([url(\'/content/pages/test1.md\')])' self.pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' self.pod.write_file('/views/base.html', content) self.pod.router.add_all() result = testing.render_path(self.pod, '/test/') self.assertIn('href="/test1/"', result)
def test_url(self): """Plain url reference works.""" content = 'URL:[url(\'/content/pages/test1.md\')]' self.pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' self.pod.write_file('/views/base.html', content) self.pod.router.add_all() result = testing.render_path(self.pod, '/test/') self.assertIn('URL:/test1', result)
def test_url_link_static(self): """Plain url reference works.""" content = 'static doc' self.pod.write_file('/static/test.txt', content) content = '[Link]([url(\'/static/test.txt\')])' self.pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' self.pod.write_file('/views/base.html', content) self.pod.router.add_all() result = testing.render_path(self.pod, '/test/') self.assertIn('href="/public/test.txt"', result)
def test_json(self): self.pod.router.add_all() html = testing.render_path(self.pod, '/json_test/') self.assertIn('key - value', html) self.assertIn('key2 - value2', html)
def test_noclasses(self): pod = testing.create_pod() fields = { 'markdown': { 'extensions': [{ 'kind': 'sourcecode', }], } } pod.write_yaml('/podspec.yaml', fields) fields = { '$view': '/views/base.html', '$path': '/{base}/' } pod.write_yaml('/content/pages/_blueprint.yaml', fields) content = """ [sourcecode:html] <div class="test"> Hello World </div> [/sourcecode] """ pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' pod.write_file('/views/base.html', content) pod.router.add_all() result = testing.render_path(pod, '/test/') style_sentinel = 'style="background: #f8f8f8"' self.assertIn(style_sentinel, result) # Verify no language. content = """ [sourcecode] <div class="test"> Hello World </div> [/sourcecode] """ pod.write_file('/content/pages/test.md', content) content = '{{doc.html|safe}}' pod.write_file('/views/base.html', content) pod.router.add_all() result = testing.render_path(pod, '/test/') style_sentinel = 'style="background: #f8f8f8"' self.assertIn(style_sentinel, result) fields = { 'markdown': { 'extensions': [{ 'kind': 'sourcecode', 'highlighter': 'plain', 'classes': True, }], } } pod.write_yaml('/podspec.yaml', fields) pod = pods.Pod(pod.root) pod.router.add_all() result = testing.render_path(pod, '/test/') code_sentinel = '<div class="code"><pre>' self.assertIn(code_sentinel, result)
def test_json(self): self.pod.router.add_all(use_cache=False) html = testing.render_path(self.pod, '/json_test/') self.assertIn('key - value', html) self.assertIn('key2 - value2', html)
def test_json_encoder(self): self.pod.router.add_all(use_cache=False) html = testing.render_path(self.pod, '/json_test/') self.assertIn('"$title": "Text Page"', html) self.assertIn('"$hidden": true', html)
def test_json_encoder(self): self.pod.router.add_all() html = testing.render_path(self.pod, '/json_test/') self.assertIn('"$title": "Text Page"', html) self.assertIn('"$hidden": true', html)