# Path: handroll/signals.py

# 
# 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/og.py
# class OpenGraphExtension(Extension):
#     """Inject Open Graph 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('open_graph'):
#             raise AbortError(_(
#                 'An open_graph section is missing in the configuration file.'))
# 
#         if not self._config.parser.has_option('open_graph', 'default_image'):
#             raise AbortError(_(
#                 'A default image URL is missing in the configuration file.'))
# 
#         self._resolver = director.resolver
#         self._url_resolver = URLResolver(
#             self._config,
#             self._config.parser.get('open_graph', 'default_image'))
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         if frontmatter.get('blog'):
#             self.add_blog_metadata(source_file, frontmatter)
#         else:
#             frontmatter['open_graph_metadata'] = ''
# 
#     def add_blog_metadata(self, source_file, frontmatter):
#         url = self._resolver.as_url(source_file)
#         metadata = [
#             '<meta property="og:type" content="article" />',
#             '<meta property="og:url" content="{}" />'.format(url),
#         ]
# 
#         image = self._url_resolver.resolve(url, frontmatter.get('image'))
#         metadata.append(
#             u'<meta property="og:image" content="{}" />'.format(image))
# 
#         title = frontmatter.get('title', '')
#         title = title.replace('"', '\'')
#         metadata.append(
#             u'<meta property="og:title" content="{}" />'.format(title))
# 
#         if frontmatter.get('summary'):
#             summary = frontmatter.get('summary', '')
#             summary = summary.replace('"', '\'')
#             metadata.append(
#                 u'<meta property="og:description" content="{}" />'.format(
#                     summary))
# 
#         frontmatter['open_graph_metadata'] = '\n'.join(metadata)
# 
# Path: handroll/tests/testcase.py
# class TestCase(unittest.TestCase):
# 
#     def __init__(self, methodName='runTest'):
#         super(TestCase, self).__init__(methodName)
#         self.factory = Factory()


import os
from handroll import signals
from handroll.exceptions import AbortError
from handroll.extensions.og import OpenGraphExtension
from handroll.tests import TestCase
# Copyright (c) 2017, Matt Layman




class TestOpenGraphExtension(TestCase):

    def tearDown(self):
        super(TestOpenGraphExtension, self).tearDown()
        # Clean up any attached extension instance.
        signals.frontmatter_loaded.receivers.clear()

# Path: handroll/signals.py

# 
# 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/og.py
# class OpenGraphExtension(Extension):
#     """Inject Open Graph 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('open_graph'):
#             raise AbortError(_(
#                 'An open_graph section is missing in the configuration file.'))
# 
#         if not self._config.parser.has_option('open_graph', 'default_image'):
#             raise AbortError(_(
#                 'A default image URL is missing in the configuration file.'))
# 
#         self._resolver = director.resolver
#         self._url_resolver = URLResolver(
#             self._config,
#             self._config.parser.get('open_graph', 'default_image'))
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         if frontmatter.get('blog'):
#             self.add_blog_metadata(source_file, frontmatter)
#         else:
#             frontmatter['open_graph_metadata'] = ''
# 
#     def add_blog_metadata(self, source_file, frontmatter):
#         url = self._resolver.as_url(source_file)
#         metadata = [
#             '<meta property="og:type" content="article" />',
#             '<meta property="og:url" content="{}" />'.format(url),
#         ]
# 
#         image = self._url_resolver.resolve(url, frontmatter.get('image'))
#         metadata.append(
#             u'<meta property="og:image" content="{}" />'.format(image))
# 
#         title = frontmatter.get('title', '')
#         title = title.replace('"', '\'')
#         metadata.append(
#             u'<meta property="og:title" content="{}" />'.format(title))
# 
#         if frontmatter.get('summary'):
#             summary = frontmatter.get('summary', '')
#             summary = summary.replace('"', '\'')
#             metadata.append(
#                 u'<meta property="og:description" content="{}" />'.format(
#                     summary))
# 
#         frontmatter['open_graph_metadata'] = '\n'.join(metadata)
# 
# Path: handroll/tests/testcase.py
# class TestCase(unittest.TestCase):
# 
#     def __init__(self, methodName='runTest'):
#         super(TestCase, self).__init__(methodName)
#         self.factory = Factory()


# Path: handroll/tests/test_open_graph_extension.py
import os
from handroll import signals
from handroll.exceptions import AbortError
from handroll.extensions.og import OpenGraphExtension
from handroll.tests import TestCase

# Copyright (c) 2017, Matt Layman




class TestOpenGraphExtension(TestCase):

    def tearDown(self):
        super(TestOpenGraphExtension, self).tearDown()
        # Clean up any attached extension instance.
        signals.frontmatter_loaded.receivers.clear()

        signals.pre_composition.receivers.clear()