# Path: handroll/signals.py

# 
# Path: handroll/extensions/sitemap.py
# class SitemapExtension(Extension):
#     """Generate a sitemap from the HTML pages of the site."""
# 
#     handle_frontmatter_loaded = True
#     handle_pre_composition = True
#     handle_post_composition = True
# 
#     def __init__(self, config):
#         super(SitemapExtension, self).__init__(config)
#         self.urls = set()
#         self._composers = None
#         self._resolver = None
#         # Assume that the sitemap needs to be generated at startup.
#         self._dirty = True
# 
#     def on_pre_composition(self, director):
#         self._composers = director.composers
#         self._resolver = director.resolver
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         composer = self._composers.select_composer_for(source_file)
#         if composer.get_output_extension(source_file) == '.html':
#             url = self._resolver.as_url(source_file)
#             if url not in self.urls:
#                 self.urls.add(url)
#                 self._dirty = True
# 
#     def on_post_composition(self, director):
#         if not self._dirty:
#             return
#         logger.info(_('Generating sitemap ...'))
#         sitemap_path = os.path.join(director.outdir, 'sitemap.txt')
#         with open(sitemap_path, 'w') as sitemap:
#             for url in sorted(self.urls):
#                 sitemap.write(url + '\n')
#         self._dirty = False
# 
# 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.extensions.sitemap import SitemapExtension
from handroll.tests import TestCase
# Copyright (c) 2017, Matt Layman




class TestSitemapExtention(TestCase):

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

    def _make_one(self, director):
        director.config.parser.add_section('sitemap')
        extension = SitemapExtension(director.config)
        extension.on_pre_composition(director)
        return extension

    def test_handles_frontmatter_loaded(self):

# Path: handroll/signals.py

# 
# Path: handroll/extensions/sitemap.py
# class SitemapExtension(Extension):
#     """Generate a sitemap from the HTML pages of the site."""
# 
#     handle_frontmatter_loaded = True
#     handle_pre_composition = True
#     handle_post_composition = True
# 
#     def __init__(self, config):
#         super(SitemapExtension, self).__init__(config)
#         self.urls = set()
#         self._composers = None
#         self._resolver = None
#         # Assume that the sitemap needs to be generated at startup.
#         self._dirty = True
# 
#     def on_pre_composition(self, director):
#         self._composers = director.composers
#         self._resolver = director.resolver
# 
#     def on_frontmatter_loaded(self, source_file, frontmatter):
#         composer = self._composers.select_composer_for(source_file)
#         if composer.get_output_extension(source_file) == '.html':
#             url = self._resolver.as_url(source_file)
#             if url not in self.urls:
#                 self.urls.add(url)
#                 self._dirty = True
# 
#     def on_post_composition(self, director):
#         if not self._dirty:
#             return
#         logger.info(_('Generating sitemap ...'))
#         sitemap_path = os.path.join(director.outdir, 'sitemap.txt')
#         with open(sitemap_path, 'w') as sitemap:
#             for url in sorted(self.urls):
#                 sitemap.write(url + '\n')
#         self._dirty = False
# 
# 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_sitemap_extension.py
import os
from handroll import signals
from handroll.extensions.sitemap import SitemapExtension
from handroll.tests import TestCase

# Copyright (c) 2017, Matt Layman




class TestSitemapExtention(TestCase):

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

    def _make_one(self, director):
        director.config.parser.add_section('sitemap')
        extension = SitemapExtension(director.config)
        extension.on_pre_composition(director)
        return extension

    def test_handles_frontmatter_loaded(self):

        extension = SitemapExtension(None)