changeset 401:8e1e55ad35fb

linker: Fix error when trying to list non-existing children. Add unit tests.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 18 May 2015 23:32:43 -0700
parents c12ee6936b8c
children 043b9d8304c7
files piecrust/data/linker.py tests/bakes/test_linker.yaml
diffstat 2 files changed, 51 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/data/linker.py	Mon May 18 19:29:49 2015 -0700
+++ b/piecrust/data/linker.py	Mon May 18 23:32:43 2015 -0700
@@ -23,7 +23,7 @@
     def children(self):
         self._linker._load()
         if self._linker._self_item is None:
-            return None
+            return []
         return self._linker._self_item._linker_info.child_linker
 
     @property
@@ -105,7 +105,7 @@
     def __init__(self):
         self.name = None
         self.is_self = False
-        self.child_linker = None
+        self.child_linker = []
 
 
 class _LinkedPage(object):
@@ -244,7 +244,7 @@
 
 
 def filter_directory_items(item):
-    return isinstance(item, linker)
+    return isinstance(item, Linker)
 
 
 def walk_linkers(linker, depth=0, max_depth=-1, filter_func=None):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/bakes/test_linker.yaml	Mon May 18 23:32:43 2015 -0700
@@ -0,0 +1,48 @@
+---
+in:
+    pages/foo.md: |
+        {%for c in family.children%}
+        {{c.title}}
+        {%endfor%}
+outfiles:
+    foo.html: ''
+---
+in:
+    pages/foo.md: |
+        {%for c in family.children-%}
+        {{c.title}}
+        {%endfor%}
+    pages/foo/one.md: |
+        ---
+        title: One
+        ---
+    pages/foo/two.md: |
+        ---
+        title: Two
+        ---
+outfiles:
+    foo.html: |
+        One
+        Two
+---
+in:
+    pages/foo.md: |
+        ---
+        title: Foo
+        ---
+        {%for c in family.siblings-%}
+        {{c.title}}{%if c.is_self%} SELFIE!{%endif%}
+        {%endfor%}
+    pages/bar.md: |
+        ---
+        title: Bar
+        ---
+    pages/other.md: |
+        ---
+        title: Other
+        ---
+outfiles:
+    foo.html: |
+        Bar
+        Foo SELFIE!
+        Other