예제 #1
0
파일: pods.py 프로젝트: grow/grow
 def write_yaml(self, path, content):
     with self.profile.timer(
             'Pod.write_yaml', label=path, meta={'path': path}):
         self.podcache.collection_cache.remove_by_path(path)
         self.podcache.document_cache.remove_by_path(path)
         content = utils.dump_yaml(content)
         self.write_file(path, content)
예제 #2
0
파일: pods.py 프로젝트: uxder/grow
 def write_yaml(self, path, content):
     with self.profile.timer(
             'Pod.write_yaml', label=path, meta={'path': path}):
         self.podcache.collection_cache.remove_by_path(path)
         self.podcache.document_cache.remove_by_path(path)
         content = utils.dump_yaml(content)
         self.write_file(path, content)
예제 #3
0
 def create(cls, collection_path, fields, pod):
     """Creates a new collection by writing a blueprint."""
     collection = cls.get(collection_path, pod)
     if collection.exists:
         raise CollectionExistsError('{} already exists.'.format(collection))
     fields = utils.dump_yaml(fields)
     pod.write_file(collection._blueprint_path, fields)
     return collection
예제 #4
0
파일: collection.py 프로젝트: ilg/grow
 def create(cls, collection_path, fields, pod):
     """Creates a new collection by writing a blueprint."""
     collection = cls.get(collection_path, pod)
     if collection.exists:
         raise CollectionExistsError(
             '{} already exists.'.format(collection))
     fields = utils.dump_yaml(fields)
     pod.write_file(collection.blueprint_path, fields)
     return collection
예제 #5
0
    def test_yaml_dump(self):
        """Test if the yaml representer is working correctly."""
        pod = testing.create_pod()
        pod.write_yaml('/podspec.yaml', {})
        pod.write_yaml('/content/pages/page.yaml', {})
        doc = pod.get_doc('/content/pages/page.yaml')
        input_obj = {'doc': doc}
        expected = textwrap.dedent("""\
            doc: !g.doc '/content/pages/page.yaml'
            """)

        self.assertEqual(expected, utils.dump_yaml(input_obj))
예제 #6
0
    def update(self, fields=utils.SENTINEL, content=utils.SENTINEL):
        """Updates content and frontmatter."""
        if fields is not utils.SENTINEL:
            raw_front_matter = utils.dump_yaml(fields)
            self.front_matter.update_raw_front_matter(raw_front_matter)
            self._doc.pod.podcache.document_cache.add_property(
                self._doc, 'front_matter', self.front_matter.export())

        if content is not utils.SENTINEL:
            self._content = content

        self._raw_content = self.to_raw_content()
예제 #7
0
    def update(self, fields=utils.SENTINEL, content=utils.SENTINEL):
        """Updates content and frontmatter."""
        if fields is not utils.SENTINEL:
            raw_front_matter = utils.dump_yaml(fields)
            self.front_matter.update_raw_front_matter(raw_front_matter)
            self._doc.pod.podcache.document_cache.add_property(
                self._doc, 'front_matter', self.front_matter.export())

        if content is not utils.SENTINEL:
            self._content = content

        self._raw_content = self.to_raw_content()
예제 #8
0
파일: formats.py 프로젝트: kezlya/grow
 def update(content, fields=utils.SENTINEL, body=utils.SENTINEL):
     """Updates content with frontmatter. The existing fields and the
     existing body are preserved if they are not specified in arguments."""
     parts = Format.split_front_matter(content) or ['', '']
     if fields is not utils.SENTINEL:
         fields = '\n' + utils.dump_yaml(fields)
         parts[0] = fields
     if body is not utils.SENTINEL and len(parts) > 1:
         parts[1] = '\n' + body
     result = '---' + '---'.join(parts)
     if result.endswith('---\n'):
         return result[:-5]
     return result
예제 #9
0
파일: formats.py 프로젝트: denmojo/pygrow
 def update(content, fields=utils.SENTINEL, body=utils.SENTINEL):
     """Updates content with frontmatter. The existing fields and the
     existing body are preserved if they are not specified in arguments."""
     parts = Format.split_front_matter(content) or ['', '']
     if fields is not utils.SENTINEL:
         fields = '\n' + utils.dump_yaml(fields)
         parts[0] = fields
     if body is not utils.SENTINEL and len(parts) > 1:
         parts[1] = '\n' + body
     result = '---' + '---'.join(parts)
     if result.endswith('---\n'):
         return result[:-5]
     return result
예제 #10
0
    def update(self, fields=utils.SENTINEL, content=utils.SENTINEL):
        """Updates content and frontmatter."""
        if fields is not utils.SENTINEL:
            # Organize some of the fields for minimal consistency.
            fields = self.organize_fields(fields)

            raw_front_matter = utils.dump_yaml(fields)
            self.front_matter.update_raw_front_matter(raw_front_matter)
            self._doc.pod.podcache.document_cache.add_property(
                self._doc, 'front_matter', self.front_matter.export())

        if content is not utils.SENTINEL:
            self._content = content

        self._raw_content = self.to_raw_content()
예제 #11
0
    def test_yaml_dump(self):
        """Test if the yaml representer is working correctly."""
        pod = testing.create_pod()
        pod.write_yaml('/podspec.yaml', {})
        pod.write_yaml('/content/pages/page.yaml', {})
        doc = pod.get_doc('/content/pages/page.yaml')
        input_obj = {
            'doc': doc
        }
        expected = textwrap.dedent(
            """\
            doc: !g.doc '/content/pages/page.yaml'
            """)

        self.assertEqual(expected, utils.dump_yaml(input_obj))
예제 #12
0
 def write_yaml(self, path, content):
     self.podcache.collection_cache.remove_by_path(path)
     self.podcache.document_cache.remove_by_path(path)
     content = utils.dump_yaml(content)
     self.write_file(path, content)
예제 #13
0
 def write_yaml(self, path, content):
     for virtual_key in self.virtual_files.keys():
         if path in virtual_key:
             del self.virtual_files[virtual_key]
     content = utils.dump_yaml(content)
     self.write_file(path, content)
예제 #14
0
파일: pods.py 프로젝트: chargrizzle/pygrow
 def write_yaml(self, path, content):
     content = utils.dump_yaml(content)
     self.write_file(path, content)
예제 #15
0
 def update_from_message(self, message):
     if not message.fields:
         raise BadFieldsError("Fields are required to create a collection.")
     fields = json.loads(message.fields)
     fields = utils.dump_yaml(fields)
     self.pod.write_file(self._blueprint_path, fields)
예제 #16
0
파일: pods.py 프로젝트: drGrove/grow
 def write_yaml(self, path, content):
     self.podcache.collection_cache.remove_by_path(path)
     self.podcache.document_cache.remove_by_path(path)
     content = utils.dump_yaml(content)
     self.write_file(path, content)
예제 #17
0
 def update_from_message(self, message):
     if not message.fields:
         raise BadFieldsError('Fields are required to create a collection.')
     fields = json.loads(message.fields)
     fields = utils.dump_yaml(fields)
     self.pod.write_file(self._blueprint_path, fields)
예제 #18
0
 def update_fields(self, fields):
     """Update the data with new field values."""
     _update_deep(self.data, fields)
     self.update_raw_front_matter(utils.dump_yaml(self.data))