From 8195677cae913e2f964bf631d88f00a33e16bc24 Mon Sep 17 00:00:00 2001 From: Sunaina Pai Date: Sat, 11 Aug 2018 14:40:18 +0530 Subject: Populate placeholders in content when specified Placeholders in content files are not populated by default. If placeholders are to be populated in content files, parameter named `render` with a string value of `yes` must be specified. This `render` parameter may be specified as a header in content files or it may be specified as a keyword argument in `make_pages` call. --- test/test_pages.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/test_pages.py') diff --git a/test/test_pages.py b/test/test_pages.py index 9f52fb7..0fefdaa 100644 --- a/test/test_pages.py +++ b/test/test_pages.py @@ -22,6 +22,10 @@ class PagesTest(unittest.TestCase): f.write('Foo') with open(os.path.join(self.blog_path, 'header-bar.txt'), 'w') as f: f.write('Bar') + with open(os.path.join(self.blog_path, 'placeholder-foo.txt'), 'w') as f: + f.write('{{ title }}:{{ author }}:Foo') + with open(os.path.join(self.blog_path, 'placeholder-bar.txt'), 'w') as f: + f.write('{{ title }}:{{ author }}:Bar') def tearDown(self): shutil.rmtree(self.blog_path) @@ -77,3 +81,47 @@ class PagesTest(unittest.TestCase): self.assertEqual(f.read(), '{{ title }}:foo:Foo') with open(os.path.join(self.site_path, 'header-bar.txt')) as f: self.assertEqual(f.read(), 'bar:{{ tag }}:Bar') + + def test_content_no_rendering(self): + # Test that placeholders are not populated in content rendering + # by default. + src = os.path.join(self.blog_path, 'placeholder-foo.txt') + dst = os.path.join(self.site_path, '{{ slug }}.txt') + tpl = '
{{ content }}
' + makesite.make_pages(src, dst, tpl, author='Admin') + with open(os.path.join(self.site_path, 'placeholder-foo.txt')) as f: + self.assertEqual(f.read(), '
{{ title }}:{{ author }}:Foo
') + + def test_content_rendering_via_kwargs(self): + # Test that placeholders are populated in content rendering when + # requested in make_pages. + src = os.path.join(self.blog_path, 'placeholder-foo.txt') + dst = os.path.join(self.site_path, '{{ slug }}.txt') + tpl = '
{{ content }}
' + makesite.make_pages(src, dst, tpl, author='Admin', render='yes') + with open(os.path.join(self.site_path, 'placeholder-foo.txt')) as f: + self.assertEqual(f.read(), '
foo:Admin:Foo
') + + def test_content_rendering_via_header(self): + # Test that placeholders are populated in content rendering when + # requested in content header. + src = os.path.join(self.blog_path, 'placeholder-bar.txt') + dst = os.path.join(self.site_path, '{{ slug }}.txt') + tpl = '
{{ content }}
' + makesite.make_pages(src, dst, tpl, author='Admin') + with open(os.path.join(self.site_path, 'placeholder-bar.txt')) as f: + self.assertEqual(f.read(), '
bar:Admin:Bar
') + + def test_rendered_content_in_summary(self): + # Test that placeholders are populated in summary if and only if + # content rendering is enabled. + src = os.path.join(self.blog_path, 'placeholder*.txt') + post_dst = os.path.join(self.site_path, '{{ slug }}.txt') + list_dst = os.path.join(self.site_path, 'list.txt') + post_layout = '' + list_layout = '
{{ content }}
' + item_layout = '

{{ summary }}

' + posts = makesite.make_pages(src, post_dst, post_layout, author='Admin') + makesite.make_list(posts, list_dst, list_layout, item_layout) + with open(os.path.join(self.site_path, 'list.txt')) as f: + self.assertEqual(f.read(), '

{{ title }}:{{ author }}:Foo

bar:Admin:Bar

') -- cgit v1.2.3