# Path: flask_blogging/processor.py
# class PostProcessor(object):
# 
#     _markdown_extensions = [MathJaxExtension(), MetaExtension()]
# 
#     @staticmethod
#     def create_slug(title):
#         return slugify(title)
# 
#     @staticmethod
#     def extract_images(post):
#         regex = re.compile(r'<\s*img [^>]*src="([^"]+)')
#         return regex.findall(post["rendered_text"])
# 
#     @classmethod
#     def construct_url(cls, post):
#         url = url_for("blogging.page_by_id", post_id=post["post_id"],
#                       slug=cls.create_slug(post["title"]))
#         return url
# 
#     @classmethod
#     def render_text(cls, post):
#         md = markdown.Markdown(extensions=cls.all_extensions())
#         post["rendered_text"] = md.convert(post["text"])
#         post["meta"] = md.Meta
# 
#     @classmethod
#     def is_author(cls, post, user):
#         return user.get_id() == u''+str(post['user_id'])
# 
#     @classmethod
#     def process(cls, post, render=True):
#         """
#         This method takes the post data and renders it
#         :param post:
#         :param render:
#         :return:
#         """
#         post["slug"] = cls.create_slug(post["title"])
#         post["editable"] = cls.is_author(post, current_user)
#         post["url"] = cls.construct_url(post)
#         post["priority"] = 0.8
#         if render:
#             cls.render_text(post)
#             post["meta"]["images"] = cls.extract_images(post)
# 
#     @classmethod
#     def all_extensions(cls):
#         return cls._markdown_extensions
# 
#     @classmethod
#     def set_custom_extensions(cls, extensions):
#         if type(extensions) == list:
#             cls._markdown_extensions.extend(extensions)
# 
# Path: flask_blogging/signals.py



    from builtins import object
from .processor import PostProcessor
from flask_principal import Principal, Permission, RoleNeed
from .signals import engine_initialised, post_processed, blueprint_created
from flask_fileupload import FlaskFileUpload
        from .views import create_blueprint

    def init_app(self, app, storage=None, cache=None, file_upload=None):
        """
        Initialize the engine.

        :param app: The app to use
        :type app: Object
        :param storage: The blog storage instance that implements the
        :type storage: Object
        :param cache: (Optional) A Flask-Cache object to enable caching
        :type cache: Object
         ``Storage`` class interface.
        """

        self.app = app
        self.config = self.app.config
        self.storage = storage or self.storage
        self.file_upload = file_upload or self.file_upload
        self.cache = cache or self.cache
        self._register_plugins(self.app, self.config)

        blog_app = create_blueprint(__name__, self)
        # external urls
        blueprint_created.send(self.app, engine=self, blueprint=blog_app)
        self.app.register_blueprint(
            blog_app, url_prefix=self.config.get("BLOGGING_URL_PREFIX"))

        self.app.extensions["FLASK_BLOGGING_ENGINE"] = self  # duplicate
        self.app.extensions["blogging"] = self
        self.principal = Principal(self.app)

# Path: flask_blogging/processor.py
# class PostProcessor(object):
# 
#     _markdown_extensions = [MathJaxExtension(), MetaExtension()]
# 
#     @staticmethod
#     def create_slug(title):
#         return slugify(title)
# 
#     @staticmethod
#     def extract_images(post):
#         regex = re.compile(r'<\s*img [^>]*src="([^"]+)')
#         return regex.findall(post["rendered_text"])
# 
#     @classmethod
#     def construct_url(cls, post):
#         url = url_for("blogging.page_by_id", post_id=post["post_id"],
#                       slug=cls.create_slug(post["title"]))
#         return url
# 
#     @classmethod
#     def render_text(cls, post):
#         md = markdown.Markdown(extensions=cls.all_extensions())
#         post["rendered_text"] = md.convert(post["text"])
#         post["meta"] = md.Meta
# 
#     @classmethod
#     def is_author(cls, post, user):
#         return user.get_id() == u''+str(post['user_id'])
# 
#     @classmethod
#     def process(cls, post, render=True):
#         """
#         This method takes the post data and renders it
#         :param post:
#         :param render:
#         :return:
#         """
#         post["slug"] = cls.create_slug(post["title"])
#         post["editable"] = cls.is_author(post, current_user)
#         post["url"] = cls.construct_url(post)
#         post["priority"] = 0.8
#         if render:
#             cls.render_text(post)
#             post["meta"]["images"] = cls.extract_images(post)
# 
#     @classmethod
#     def all_extensions(cls):
#         return cls._markdown_extensions
# 
#     @classmethod
#     def set_custom_extensions(cls, extensions):
#         if type(extensions) == list:
#             cls._markdown_extensions.extend(extensions)
# 
# Path: flask_blogging/signals.py



# Path: flask_blogging/engine.py
    from builtins import object
from .processor import PostProcessor
from flask_principal import Principal, Permission, RoleNeed
from .signals import engine_initialised, post_processed, blueprint_created
from flask_fileupload import FlaskFileUpload
        from .views import create_blueprint


    def init_app(self, app, storage=None, cache=None, file_upload=None):
        """
        Initialize the engine.

        :param app: The app to use
        :type app: Object
        :param storage: The blog storage instance that implements the
        :type storage: Object
        :param cache: (Optional) A Flask-Cache object to enable caching
        :type cache: Object
         ``Storage`` class interface.
        """

        self.app = app
        self.config = self.app.config
        self.storage = storage or self.storage
        self.file_upload = file_upload or self.file_upload
        self.cache = cache or self.cache
        self._register_plugins(self.app, self.config)

        blog_app = create_blueprint(__name__, self)
        # external urls
        blueprint_created.send(self.app, engine=self, blueprint=blog_app)
        self.app.register_blueprint(
            blog_app, url_prefix=self.config.get("BLOGGING_URL_PREFIX"))

        self.app.extensions["FLASK_BLOGGING_ENGINE"] = self  # duplicate
        self.app.extensions["blogging"] = self
        self.principal = Principal(self.app)

        engine_initialised.send(self.app, engine=self)