mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Avoid circular import, pass Readers() to Content as parameter
This commit is contained in:
parent
850a7db5f0
commit
771a7579cb
3 changed files with 6 additions and 8 deletions
|
|
@ -36,6 +36,7 @@ class Content(object):
|
|||
:param settings: the settings dictionary (optional).
|
||||
:param source_path: The location of the source of this content (if any).
|
||||
:param context: The shared context between generators.
|
||||
:param _readers: readers.Readers() instance used for rendering includes.
|
||||
|
||||
"""
|
||||
@deprecated_attribute(old='filename', new='source_path', since=(3, 2, 0))
|
||||
|
|
@ -43,7 +44,7 @@ class Content(object):
|
|||
return None
|
||||
|
||||
def __init__(self, content, metadata=None, settings=None,
|
||||
source_path=None, context=None):
|
||||
source_path=None, context=None, _readers=None):
|
||||
if metadata is None:
|
||||
metadata = {}
|
||||
if settings is None:
|
||||
|
|
@ -152,17 +153,12 @@ class Content(object):
|
|||
self._summary = metadata['summary']
|
||||
|
||||
# used for rendering {includes}
|
||||
self._readers = None
|
||||
self._readers = _readers
|
||||
|
||||
signals.content_object_init.send(self)
|
||||
|
||||
@property
|
||||
def readers(self):
|
||||
if self._readers is None:
|
||||
# import here due to circular imports
|
||||
from pelican.readers import Readers
|
||||
self._readers = Readers(self.settings)
|
||||
|
||||
return self._readers
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
|||
|
|
@ -574,7 +574,7 @@ class Readers(FileStampDataCacher):
|
|||
|
||||
return content_class(content=content, metadata=metadata,
|
||||
settings=self.settings, source_path=path,
|
||||
context=context)
|
||||
context=context, _readers=self)
|
||||
|
||||
|
||||
def find_empty_alt(content, path):
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from jinja2.utils import generate_lorem_ipsum
|
|||
import six
|
||||
|
||||
from pelican.contents import Article, Author, Category, Page, Static, Tag
|
||||
from pelican.readers import Readers
|
||||
from pelican.settings import DEFAULT_CONFIG
|
||||
from pelican.signals import content_object_init
|
||||
from pelican.tests.support import LoggedTestCase, get_settings, unittest
|
||||
|
|
@ -428,6 +429,7 @@ class TestPage(LoggedTestCase):
|
|||
settings = get_settings()
|
||||
settings['PATH'] = CONTENT_PATH
|
||||
args['settings'] = settings
|
||||
args['_readers'] = Readers(settings)
|
||||
|
||||
# test inclusion b/w files of different types
|
||||
# HTML includes Markdown
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue