def get_doc(self, pod_path, locale=None): """Returns a document contained in this collection.""" pod_path = document.Document.clean_localized_path(pod_path, locale) # Some uses are using str(None) if locale is not None and locale != 'None': locale = locales.Locale.from_alias(self.pod, locale) locale.set_alias(self.pod) localized_path = document.Document.localize_path( pod_path, str(locale)) if self.pod.file_exists(localized_path): pod_path = localized_path elif locale.alias: localized_path = document.Document.localize_path( pod_path, locale.alias) if self.pod.file_exists(localized_path): pod_path = localized_path cached = self.pod.podcache.collection_cache.get_document( self, pod_path, locale) if cached: return cached doc = document.Document(pod_path, locale=locale, _pod=self.pod, _collection=self) self.pod.podcache.collection_cache.add_document(doc) return doc
def content_from_template(self): """Handle the request for copying files.""" collection_path = self._get_param('collection_path') key = self._get_param('key') file_name = self._get_param('file_name').strip() collection = self.pod.get_collection(collection_path) templates = self._get_collection_templates(collection) template_meta = templates.get(key) # Allow collection to define a default page template. if not template_meta: template_meta = templates.get('_default') # No template selected, making an arbitrary blank page. if not template_meta: # Write a blank file. pod_path = os.path.join(collection.pod_path, file_name) self.pod.write_file(pod_path, '') return # Add the extension if not provided. file_ext = template_meta.get('extension') if file_ext and not file_name.endswith(file_ext): file_name = '{}.{}'.format(file_name, file_ext) pod_path = os.path.join(collection.pod_path, file_name) doc = document.Document(pod_path, _pod=self.pod, _collection=collection) doc.format.update(fields=template_meta.get('front_matter'), content=template_meta.get('content')) doc.write()
def get_doc(self, pod_path, locale=None): """Returns a document contained in this collection.""" pod_path = document.Document.clean_localized_path(pod_path, locale) if locale is not None: localized_path = document.Document.localize_path(pod_path, locale) if self.pod.file_exists(localized_path): pod_path = localized_path cached = self.pod.podcache.collection_cache.get_document( self, pod_path, locale) if cached: return cached doc = document.Document( pod_path, locale=locale, _pod=self.pod, _collection=self) self.pod.podcache.collection_cache.add_document(doc) return doc
def createTestDoc(): test_dir = os.path.join(os.path.dirname(__file__), 'unit-test') pod = pods.Pod(test_dir) pod.get_podspec().yaml.get('deployments').get('default').setdefault( 'extracted_examples_dir', test_dir) coll = collection.Collection(test_dir, pod) coll.fields = {} doc = document.Document('/test/bar.md', pod, _collection=coll) doc.fields = { '$title': 'Test', '$path': '/test/bar.html', 'formats': ['websites', 'email'], } return doc
def createTempDoc(self, formats): pod = pods.Pod(self.temp_dir) pod.get_podspec().yaml.get('deployments').get('default').setdefault( 'extracted_examples_dir', self.temp_dir) coll = collection.Collection(self.temp_dir, pod) coll.fields = {} doc = document.Document('/{}.md'.format(self.example_md_counter), pod, _collection=coll) doc.fields = { '$title': 'Test', '$path': '/{}.html'.format(self.example_md_counter), 'formats': formats, } return doc
def doc(self): """Doc for the controller.""" if not self._doc: partial = self.params['partial'] ext_config = structures.DeepReferenceDict( self.pod.extensions_controller.extension_config( 'extensions.editor.EditorExtension')) collection_path = ext_config['screenshots.partials.collection'] if not collection_path: raise werkzeug_exceptions.BadRequest( 'No collection path defined for partial screenshots') col = self.pod.get_collection(collection_path) pod_partial = self.pod.partials.get_partial(partial) partial_example = pod_partial.config.get('editor', {}).get( 'examples', {}).get(self.params['key']) if not partial_example: raise werkzeug_exceptions.NotFound( 'Unable to find example in partial: {}'.format( self.params['key'])) partial_example['partial'] = partial doc_fields = { '$view': ext_config['screenshots.partials.view'], 'partials': [ partial_example, ], } locale = self.route_info.meta.get('locale', self.params.get('locale')) pod_path = os.path.join(collection_path, '_partial.yaml') self._doc = document.Document(pod_path, locale=locale, _pod=self.pod, _collection=col) self._doc.format.update(fields=doc_fields) return self._doc
def doc(self): """Doc for the controller.""" if not self._doc: collection_path = '/{}'.format(self.params['collection']) collection_path_parts = collection_path.split('/') key = collection_path_parts.pop() collection_path = '/'.join(collection_path_parts) col = self.pod.get_collection(collection_path) # Find the template file to load the template from. template_path = os.path.join(collection_path, TEMPLATE_FILE_NAME) try: template_info = self.pod.read_yaml(template_path) except IOError: raise werkzeug_exceptions.NotFound( 'No template file found for collection: {}'.format( template_path)) template_meta = template_info.get(key) if not template_meta: raise werkzeug_exceptions.NotFound( 'Unable to find template: {}'.format(key)) locale = self.route_info.meta.get('locale', self.params.get('locale')) pod_path = os.path.join( collection_path, '_template.{}'.format( template_meta.get('file_extension', 'html'))) self._doc = document.Document(pod_path, locale=locale, _pod=self.pod, _collection=col) self._doc.format.update(fields=template_meta.get('front_matter'), content=template_meta.get('content')) return self._doc