mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge a8555ef976 into 5f1d5c4b88
This commit is contained in:
commit
5a13c65684
7 changed files with 49 additions and 0 deletions
|
|
@ -700,6 +700,14 @@ Template pages
|
|||
separate templates from the theme. Example: projects, resume, profile ...
|
||||
These templates need to use ``DIRECT_TEMPLATES`` setting.
|
||||
|
||||
.. data:: THEME_TEMPLATE_OVERRIDES = []
|
||||
|
||||
A list of paths you want Jinja2 to search for templates before searching the
|
||||
theme's ``templates/`` directory. Allows for overriding individual theme
|
||||
template files without having to fork an existing theme. Jinja2 searches in
|
||||
the following order: files in ``THEME_TEMPLATE_OVERRIDES`` first, theme's
|
||||
``templates/``
|
||||
|
||||
|
||||
Metadata
|
||||
========
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ class Generator(object):
|
|||
# templates cache
|
||||
self._templates = {}
|
||||
self._templates_path = []
|
||||
self._templates_path += self.settings['THEME_TEMPLATE_OVERRIDES']
|
||||
self._templates_path.append(os.path.expanduser(
|
||||
os.path.join(self.theme, 'templates')))
|
||||
self._templates_path += self.settings['EXTRA_TEMPLATES_PATHS']
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ DEFAULT_CONFIG = {
|
|||
'RELATIVE_URLS': False,
|
||||
'DEFAULT_LANG': 'en',
|
||||
'DIRECT_TEMPLATES': ['index', 'tags', 'categories', 'authors', 'archives'],
|
||||
'THEME_TEMPLATE_OVERRIDES': [],
|
||||
'EXTRA_TEMPLATES_PATHS': [],
|
||||
'PAGINATED_DIRECT_TEMPLATES': ['index'],
|
||||
'PELICAN_CLASS': 'pelican.Pelican',
|
||||
|
|
@ -380,6 +381,7 @@ def configure_settings(settings):
|
|||
'ARTICLE_EXCLUDES',
|
||||
'DEFAULT_METADATA',
|
||||
'DIRECT_TEMPLATES',
|
||||
'THEME_TEMPLATE_OVERRIDES',
|
||||
'EXTRA_TEMPLATES_PATHS',
|
||||
'FILES_TO_COPY',
|
||||
'IGNORE_FILES',
|
||||
|
|
|
|||
|
|
@ -118,6 +118,32 @@ class TestGenerator(unittest.TestCase):
|
|||
generator.env.comment_end_string)
|
||||
|
||||
|
||||
# def test_get_templat_with_theme_overrides(self):
|
||||
# override_dirs = (os.path.join(CUR_DIR, 'theme_overrides', 'level1'),
|
||||
# os.path.join(CUR_DIR, 'theme_overrides', 'level2'))
|
||||
# self.settings['THEME_TEMPLATE_OVERRIDES'] = override_dirs
|
||||
# generator = Generator(
|
||||
# context=self.settings.copy(),
|
||||
# settings=self.settings,
|
||||
# path=CUR_DIR,
|
||||
# theme=self.settings['THEME'],
|
||||
# output_path=None)
|
||||
|
||||
# filename = generator.get_template('article').filename
|
||||
# self.assertEqual(override_dirs[0], os.path.dirname(filename))
|
||||
# self.assertEqual('article.html', os.path.basename(filename))
|
||||
|
||||
# filename = generator.get_template('authors').filename
|
||||
# self.assertEqual(override_dirs[1], os.path.dirname(filename))
|
||||
# self.assertEqual('authors.html', os.path.basename(filename))
|
||||
|
||||
# filename = generator.get_template('taglist').filename
|
||||
# self.assertEqual(os.path.join(self.settings['THEME'], 'templates'),
|
||||
# os.path.dirname(filename))
|
||||
# self.assertNotIn(os.path.dirname(filename), override_dirs)
|
||||
# self.assertEqual('taglist.html', os.path.basename(filename))
|
||||
|
||||
|
||||
class TestArticlesGenerator(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
4
pelican/tests/theme_overrides/level1/article.html
Normal file
4
pelican/tests/theme_overrides/level1/article.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<!--
|
||||
This file is only here to test the `THEME_TEMPLATE_OVERRIDES` configuration
|
||||
setting.
|
||||
-->
|
||||
4
pelican/tests/theme_overrides/level2/article.html
Normal file
4
pelican/tests/theme_overrides/level2/article.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<!--
|
||||
This file is only here to test the `THEME_TEMPLATE_OVERRIDES` configuration
|
||||
setting.
|
||||
-->
|
||||
4
pelican/tests/theme_overrides/level2/authors.html
Normal file
4
pelican/tests/theme_overrides/level2/authors.html
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<!--
|
||||
This file is only here to test the `THEME_TEMPLATE_OVERRIDES` configuration
|
||||
setting.
|
||||
-->
|
||||
Loading…
Add table
Add a link
Reference in a new issue