当前位置: 首页>>代码示例>>Python>>正文


Python PagesGenerator.generate_context方法代码示例

本文整理汇总了Python中pelican.generators.PagesGenerator.generate_context方法的典型用法代码示例。如果您正苦于以下问题:Python PagesGenerator.generate_context方法的具体用法?Python PagesGenerator.generate_context怎么用?Python PagesGenerator.generate_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pelican.generators.PagesGenerator的用法示例。


在下文中一共展示了PagesGenerator.generate_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_page_ignore_cache

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_page_ignore_cache(self):
        """Test that all the pages are read again when not loading cache

        used in --ignore_cache or autoreload mode"""
        settings = self._get_cache_enabled_settings()
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache_open'))
        orig_call_count = generator.readers.read_file.call_count

        settings['LOAD_CONTENT_CACHE'] = False
        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        self.assertEqual(
            generator.readers.read_file.call_count,
            orig_call_count)
开发者ID:adeverteuil,项目名称:pelican,代码行数:27,代码来源:test_cache.py

示例2: test_generate_context

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_generate_context(self):
        settings = get_settings(filenames={})
        settings["CACHE_PATH"] = self.temp_cache
        settings["PAGE_PATHS"] = ["TestPages"]  # relative to CUR_DIR
        settings["DEFAULT_DATE"] = (1970, 1, 1)

        generator = PagesGenerator(
            context=settings.copy(), settings=settings, path=CUR_DIR, theme=settings["THEME"], output_path=None
        )
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)

        pages_expected = [
            ["This is a test page", "published", "page"],
            ["This is a markdown test page", "published", "page"],
            ["This is a test page with a preset template", "published", "custom"],
            ["Page with a bunch of links", "published", "page"],
            ["A Page (Test) for sorting", "published", "page"],
        ]
        hidden_pages_expected = [
            ["This is a test hidden page", "hidden", "page"],
            ["This is a markdown test hidden page", "hidden", "page"],
            ["This is a test hidden page with a custom template", "hidden", "custom"],
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(sorted(pages_expected), sorted(self.distill_pages(generator.context["pages"])))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
        self.assertEqual(sorted(hidden_pages_expected), sorted(self.distill_pages(generator.context["hidden_pages"])))
开发者ID:entelesis,项目名称:pelican,代码行数:32,代码来源:test_generators.py

示例3: test_generate_context

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_generate_context(self):
        settings = _DEFAULT_CONFIG.copy()

        settings['PAGE_DIR'] = 'TestPages'
        settings['DEFAULT_DATE'] = (1970, 01, 01)
        generator = PagesGenerator(settings.copy(), settings, CUR_DIR,
                                      _DEFAULT_CONFIG['THEME'], None,
                                      _DEFAULT_CONFIG['MARKUP'])
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)

        pages_expected = [
            [u'This is a test page', 'published', 'page'],
            [u'This is a markdown test page', 'published', 'page'],
            [u'This is a test page with a preset template', 'published', 'custom']
        ]
        hidden_pages_expected = [
            [u'This is a test hidden page', 'hidden', 'page'],
            [u'This is a markdown test hidden page', 'hidden', 'page'],
            [u'This is a test hidden page with a custom template', 'hidden', 'custom']
        ]

        self.assertItemsEqual(pages_expected,pages)
        self.assertItemsEqual(hidden_pages_expected,hidden_pages)
开发者ID:bbinet,项目名称:pelican,代码行数:27,代码来源:test_generators.py

示例4: test_generate_context

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_generate_context(self):
        settings = get_settings(filenames={})
        settings['PAGE_DIR'] = 'TestPages'  # relative to CUR_DIR
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)

        pages_expected = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom']
        ]
        hidden_pages_expected = [
            ['This is a test hidden page', 'hidden', 'page'],
            ['This is a markdown test hidden page', 'hidden', 'page'],
            ['This is a test hidden page with a custom template', 'hidden',
             'custom']
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
开发者ID:JSteunou,项目名称:pelican,代码行数:29,代码来源:test_generators.py

示例5: test_generate_context

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_generate_context(self):
        settings = get_settings()
        settings['PAGE_DIR'] = 'TestPages'
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(settings.copy(), settings, CUR_DIR,
                                      settings['THEME'], None,
                                      settings['MARKUP'])
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)

        pages_expected = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom']
        ]
        hidden_pages_expected = [
            ['This is a test hidden page', 'hidden', 'page'],
            ['This is a markdown test hidden page', 'hidden', 'page'],
            ['This is a test hidden page with a custom template', 'hidden',
             'custom']
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
开发者ID:AndreLesa,项目名称:pelican,代码行数:29,代码来源:test_generators.py

示例6: test_generate_context

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_generate_context(self):
        settings = get_settings()
        settings['CACHE_PATH'] = self.temp_cache
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)
        draft_pages = self.distill_pages(generator.draft_pages)

        pages_expected = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
            ['Page with a bunch of links', 'published', 'page'],
            ['Page with static links', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
        ]
        hidden_pages_expected = [
            ['This is a test hidden page', 'hidden', 'page'],
            ['This is a markdown test hidden page', 'hidden', 'page'],
            ['This is a test hidden page with a custom template', 'hidden',
             'custom'],
        ]
        draft_pages_expected = [
            ['This is a test draft page', 'draft', 'page'],
            ['This is a markdown test draft page', 'draft', 'page'],
            ['This is a test draft page with a custom template', 'draft',
             'custom'],
        ]

        self.assertEqual(sorted(pages_expected), sorted(pages))
        self.assertEqual(
            sorted(pages_expected),
            sorted(self.distill_pages(generator.context['pages'])))
        self.assertEqual(sorted(hidden_pages_expected), sorted(hidden_pages))
        self.assertEqual(sorted(draft_pages_expected), sorted(draft_pages))
        self.assertEqual(
            sorted(hidden_pages_expected),
            sorted(self.distill_pages(generator.context['hidden_pages'])))
        self.assertEqual(
            sorted(draft_pages_expected),
            sorted(self.distill_pages(generator.context['draft_pages'])))
开发者ID:getpelican,项目名称:pelican,代码行数:51,代码来源:test_generators.py

示例7: test_page_object_caching

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_page_object_caching(self):
        """Test Page objects caching at the generator level"""
        settings = get_settings(filenames={})
        settings['CACHE_PATH'] = self.temp_cache
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache'))

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        generator.readers.read_file.assert_called_count == 0
开发者ID:0xMF,项目名称:pelican,代码行数:21,代码来源:test_generators.py

示例8: test_tag_and_category_links_on_generated_pages

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_tag_and_category_links_on_generated_pages(self):
        """
        Test to ensure links of the form {tag}tagname and {category}catname
        are generated correctly on pages
        """
        settings = get_settings(filenames={})
        settings['PAGE_PATHS'] = ['TestPages'] # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages_by_title = {p.title: p.content for p in generator.pages}

        test_content = pages_by_title['Page with a bunch of links']
        self.assertIn('<a href="/category/yeah.html">', test_content)
        self.assertIn('<a href="/tag/matsuku.html">', test_content)
开发者ID:alexras,项目名称:pelican,代码行数:21,代码来源:test_generators.py

示例9: test_static_and_attach_links_on_generated_pages

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_static_and_attach_links_on_generated_pages(self):
        """
        Test to ensure links of the form {static}filename and {attach}filename
        are included in context['static_links']
        """
        settings = get_settings()
        settings['PAGE_PATHS'] = ['TestPages/page_with_static_links.md']
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)
        context = get_context(settings)

        generator = PagesGenerator(
            context=context, settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()

        self.assertIn('pelican/tests/TestPages/image0.jpg',
                      context['static_links'])
        self.assertIn('pelican/tests/TestPages/image1.jpg',
                      context['static_links'])
开发者ID:getpelican,项目名称:pelican,代码行数:22,代码来源:test_generators.py

示例10: test_reader_content_caching

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_reader_content_caching(self):
        """Test raw content caching at the reader level"""
        settings = get_settings(filenames={})
        settings['CACHE_PATH'] = self.temp_cache
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator.readers, '_cache'))

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        readers = generator.readers.readers
        for reader in readers.values():
            reader.read = MagicMock()
        generator.generate_context()
        for reader in readers.values():
            reader.read.assert_called_count == 0
开发者ID:0xMF,项目名称:pelican,代码行数:23,代码来源:test_generators.py

示例11: test_page_reader_content_caching

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_page_reader_content_caching(self):
        """Test raw page content caching at the reader level"""
        settings = self._get_cache_enabled_settings()
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator.readers, '_cache'))

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        readers = generator.readers.readers
        for reader in readers.values():
            reader.read = MagicMock()
        generator.generate_context()
        for reader in readers.values():
            self.assertEqual(reader.read.call_count, 0)
开发者ID:adeverteuil,项目名称:pelican,代码行数:23,代码来源:test_cache.py

示例12: test_generate_sorted

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_generate_sorted(self):
        settings = get_settings(filenames={})
        settings['PAGE_PATHS'] = ['TestPages']  # relative to CUR_DIR
        settings['CACHE_PATH'] = self.temp_cache
        settings['DEFAULT_DATE'] = (1970, 1, 1)

        # default sort (filename)
        pages_expected_sorted_by_filename = [
            ['This is a test page', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['A Page (Test) for sorting', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
        ]
        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_filename, pages)

        # sort by title
        pages_expected_sorted_by_title = [
            ['A Page (Test) for sorting', 'published', 'page'],
            ['Page with a bunch of links', 'published', 'page'],
            ['This is a markdown test page', 'published', 'page'],
            ['This is a test page', 'published', 'page'],
            ['This is a test page with a preset template', 'published',
             'custom'],
        ]
        settings['PAGE_ORDER_BY'] = 'title'
        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        self.assertEqual(pages_expected_sorted_by_title, pages)
开发者ID:ironM,项目名称:pelican,代码行数:40,代码来源:test_generators.py

示例13: test_ignore_cache

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_ignore_cache(self):
        """Test that all the pages are read again when not loading cache

        used in --ignore_cache or autoreload mode"""
        settings = get_settings(filenames={})
        settings['CACHE_DIRECTORY'] = self.temp_cache
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache_open'))
        orig_call_count = generator.readers.read_file.call_count

        settings['LOAD_CONTENT_CACHE'] = False
        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CONTENT_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        generator.readers.read_file.assert_called_count == orig_call_count
开发者ID:aftersomemath,项目名称:pelican,代码行数:25,代码来源:test_generators.py

示例14: test_page_object_caching

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_page_object_caching(self):
        """Test Page objects caching at the generator level"""
        settings = self._get_cache_enabled_settings()
        settings['CONTENT_CACHING_LAYER'] = 'generator'
        settings['PAGE_PATHS'] = ['TestPages']
        settings['READERS'] = {'asc': None}

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.generate_context()
        self.assertTrue(hasattr(generator, '_cache'))

        generator = PagesGenerator(
            context=settings.copy(), settings=settings,
            path=CUR_DIR, theme=settings['THEME'], output_path=None)
        generator.readers.read_file = MagicMock()
        generator.generate_context()
        """
        1 File doesn't get cached because it was not valid
        - bad_page.rst
        """
        self.assertEqual(generator.readers.read_file.call_count, 1)
开发者ID:adeverteuil,项目名称:pelican,代码行数:25,代码来源:test_cache.py

示例15: test_generate_context

# 需要导入模块: from pelican.generators import PagesGenerator [as 别名]
# 或者: from pelican.generators.PagesGenerator import generate_context [as 别名]
    def test_generate_context(self):
        settings = get_settings()
        settings["PAGE_DIR"] = "TestPages"
        settings["DEFAULT_DATE"] = (1970, 1, 1)

        generator = PagesGenerator(settings.copy(), settings, CUR_DIR, settings["THEME"], None, settings["MARKUP"])
        generator.generate_context()
        pages = self.distill_pages(generator.pages)
        hidden_pages = self.distill_pages(generator.hidden_pages)

        pages_expected = [
            ["This is a test page", "published", "page"],
            ["This is a markdown test page", "published", "page"],
            ["This is a test page with a preset template", "published", "custom"],
        ]
        hidden_pages_expected = [
            ["This is a test hidden page", "hidden", "page"],
            ["This is a markdown test hidden page", "hidden", "page"],
            ["This is a test hidden page with a custom template", "hidden", "custom"],
        ]

        self.assertItemsEqual(pages_expected, pages)
        self.assertItemsEqual(hidden_pages_expected, hidden_pages)
开发者ID:davidmarble,项目名称:pelican,代码行数:25,代码来源:test_generators.py


注:本文中的pelican.generators.PagesGenerator.generate_context方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。