Skip to content
Browse files

Add user-defined filename pattern matching option

  • Loading branch information...
1 parent 4594ef9 commit 7a3b81b1e2286f64096a77dfe36e417ceea944b6 @bow committed Jun 22, 2012
View
1 CHANGELOG
@@ -11,6 +11,7 @@ Highlights:
o New feature: custom pagination titles
o Text engines can now parse file in subdirectories
+ o Text engines can now parse files according to a user-defined pattern
o Builtin atomic plugin can now use user-defined templates
o Changed/removed these setting names/values:
View
10 volt/engine/builtins/__init__.py
@@ -15,6 +15,7 @@
import glob
import os
+from volt.config import Config
from volt.engine.core import _RE_DELIM, Engine, Unit
from volt.utils import cachedproperty
@@ -80,13 +81,20 @@ class TextEngine(Engine):
"""Engine class for processing text units."""
+ # Default configurations for the base text engine
+ DEFAULTS = Config(
+ # Unit filename pattern to match
+ UNIT_FNAME_PATTERN = '*'
+ )
+
@cachedproperty
def units(self):
"""Units whose source are text files in the filesystem."""
target_dir = self.config.CONTENT_DIR
+ pattern = self.config.UNIT_FNAME_PATTERN
units = []
for curdir, children, files in os.walk(target_dir):
- targets = glob.iglob(os.path.join(curdir, '*'))
+ targets = glob.iglob(os.path.join(curdir, pattern))
files = (x for x in targets if os.path.isfile(x))
for fname in files:
units.append(TextUnit(os.path.join(curdir, fname), self.config))
View
4 volt/engine/builtins/blog.py
@@ -52,6 +52,10 @@ class BlogEngine(TextEngine):
# relative to the default Volt content directory
CONTENT_DIR = 'blog',
+ # Unit filename pattern to match
+ # Defaults to '*' (match all files)
+ UNIT_FNAME_PATTERN = '*',
+
# File paths of blog template files
# relative to the default Volt template directory
UNIT_TEMPLATE = 'blog_unit.html',
View
4 volt/engine/builtins/plain.py
@@ -38,6 +38,10 @@ class PlainEngine(TextEngine):
# relative to the default Volt content directory
CONTENT_DIR = 'plain',
+ # Unit filename pattern to match
+ # Defaults to '*' (match all files)
+ UNIT_FNAME_PATTERN = '*',
+
# File paths of plain page template files
# relative to the default Volt template directory
UNIT_TEMPLATE = 'plain_unit.html',
View
0 ...fixtures/engines/engine_pass/05_528491.md → ...ixtures/engines/engine_pass/05_528491.rst
File renamed without changes.
View
0 ...es/engine_pass/2010/02_one-simple-idea.md → ...s/engine_pass/2010/02_one-simple-idea.rst
File renamed without changes.
View
20 volt/test/test_engine_builtins.py
@@ -39,10 +39,26 @@ def test_units(self, TextUnit_mock):
content_dir = os.path.join(FIXTURE_DIR, 'engines', 'engine_pass')
engine.config.CONTENT_DIR = content_dir
fnames = [os.path.join('2010', '01_radical-notion.md'),
- os.path.join('2010', '02_one-simple-idea.md'),
+ os.path.join('2010', '02_one-simple-idea.rst'),
os.path.join('2011', '03_dream-is-collapsing.md'),
'04_dream-within-a-dream.md',
- '05_528491.md']
+ '05_528491.rst']
+ abs_fnames = [os.path.join(content_dir, x) for x in fnames]
+
+ call_args = zip(abs_fnames, [engine.config] * len(fnames))
+ calls = [call(*x) for x in call_args]
+
+ engine.units
+ TextUnit_mock.assert_has_calls(calls, any_order=True)
+
+ @patch('volt.engine.builtins.TextUnit')
+ def test_units_fname_pattern(self, TextUnit_mock):
+ engine = TestTextEngine()
+ engine.config.UNIT_FNAME_PATTERN = '*.rst'
+ content_dir = os.path.join(FIXTURE_DIR, 'engines', 'engine_pass')
+ engine.config.CONTENT_DIR = content_dir
+ fnames = [os.path.join('2010', '02_one-simple-idea.rst'),
+ '05_528491.rst']
abs_fnames = [os.path.join(content_dir, x) for x in fnames]
call_args = zip(abs_fnames, [engine.config] * len(fnames))

0 comments on commit 7a3b81b

Please sign in to comment.
Something went wrong with that request. Please try again.