예제 #1
0
    def pending_test(self):
        """Pending status"""
        file = self.post_tests_dir / 'published.md'
        post = Post(file)
        post.timestamp = times.now() + timedelta(days=1)

        self.assertTrue(post.is_pending)
        self.assertFalse(post.is_published)
        self.assertFalse(post.is_draft)
예제 #2
0
    def pending_test(self):
        """Pending status"""
        file = self.post_tests_dir / 'published.md'
        post = Post(file)
        post.timestamp = times.now() + timedelta(days=1)

        self.assertTrue(post.is_pending)
        self.assertFalse(post.is_published)
        self.assertFalse(post.is_draft)
예제 #3
0
    def test_lazy_links(self):
        from engineer.conf import settings
        from engineer.models import Post

        settings.reload('config.yaml')

        post = Post('posts/lazy_markdown_links.md')
        self.assertEqual(post.content_preprocessed.strip(),
                         self._expected_output.strip())

        post = Post('posts/lazy_markdown_links2.md')
        self.assertEqual(post.content_preprocessed.strip(),
                         self._expected_output2.strip())
예제 #4
0
    def global_links_test(self):
        """Global links test."""
        from engineer.conf import settings

        settings.reload(self.config_dir / 'global_links_settings.yaml')
        post = Post(self.post_dir / 'global_links_post.md')

        expected_content = """
<p><a href="http://tylerbutler.com">Tyler Butler</a> is the author of&nbsp;Engineer.</p>
<p>He does not like to be called <a href="http://tylerbutler.com">Ty</a>.</p>
        """

        actual_content = unicode(post.convert_to_html(post.content_preprocessed))
        self.assertEqual(actual_content.strip(), expected_content.strip())
예제 #5
0
    def published_test(self):
        """Published status"""
        file = self.post_tests_dir / 'published.md'
        post = Post(file)

        self.assertTrue(post.is_published)
        self.assertFalse(post.is_draft)
예제 #6
0
    def load_all(input):
        new_posts = PostCollection()
        cached_posts = PostCollection()

        file_list = []
        for directory in input:
            logger.info("Getting posts from %s." % directory)
            file_list.extend(path(directory).listdir('*.md') + path(directory).listdir('*.markdown'))

        for f in file_list:
            try:
                if f not in settings.POST_CACHE:
                    logger.debug("'%s': Beginning to parse." % f.basename())
                    post = Post(f)
                    logger.debug("'%s': Parsed successfully." % f.basename())
                    new_posts.append(post)
                    logger.info("'%s': LOADED" % f.basename())
                else:
                    logger.info("'%s': FROM CACHE" % f.basename())
                    cached_posts.append(settings.POST_CACHE[f])
            except PostMetadataError as e:
                logger.warning("SKIPPING '%s': metadata is invalid. %s" % (f.basename(), e.message))
                continue
        logger.console("Found %d new posts and loaded %s from the cache." % (len(new_posts), len(cached_posts)))

        settings.CACHE.sync()
        return new_posts, cached_posts
예제 #7
0
    def multiple_tag_test(self):
        """Multiple tags"""
        file = self.post_tests_dir / 'tag_multiple.md'
        post = Post(file)

        self.assertEqual(len(post.tags), 3)
        self.assertIsInstance(post.tags, list)
예제 #8
0
    def single_tag_test(self):
        """Single tag"""
        file = self.post_tests_dir / 'tag_single.md'
        post = Post(file)

        self.assertEqual(post.tags, ['single'])
        self.assertEqual(len(post.tags), 1)
예제 #9
0
    def draft_default_test(self):
        """Draft default status"""
        file = self.post_tests_dir / 'fenced_metadata.md'
        post = Post(file)

        self.assertTrue(post.is_draft)
        self.assertFalse(post.is_published)
예제 #10
0
    def custom_properties_test(self):
        """Custom properties"""
        file = self.post_tests_dir / 'custom_properties.md'
        post = Post(file)

        self.assertEqual(len(post.custom_properties), 2)
        self.assertIsInstance(post.custom_properties['custom_list'], list)
        self.assertIsInstance(post.custom_properties['custom_dict'], dict)
예제 #11
0
    def default_metadata_test(self):
        """Metadata defaults"""
        file = self.post_tests_dir / 'fenced_metadata.md'
        post = Post(file)

        self.assertNotEqual(post.slug, None)
        self.assertNotEqual(post.timestamp, None)
        self.assertNotEqual(post.status, None)
예제 #12
0
    def cased_metadata_test(self):
        """Cased metadata"""
        file = self.post_tests_dir / 'cased_metadata.md'
        post = Post(file)

        self.assertEqual(post.title, 'Cased Metadata')
        self.assertEqual(post.custom_properties['customproperty'], 'custom')
        self.assertEqual(len(post.tags), 2)
예제 #13
0
    def unicode_content_test(self):
        """Unicode post content."""
        file = self.post_dir / 'unicode_content.md'

        # Just loading the post will throw an exception if the unicode handling is broken - no need to specifically
        # assert anything for that case.
        post = Post(file)

        self.assertIn(u"also a “unicode character” in the metadata!", post.tags)
예제 #14
0
    def test_pretty(self):
        from engineer.conf import settings

        settings.reload(self.config_dir / 'permalinks_pretty.yaml')
        file = self.post_dir / 'tag_multiple.md'
        post = Post(file)

        self.assertEqual(post.url, '/test/2012/09/tag-multiple/')
        self.assertEqual(post.output_file_name, 'index.html')
예제 #15
0
    def test_timestamp_custom(self):
        from engineer.conf import settings

        settings.reload(self.config_dir / 'permalinks_timestamp_custom.yaml')
        file = self.post_dir / 'tag_multiple.md'
        post = Post(file)

        self.assertEqual(post.url, '/test/2012-09-04/tag-multiple.html')
        self.assertEqual(post.output_file_name, 'tag-multiple.html')
예제 #16
0
    def test_end_slash(self):
        from engineer.conf import settings

        settings.reload(self.post_tests_dir / 'permalinks_end_slash.yaml')
        file = self.post_tests_dir / 'tag_multiple.md'
        post = Post(file)

        self.assertEqual(post.url, '/test/test/tag-multiple/')
        self.assertEqual(post.output_file_name, 'index.html')
예제 #17
0
    def test_slug(self):
        from engineer.conf import settings

        settings.reload(self.post_tests_dir / 'permalinks_slug.yaml')
        file = self.post_tests_dir / 'tag_multiple.md'
        post = Post(file)

        self.assertEqual(post.url, '/test/2012/09/04/tag-multiple.html')
        self.assertEqual(post.output_file_name, 'tag-multiple.html')
예제 #18
0
    def test_no_leading_zeroes(self):
        from engineer.conf import settings

        settings.reload(self.config_dir / 'permalinks_no_leading_zeroes.yaml')
        file = self.post_dir / 'tag_multiple.md'
        post = Post(file)

        self.assertEqual(post.url, '/test/2012/9/4/tag-multiple.html')
        self.assertEqual(post.output_file_name, 'tag-multiple.html')
예제 #19
0
    def test_post_renamer_custom_config(self):
        from engineer.conf import settings
        from engineer.models import Post

        settings.reload('custom_renames.yaml')

        post = Post('posts/draft_post.md')
        self.assertEqual(post.source.name, 'draft_post.md')
        self.assertTrue(post.source.exists())

        post = Post('posts/review_post.md')
        self.assertEqual(post.source.name, '2012-11-02-a-post-in-review.md')
        self.assertTrue(post.source.exists())
        self.assertFalse(path('posts/review_post.md').exists())

        post = Post('posts/published_post_with_timestamp.md')
        self.assertEqual(post.source.name, '(p) 2012-11-02 a-published-post.md')
        self.assertTrue(post.source.exists())
        self.assertFalse(path('posts/published_post_with_timestamp.md').exists())
예제 #20
0
    def regular_loading_test(self):
        from engineer.conf import settings
        from engineer.loaders import LocalLoader
        from engineer.models import Post, PostCollection

        post_file = self.post_dir / 'subdir/post_in_subdir.md'
        expected_post = Post(post_file)
        new_posts, cached_posts = LocalLoader.load_all(settings.POST_DIR)
        all_posts = PostCollection(new_posts + cached_posts)

        self.assertNotIn(expected_post, all_posts)
예제 #21
0
    def test_force_fenced_metadata(self):
        from engineer.conf import settings
        from engineer.models import Post

        settings.reload('finalization_fenced.yaml')
        settings.create_required_directories()
        post = Post('posts/finalization_draft.md')
        self.assertEqual(post.title, "Finalization Draft")

        expected_output = '---\n\n' + finalization_draft_output
        with open(post.source, mode='rb') as post_file:
            content = post_file.read()
        self.assertEqual(content, expected_output)
예제 #22
0
    def load_all(input):
        new_posts = PostCollection()
        cached_posts = PostCollection()

        # parse input directories into a dict. The key is the path, the value is a bool indicating
        # whether the path should be walked when looking for posts or not
        directories = {}
        for dir in input:
            if unicode(dir).endswith('*'):
                directories[path(
                    dir[:-1]).expand().abspath().normpath()] = True
            else:
                directories[path(dir).expand().abspath().normpath()] = False

        file_list = []
        for directory, should_walk in directories.iteritems():
            if directory.exists():
                logger.info("Getting posts from %s." % directory)
                if should_walk:
                    file_list.extend(
                        [f for f in directory.walkfiles('*.md')] +
                        [f for f in directory.files('*.markdown')])
                else:
                    file_list.extend(
                        directory.files('*.md') +
                        directory.files('*.markdown'))
            else:
                logger.warning("Can't find source post directory %s." %
                               directory)

        for f in file_list:
            try:
                if f not in settings.POST_CACHE:
                    logger.debug("'%s': Beginning to parse." % f.basename())
                    post = Post(f)
                    logger.debug("'%s': Parsed successfully." % f.basename())
                    new_posts.append(post)
                    logger.info("'%s': LOADED" % f.basename())
                else:
                    logger.info("'%s': FROM CACHE" % f.basename())
                    cached_posts.append(settings.POST_CACHE[f])
            except PostMetadataError as e:
                logger.warning("SKIPPING '%s': metadata is invalid. %s" %
                               (f.basename(), e.message))
                continue
        logger.console("Found %d new posts and loaded %s from the cache." %
                       (len(new_posts), len(cached_posts)))

        settings.CACHE.sync()
        return new_posts, cached_posts
예제 #23
0
    def test_finalization_unfenced_post(self):
        from engineer.conf import settings
        from engineer.models import Post

        settings.reload('finalization_unfenced.yaml')
        settings.create_required_directories()
        post = Post('posts/finalization_fenced.md')
        self.assertEqual(post.title, "Finalization Fenced")

        expected_output = ''.join(
            finalization_fenced_output.splitlines(True)[2:])
        with open(post.source, mode='rb') as post_file:
            content = post_file.read()
        self.assertEqual(content, expected_output)
예제 #24
0
    def test_lazy_links_persist(self):
        from engineer.conf import settings
        from engineer.models import Post

        settings.reload('lazy_links_persist.yaml')

        post = Post('posts/lazy_markdown_links.md')
        self.assertEqual(post.content_preprocessed.strip(),
                         self._expected_output.strip())

        with open(post.source, mode='rb') as post_file:
            content = post_file.read()
        self.assertEqual(
            content.strip(),
            self._expected_metadata + self._expected_output.strip())
예제 #25
0
파일: bundled.py 프로젝트: jheyse/engineer
    def preprocess(cls, post, metadata):
        from engineer.models import Post

        # First check if either form of the break marker is present using the regex
        parsed_content = re.match(cls._regex, post.content_preprocessed)
        if parsed_content is None or parsed_content.group('teaser_content') is None:
            post.content_teaser = None
            return post

        # Post is meant to be broken apart, so normalize the break marker to the HTML comment form.
        post.content_preprocessed = unicode(parsed_content.group('teaser_content') +
                                            '\n\n<!-- more -->\n\n' +
                                            parsed_content.group('rest_of_content'))

        # Convert the full post to HTML, then use the regex again to split the resulting HTML post. This is needed
        # since Markdown might have links in the first half of the post that are listed at the bottom. By converting
        # the whole post to HTML first then splitting we get a correctly processed HTML teaser.
        parsed_content = re.match(cls._regex, Post.convert_to_html(post.content_preprocessed))
        post.content_teaser = parsed_content.group('teaser_content')
        return post
예제 #26
0
    def preprocess(cls, post, metadata):
        from engineer.models import Post

        # First check if either form of the break marker is present using the regex
        parsed_content = re.match(cls._regex, post.content_preprocessed)
        if parsed_content is None or parsed_content.group(
                'teaser_content') is None:
            post.content_teaser = None
            return post

        # Post is meant to be broken apart, so normalize the break marker to the HTML comment form.
        post.content_preprocessed = unicode(
            parsed_content.group('teaser_content') + '\n\n<!-- more -->\n\n' +
            parsed_content.group('rest_of_content'))

        # Convert the full post to HTML, then use the regex again to split the resulting HTML post. This is needed
        # since Markdown might have links in the first half of the post that are listed at the bottom. By converting
        # the whole post to HTML first then splitting we get a correctly processed HTML teaser.
        parsed_content = re.match(
            cls._regex, Post.convert_to_html(post.content_preprocessed))
        post.content_teaser = parsed_content.group('teaser_content')
        return post
예제 #27
0
    def test_finalization_draft(self):
        from engineer.conf import settings
        from engineer.models import Post

        settings.reload('finalization.yaml')
        settings.create_required_directories()
        post = Post('posts/finalization_draft.md')
        self.assertEqual(post.title, "Finalization Draft")

        expected_output = """title: Finalization Draft
status: draft
url: /{year:02d}/{month:02d}/{day:02d}/finalization-draft/
slug: finalization-draft
tags:
- tag

---

This is a finalization test post.
""".format(year=post.timestamp_local.year, month=post.timestamp_local.month, day=post.timestamp_local.day)

        with open(post.source, mode='rb') as post_file:
            content = post_file.read()
        self.assertEqual(content, expected_output)
예제 #28
0
    def post_breaks_simple_test(self):
        """Post breaks of the form: -- more --"""
        file = self.post_tests_dir / 'post_breaks_simple.md'
        post = Post(file)

        self.assertNotEqual(getattr(post, 'content_teaser', None), None)
예제 #29
0
    def post_breaks_octopress_test(self):
        """Post breaks of the form: <!-- more -->"""
        file = self.post_tests_dir / 'post_breaks_octopress.md'
        post = Post(file)

        self.assertNotEqual(getattr(post, 'content_teaser', None), None)
예제 #30
0
 def missing_metadata_test(self):
     """Missing metadata"""
     file = self.post_tests_dir / 'missing_metadata.md'
     with self.assertRaises(PostMetadataError):
         Post(file)
예제 #31
0
    def fenced_metadata_test(self):
        """Fenced metadata"""
        file = self.post_tests_dir / 'fenced_metadata.md'
        post = Post(file)

        self.assertEqual(post._fence, True)
예제 #32
0
    def no_custom_properties_test(self):
        """No custom properties"""
        file = self.post_tests_dir / 'fenced_metadata.md'
        post = Post(file)

        self.assertEqual(post.custom_properties, {})