# 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/twitter.py
# 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(_(
#                 'A default image URL is missing in the configuration file.'))
# 
#         if not self._config.parser.has_option('twitter', 'site_username'):
#             raise AbortError(_(
#                 'A site username is missing in the configuration file.'))
# 
#         self._resolver = director.resolver
#         self._url_resolver = URLResolver(
#             self._config,
#             self._config.parser.get('twitter', 'default_image'))
#         self._site = self._config.parser.get('twitter', 'site_username')
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         if frontmatter.get('blog'):
#             self.add_metadata(source_file, frontmatter)
#         else:
#             frontmatter['twitter_metadata'] = ''
# 
#     def add_metadata(self, source_file, frontmatter):
#         metadata = [
#             '<meta name="twitter:card" content="summary" />',
#             '<meta name="twitter:site" content="{}" />'.format(self._site),
#         ]
# 
#         url = self._resolver.as_url(source_file)
#         image = self._url_resolver.resolve(url, frontmatter.get('image'))
#         metadata.append(
#             u'<meta name="twitter:image" content="{}" />'.format(image))
# 
#         title = frontmatter.get('title', '')
#         title = title.replace('"', '\'')
#         metadata.append(
#             u'<meta name="twitter:title" content="{}" />'.format(title))
# 
#         if frontmatter.get('summary'):
#             summary = frontmatter.get('summary', '')
#             summary = summary.replace('"', '\'')
#             metadata.append(
#                 u'<meta name="twitter:description" content="{}" />'.format(
#                     summary))
# 
#         frontmatter['twitter_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.twitter import TwitterExtension
from handroll.tests import TestCase



class TestTwitterExtension(TestCase):

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

    def _make_one(self, director):
        director.config.parser.add_section('twitter')
        director.config.parser.set(
            'twitter', 'default_image',
            'http://www.example.com/images/twitter.png')
        director.config.parser.set('twitter', 'site_username', '@mblayman')
        extension = TwitterExtension(director.config)
        extension.on_pre_composition(director)
        return extension

    def test_handles_frontmatter_loaded(self):
        extension = TwitterExtension(None)
        self.assertTrue(extension.handle_frontmatter_loaded)

    def test_handles_pre_composition(self):
        extension = TwitterExtension(None)
        self.assertTrue(extension.handle_pre_composition)

    def test_no_twitter_data(self):

# 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/twitter.py
# 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(_(
#                 'A default image URL is missing in the configuration file.'))
# 
#         if not self._config.parser.has_option('twitter', 'site_username'):
#             raise AbortError(_(
#                 'A site username is missing in the configuration file.'))
# 
#         self._resolver = director.resolver
#         self._url_resolver = URLResolver(
#             self._config,
#             self._config.parser.get('twitter', 'default_image'))
#         self._site = self._config.parser.get('twitter', 'site_username')
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         if frontmatter.get('blog'):
#             self.add_metadata(source_file, frontmatter)
#         else:
#             frontmatter['twitter_metadata'] = ''
# 
#     def add_metadata(self, source_file, frontmatter):
#         metadata = [
#             '<meta name="twitter:card" content="summary" />',
#             '<meta name="twitter:site" content="{}" />'.format(self._site),
#         ]
# 
#         url = self._resolver.as_url(source_file)
#         image = self._url_resolver.resolve(url, frontmatter.get('image'))
#         metadata.append(
#             u'<meta name="twitter:image" content="{}" />'.format(image))
# 
#         title = frontmatter.get('title', '')
#         title = title.replace('"', '\'')
#         metadata.append(
#             u'<meta name="twitter:title" content="{}" />'.format(title))
# 
#         if frontmatter.get('summary'):
#             summary = frontmatter.get('summary', '')
#             summary = summary.replace('"', '\'')
#             metadata.append(
#                 u'<meta name="twitter:description" content="{}" />'.format(
#                     summary))
# 
#         frontmatter['twitter_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_twitter_extension.py
import os
from handroll import signals
from handroll.exceptions import AbortError
from handroll.extensions.twitter import TwitterExtension
from handroll.tests import TestCase




class TestTwitterExtension(TestCase):

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

    def _make_one(self, director):
        director.config.parser.add_section('twitter')
        director.config.parser.set(
            'twitter', 'default_image',
            'http://www.example.com/images/twitter.png')
        director.config.parser.set('twitter', 'site_username', '@mblayman')
        extension = TwitterExtension(director.config)
        extension.on_pre_composition(director)
        return extension

    def test_handles_frontmatter_loaded(self):
        extension = TwitterExtension(None)
        self.assertTrue(extension.handle_frontmatter_loaded)

    def test_handles_pre_composition(self):
        extension = TwitterExtension(None)
        self.assertTrue(extension.handle_pre_composition)

    def test_no_twitter_data(self):

        extension = TwitterExtension(None)