def test_bad_format(self): """Tests case for badly formatted raw content.""" doc = self.pod.get_doc('/content/pages/html.html') content = 'testing: > 2' with self.assertRaises(document_front_matter.BadFormatError): document_front_matter.DocumentFrontMatter(doc, raw_front_matter=content) doc = self.pod.get_doc('/content/pages/html.html') content = textwrap.dedent(""" name: Jane Doe --- foo: bar """).lstrip() with self.assertRaises(document_front_matter.BadFormatError): document_front_matter.DocumentFrontMatter(doc, raw_front_matter=content) doc = self.pod.get_doc('/content/pages/html.html') content = textwrap.dedent(""" - alpha - beta - charlie """).lstrip() with self.assertRaises(document_front_matter.BadFormatError): document_front_matter.DocumentFrontMatter(doc, raw_front_matter=content)
def front_matter(self): cached_front_matter = self._doc.pod.podcache.document_cache\ .get_property(self._doc, 'front_matter') if cached_front_matter: return doc_front_matter.DocumentFrontMatter( self._doc, raw_front_matter=cached_front_matter) front_matter = self._parse_front_matter() self._doc.pod.podcache.document_cache.add_property( self._doc, 'front_matter', front_matter.export()) return front_matter
def test_export(self): """Test exporting the front raw matter.""" expected = textwrap.dedent(""" $title@: HTML Page $hidden: true """).strip() doc = self.pod.get_doc('/content/pages/html.html') self.assertEquals( expected, document_front_matter.DocumentFrontMatter(doc).export())
def _parse_front_matter(self): """Parse the front matter from the raw content.""" return doc_front_matter.DocumentFrontMatter(self._doc)
def _parse_front_matter(self): return doc_front_matter.DocumentFrontMatter( self._doc, raw_front_matter=self.raw_content)
def test_empty_raw_front_matter(self): """Test for empty or missing front matter.""" doc = self.pod.get_doc('/content/pages/html.html') document_front_matter.DocumentFrontMatter(doc, raw_front_matter=None)