# Path: handroll/exceptions.py
# class AbortError(Exception):
#     """Any fatal errors that would prevent handroll from proceeding should
#     signal with the ``AbortError`` exception."""
# 
# Path: handroll/extensions/base.py
# class Extension(object):
#     """A base extension which hooks handler methods to handroll's signals."""
# 
#     handle_frontmatter_loaded = False
#     handle_pre_composition = False
#     handle_post_composition = False
# 
#     def __init__(self, config):
#         self._config = config
#         # Handler functions are put in a dictionary to keep references to them.
#         # Blinker behaves in strange ways without the references.
#         self._handlers = {}
# 
#         if self.handle_frontmatter_loaded:
#             def _handle_frontmatter_loaded(source_file, **kwargs):
#                 self.on_frontmatter_loaded(source_file, kwargs['frontmatter'])
#             self._handlers['frontmatter_loaded'] = _handle_frontmatter_loaded
#             signals.frontmatter_loaded.connect(_handle_frontmatter_loaded)
# 
#         if self.handle_post_composition:
#             def _handle_post_composition(director, **kwargs):
#                 self.on_post_composition(director)
#             self._handlers['post_composition'] = _handle_post_composition
#             signals.post_composition.connect(_handle_post_composition)
# 
#         if self.handle_pre_composition:
#             def _handle_pre_composition(director, **kwargs):
#                 self.on_pre_composition(director)
#             self._handlers['pre_composition'] = _handle_pre_composition
#             signals.pre_composition.connect(_handle_pre_composition)
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         """Handle the ``frontmatter_loaded`` signal.
# 
#         Activate this handler by setting ``handle_frontmatter_loaded``
#         to ``True`` in the extension subclass.
# 
#         :param source_file: Absolute path of the source file
#         :param frontmatter: Dictionary of parsed frontmatter
#         """
#         raise NotImplementedError()
# 
#     def on_pre_composition(self, director):
#         """Handle the ``pre_composition`` signal.
# 
#         Activate this handler by setting ``handle_pre_composition``
#         to ``True`` in the extension subclass.
# 
#         :param director: The director instance
#         """
#         raise NotImplementedError()
# 
#     def on_post_composition(self, director):
#         """Handle the ``post_composition`` signal.
# 
#         Activate this handler by setting ``handle_post_composition``
#         to ``True`` in the extension subclass.
# 
#         :param director: The director instance
#         """
#         raise NotImplementedError()
# 
# Path: handroll/i18n.py

# 
# Path: handroll/resolver.py
# class URLResolver(object):
#     """Resolve a URL in relation to another URL."""
# 
#     def __init__(self, config, default_url):
#         self._config = config
#         self._default_url = default_url
# 
#     def resolve(self, base_url, path):
#         """Resolve a path relative to a base URL.
# 
#         Use the default if the path is empty.
#         """
#         if path:
#             if path.startswith('/'):
#                 return self._config.domain + path
#             else:
#                 url_parts = base_url.split('/')
#                 url_parts[-1] = path
#                 return '/'.join(url_parts)
#         return self._default_url


from handroll.exceptions import AbortError
from handroll.extensions.base import Extension
from handroll.i18n import _
from handroll.resolver import URLResolver
# Copyright (c) 2017, Matt Layman



class TwitterExtension(Extension):
    """Inject Twitter metadata into the template context."""

    handle_frontmatter_loaded = True
    handle_pre_composition = True

    def on_pre_composition(self, director):
        if not self._config.parser.has_section('twitter'):
            raise AbortError(_(
                'An twitter section is missing in the configuration file.'))

        if not self._config.parser.has_option('twitter', 'default_image'):

# Path: handroll/exceptions.py
# class AbortError(Exception):
#     """Any fatal errors that would prevent handroll from proceeding should
#     signal with the ``AbortError`` exception."""
# 
# Path: handroll/extensions/base.py
# class Extension(object):
#     """A base extension which hooks handler methods to handroll's signals."""
# 
#     handle_frontmatter_loaded = False
#     handle_pre_composition = False
#     handle_post_composition = False
# 
#     def __init__(self, config):
#         self._config = config
#         # Handler functions are put in a dictionary to keep references to them.
#         # Blinker behaves in strange ways without the references.
#         self._handlers = {}
# 
#         if self.handle_frontmatter_loaded:
#             def _handle_frontmatter_loaded(source_file, **kwargs):
#                 self.on_frontmatter_loaded(source_file, kwargs['frontmatter'])
#             self._handlers['frontmatter_loaded'] = _handle_frontmatter_loaded
#             signals.frontmatter_loaded.connect(_handle_frontmatter_loaded)
# 
#         if self.handle_post_composition:
#             def _handle_post_composition(director, **kwargs):
#                 self.on_post_composition(director)
#             self._handlers['post_composition'] = _handle_post_composition
#             signals.post_composition.connect(_handle_post_composition)
# 
#         if self.handle_pre_composition:
#             def _handle_pre_composition(director, **kwargs):
#                 self.on_pre_composition(director)
#             self._handlers['pre_composition'] = _handle_pre_composition
#             signals.pre_composition.connect(_handle_pre_composition)
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         """Handle the ``frontmatter_loaded`` signal.
# 
#         Activate this handler by setting ``handle_frontmatter_loaded``
#         to ``True`` in the extension subclass.
# 
#         :param source_file: Absolute path of the source file
#         :param frontmatter: Dictionary of parsed frontmatter
#         """
#         raise NotImplementedError()
# 
#     def on_pre_composition(self, director):
#         """Handle the ``pre_composition`` signal.
# 
#         Activate this handler by setting ``handle_pre_composition``
#         to ``True`` in the extension subclass.
# 
#         :param director: The director instance
#         """
#         raise NotImplementedError()
# 
#     def on_post_composition(self, director):
#         """Handle the ``post_composition`` signal.
# 
#         Activate this handler by setting ``handle_post_composition``
#         to ``True`` in the extension subclass.
# 
#         :param director: The director instance
#         """
#         raise NotImplementedError()
# 
# Path: handroll/i18n.py

# 
# Path: handroll/resolver.py
# class URLResolver(object):
#     """Resolve a URL in relation to another URL."""
# 
#     def __init__(self, config, default_url):
#         self._config = config
#         self._default_url = default_url
# 
#     def resolve(self, base_url, path):
#         """Resolve a path relative to a base URL.
# 
#         Use the default if the path is empty.
#         """
#         if path:
#             if path.startswith('/'):
#                 return self._config.domain + path
#             else:
#                 url_parts = base_url.split('/')
#                 url_parts[-1] = path
#                 return '/'.join(url_parts)
#         return self._default_url


# Path: handroll/extensions/twitter.py
from handroll.exceptions import AbortError
from handroll.extensions.base import Extension
from handroll.i18n import _
from handroll.resolver import URLResolver

# Copyright (c) 2017, Matt Layman



class TwitterExtension(Extension):
    """Inject Twitter metadata into the template context."""

    handle_frontmatter_loaded = True
    handle_pre_composition = True

    def on_pre_composition(self, director):
        if not self._config.parser.has_section('twitter'):
            raise AbortError(_(
                'An twitter section is missing in the configuration file.'))

        if not self._config.parser.has_option('twitter', 'default_image'):

            raise AbortError(_(