本文整理汇总了Python中pelican.contents.Page类的典型用法代码示例。如果您正苦于以下问题:Python Page类的具体用法?Python Page怎么用?Python Page使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_metadata_url_format
def test_metadata_url_format(self):
# Arbitrary metadata should be passed through url_format()
page = Page(**self.page_kwargs)
self.assertIn('summary', page.url_format.keys())
page.metadata['directory'] = 'test-dir'
page.settings = get_settings(PAGE_SAVE_AS='{directory}/{slug}')
self.assertEqual(page.save_as, 'test-dir/foo-bar')
示例2: test_get_content
def test_get_content(self):
# Test that the content is updated with the relative links to
# filenames, tags and categories.
settings = get_settings()
args = self.page_kwargs.copy()
args['settings'] = settings
# Tag
args['content'] = ('A simple test, with a '
'<a href="|tag|tagname">link</a>')
page = Page(**args)
content = page.get_content('http://notmyidea.org')
self.assertEqual(
content,
('A simple test, with a '
'<a href="http://notmyidea.org/tag/tagname.html">link</a>'))
# Category
args['content'] = ('A simple test, with a '
'<a href="|category|category">link</a>')
page = Page(**args)
content = page.get_content('http://notmyidea.org')
self.assertEqual(
content,
('A simple test, with a '
'<a href="http://notmyidea.org/category/category.html">link</a>'))
示例3: test_save_as
def test_save_as(self):
# if a lang is not the default lang, save_as should be set accordingly
page = Page('content', {'title': 'foobar', 'lang': 'fr'}) #default lang is en
self.assertEqual(page.save_as, "foobar-fr.html")
# otherwise, if a title is defined, save_as should be set
page = Page('content', {'title': 'foobar'})
page.save_as = 'foobar.html'
示例4: test_metadata_url_format
def test_metadata_url_format(self):
"""Arbitrary metadata should be passed through url_format()
"""
page = Page(**self.page_kwargs)
self.assertIn('summary', page.url_format.keys())
page.metadata['directory'] = 'test-dir'
page.settings = _DEFAULT_CONFIG.copy()
page.settings['PAGE_SAVE_AS'] = '{directory}/{slug}'
self.assertEqual(page.save_as, 'test-dir/foo-bar')
示例5: test_mandatory_properties
def test_mandatory_properties(self):
# If the title is not set, must throw an exception.
page = Page('content')
self.assertFalse(page._has_valid_mandatory_properties())
self.assertLogCountEqual(
count=1,
msg="Skipping .*: could not find information about 'title'",
level=logging.ERROR)
page = Page('content', metadata={'title': 'foobar'})
self.assertTrue(page._has_valid_mandatory_properties())
示例6: test_summary_get_summary_warning
def test_summary_get_summary_warning(self):
"""calling ._get_summary() should issue a warning"""
page_kwargs = self._copy_page_kwargs()
page = Page(**page_kwargs)
self.assertEqual(page.summary, TEST_SUMMARY)
self.assertEqual(page._get_summary(), TEST_SUMMARY)
self.assertLogCountEqual(
count=1,
msg="_get_summary\(\) has been deprecated since 3\.6\.4\. "
"Use the summary decorator instead",
level=logging.WARNING)
示例7: test_category_link_syntax
def test_category_link_syntax(self):
"{category} link syntax triggers url replacement."
html = '<a href="{category}foo">link</a>'
page = Page(content=html,
metadata={'title': 'fakepage'}, settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertNotEqual(content, html)
示例8: test_save_as
def test_save_as(self):
# if a lang is not the default lang, save_as should be set accordingly
page = Page("content", {"title": "foobar", "lang": "fr"}) # default lang is en
self.assertEqual(page.save_as, "foobar-fr.html")
# otherwise, if a title is defined, save_as should be set
page = Page("content", {"title": "foobar"})
page.save_as = "foobar.html"
# if no title is given, there is no save_as
page = Page("content")
self.assertFalse(hasattr(page, "save_as"))
示例9: test_save_as
def test_save_as(self):
"""If a lang is not the default lang, save_as should be set
accordingly.
"""
# if a title is defined, save_as should be set
page = Page(**self.page_kwargs)
page.save_as = 'foo-bar.html'
# if a language is defined, save_as should include it accordingly
self.page_kwargs['metadata'].update({'lang': 'fr', })
page = Page(**self.page_kwargs)
self.assertEqual(page.save_as, "foo-bar-fr.html")
示例10: test_link_to_unknown_file
def test_link_to_unknown_file(self):
"{filename} link to unknown file should trigger warning."
html = '<a href="{filename}foo">link</a>'
page = Page(content=html,
metadata={'title': 'fakepage'}, settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertEqual(content, html)
self.assertLogCountEqual(
count=1,
msg="Unable to find 'foo', skipping url replacement.",
level=logging.WARNING)
示例11: test_unknown_link_syntax
def test_unknown_link_syntax(self):
"{unknown} link syntax should trigger warning."
html = '<a href="{unknown}foo">link</a>'
page = Page(content=html,
metadata={'title': 'fakepage'}, settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertEqual(content, html)
self.assertLogCountEqual(
count=1,
msg="Replacement Indicator 'unknown' not recognized, "
"skipping replacement",
level=logging.WARNING)
示例12: test_attach_link_syntax
def test_attach_link_syntax(self):
"""{attach} link syntax triggers output path override & url replacement.
"""
html = '<a href="{attach}../foo.jpg">link</a>'
page = Page(content=html,
metadata={'title': 'fakepage'}, settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertNotEqual(content, html,
"{attach} link syntax did not trigger URL replacement.")
expected_save_as = os.path.join('outpages', 'foo.jpg')
self.assertEqual(self.static.save_as, expected_save_as)
self.assertEqual(self.static.url, path_to_url(expected_save_as))
示例13: test_index_link_syntax
def test_index_link_syntax(self):
"{index} link syntax triggers url replacement."
html = '<a href="{index}">link</a>'
page = Page(
content=html,
metadata={'title': 'fakepage'},
settings=self.settings,
source_path=os.path.join('dir', 'otherdir', 'fakepage.md'),
context=self.context)
content = page.get_content('')
self.assertNotEqual(content, html)
expected_html = ('<a href="' +
'/'.join((self.settings['SITEURL'],
self.settings['INDEX_SAVE_AS'])) +
'">link</a>')
self.assertEqual(content, expected_html)
示例14: test_mandatory_properties
def test_mandatory_properties(self):
# if the title is not set, must throw an exception
page = Page('content', {'title':'foobar'})
page.mandatory_properties = ('title', 'foo')
with self.assertRaises(NameError) as cm:
page.check_properties()
page = Page('content', metadata={'title': 'foobar'})
page.check_properties()
示例15: generate_context
def generate_context(self):
all_pages = []
for f in self.get_files(os.sep.join((self.path, 'pages'))):
content, metadata = read_file(f)
page = Page(content, metadata, settings=self.settings,
filename=f)
if not is_valid_content(page, f):
continue
if self.settings.get('CLEAN_URLS_NO_PROXY'):
# cleaning page url
page.save_as = os.path.join(page.slug, 'index.html')
page.url = os.path.dirname(page.save_as) + '/'
all_pages.append(page)
self.pages, self.translations = process_translations(all_pages)
self._update_context(('pages', ))
self.context['PAGES'] = self.pages