Skip to content

Commit

Permalink
Don't treat trailing dashes as a new part
Browse files Browse the repository at this point in the history
This wasn't a problem before adding validation for doc parts in c8bb8ab.
  • Loading branch information
stucox committed Jun 20, 2016
1 parent 861e629 commit f13e71c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 20 additions & 3 deletions grow/pods/documents_test.py
Expand Up @@ -136,7 +136,7 @@ def test_disallow_part_with_no_locale(self):
))

with self.assertRaises(formats.BadFormatError):
self.pod.get_doc('/content/localized/part-with-no-locale.yaml')
self.pod.get_doc('/' + doc_pod_path)

# This should be fine:
with open(os.path.join(self.pod.root, doc_pod_path), 'w') as f:
Expand All @@ -154,11 +154,28 @@ def test_disallow_part_with_no_locale(self):
foo: bar
"""
))
de_doc = self.pod.get_doc('/content/localized/part-with-no-locale.yaml', locale='de')
fr_doc = self.pod.get_doc('/content/localized/part-with-no-locale.yaml', locale='fr')
de_doc = self.pod.get_doc('/' + doc_pod_path, locale='de')
fr_doc = self.pod.get_doc('/' + doc_pod_path, locale='fr')
self.assertEqual(de_doc.fields['foo'], 'bar')
self.assertNotIn('foo', fr_doc.fields)

def test_dont_treat_trailing_dashes_as_a_new_part(self):
doc_pod_path = 'content/localized/part-with-trailing-dashes.yaml'
with open(os.path.join(self.pod.root, doc_pod_path), 'w') as f:
f.write(dedent(
"""\
---
root_doc_part: true
---
$locale: de
subsequent_doc_part: true
---
"""
))

doc = self.pod.get_doc('/' + doc_pod_path)
self.assertEqual(len(doc.format._iterate_content()), 2)

def test_view_override(self):
doc = self.pod.get_doc('/content/localized/localized-view-override.yaml')
self.assertEqual('/views/localized.html', doc.view)
Expand Down
5 changes: 4 additions & 1 deletion grow/pods/formats.py
Expand Up @@ -80,7 +80,10 @@ def load(self):
class _SplitDocumentFormat(Format):

def _iterate_content(self):
return [(part, part) for part in Format.split_front_matter(self.content)]
parts = [(part, part) for part in Format.split_front_matter(self.content)]
if not parts[-1][0].strip():
parts.pop()
return parts

def _validate_fields(self, fields):
if '$locale' in fields and '$locales' in fields:
Expand Down

0 comments on commit f13e71c

Please sign in to comment.