mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #283 from draftcode/default_category
DEFAULT_CATEGORY is ignored.
This commit is contained in:
commit
c71ad2babc
5 changed files with 43 additions and 3 deletions
|
|
@ -219,9 +219,10 @@ class ArticlesGenerator(Generator):
|
||||||
def generate_context(self):
|
def generate_context(self):
|
||||||
"""change the context"""
|
"""change the context"""
|
||||||
|
|
||||||
|
article_path = os.path.join(self.path, self.settings['ARTICLE_DIR'])
|
||||||
all_articles = []
|
all_articles = []
|
||||||
for f in self.get_files(
|
for f in self.get_files(
|
||||||
os.path.join(self.path, self.settings['ARTICLE_DIR']),
|
article_path,
|
||||||
exclude=self.settings['ARTICLE_EXCLUDES']):
|
exclude=self.settings['ARTICLE_EXCLUDES']):
|
||||||
try:
|
try:
|
||||||
content, metadata = read_file(f, settings=self.settings)
|
content, metadata = read_file(f, settings=self.settings)
|
||||||
|
|
@ -232,7 +233,7 @@ class ArticlesGenerator(Generator):
|
||||||
# if no category is set, use the name of the path as a category
|
# if no category is set, use the name of the path as a category
|
||||||
if 'category' not in metadata:
|
if 'category' not in metadata:
|
||||||
|
|
||||||
if os.path.dirname(f) == self.path:
|
if os.path.dirname(f) == article_path:
|
||||||
category = self.settings['DEFAULT_CATEGORY']
|
category = self.settings['DEFAULT_CATEGORY']
|
||||||
else:
|
else:
|
||||||
category = os.path.basename(os.path.dirname(f))\
|
category = os.path.basename(os.path.dirname(f))\
|
||||||
|
|
|
||||||
6
tests/content/TestCategory/article_with_category.rst
Normal file
6
tests/content/TestCategory/article_with_category.rst
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
This is an article with category !
|
||||||
|
##################################
|
||||||
|
|
||||||
|
:category: yeah
|
||||||
|
|
||||||
|
This article should be in 'yeah' category.
|
||||||
4
tests/content/TestCategory/article_without_category.rst
Normal file
4
tests/content/TestCategory/article_without_category.rst
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
This is an article without category !
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
This article should be in 'TestCategory' category.
|
||||||
6
tests/content/article_without_category.rst
Normal file
6
tests/content/article_without_category.rst
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
This is an article without category !
|
||||||
|
#####################################
|
||||||
|
|
||||||
|
This article should be in the DEFAULT_CATEGORY.
|
||||||
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from mock import MagicMock
|
from mock import MagicMock
|
||||||
|
import os
|
||||||
|
|
||||||
from pelican.generators import ArticlesGenerator
|
from pelican.generators import ArticlesGenerator
|
||||||
from pelican.settings import _DEFAULT_CONFIG
|
from pelican.settings import _DEFAULT_CONFIG
|
||||||
from .support import unittest
|
from .support import unittest
|
||||||
|
|
||||||
|
CUR_DIR = os.path.dirname(__file__)
|
||||||
|
|
||||||
class TestArticlesGenerator(unittest.TestCase):
|
class TestArticlesGenerator(unittest.TestCase):
|
||||||
|
|
||||||
|
|
@ -13,7 +15,7 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
|
|
||||||
generator = ArticlesGenerator(None, {'FEED': _DEFAULT_CONFIG['FEED']},
|
generator = ArticlesGenerator(None, {'FEED': _DEFAULT_CONFIG['FEED']},
|
||||||
None, _DEFAULT_CONFIG['THEME'], None,
|
None, _DEFAULT_CONFIG['THEME'], None,
|
||||||
None)
|
_DEFAULT_CONFIG['MARKUP'])
|
||||||
writer = MagicMock()
|
writer = MagicMock()
|
||||||
generator.generate_feeds(writer)
|
generator.generate_feeds(writer)
|
||||||
writer.write_feed.assert_called_with([], None, 'feeds/all.atom.xml')
|
writer.write_feed.assert_called_with([], None, 'feeds/all.atom.xml')
|
||||||
|
|
@ -23,3 +25,24 @@ class TestArticlesGenerator(unittest.TestCase):
|
||||||
writer = MagicMock()
|
writer = MagicMock()
|
||||||
generator.generate_feeds(writer)
|
generator.generate_feeds(writer)
|
||||||
self.assertFalse(writer.write_feed.called)
|
self.assertFalse(writer.write_feed.called)
|
||||||
|
|
||||||
|
def test_generate_context(self):
|
||||||
|
|
||||||
|
settings = _DEFAULT_CONFIG
|
||||||
|
settings['ARTICLE_DIR'] = 'content'
|
||||||
|
settings['DEFAULT_CATEGORY'] = 'Default'
|
||||||
|
generator = ArticlesGenerator(settings.copy(), settings, CUR_DIR,
|
||||||
|
_DEFAULT_CONFIG['THEME'], None,
|
||||||
|
_DEFAULT_CONFIG['MARKUP'])
|
||||||
|
generator.generate_context()
|
||||||
|
for article in generator.articles:
|
||||||
|
relfilepath = os.path.relpath(article.filename, CUR_DIR)
|
||||||
|
if relfilepath == os.path.join("TestCategory",
|
||||||
|
"article_with_category.rst"):
|
||||||
|
self.assertEquals(article.category.name, 'yeah')
|
||||||
|
elif relfilepath == os.path.join("TestCategory",
|
||||||
|
"article_without_category.rst"):
|
||||||
|
self.assertEquals(article.category.name, 'TestCategory')
|
||||||
|
elif relfilepath == "article_without_category.rst":
|
||||||
|
self.assertEquals(article.category.name, 'Default')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue