Esempio n. 1
0
    def test_parent_paths(self):
        tests = [
            (['map'], ['map']),
            (['map', 'spain', 'choropleth'], ['map', 'map/spain', 'map/spain/choropleth'])
        ]

        for test_input, expected in tests:
            self.assertEqual(expected, list(path.parent_paths(test_input)))
Esempio n. 2
0
    def test_parent_paths(self):
        tests = [(['map'], ['map']),
                 (['map', 'spain',
                   'choropleth'], ['map', 'map/spain',
                                   'map/spain/choropleth'])]

        for test_input, expected in tests:
            self.assertEqual(expected, list(path.parent_paths(test_input)))
Esempio n. 3
0
    def _update_index(self, doc, url=None):
        """Add a doc to index determined from given url.

        For each directory in the URL except for the one containing the content
        file itself a collection is created, if it doesn't exist, and the
        document is added to it.
        """

        if url is None:
            url = doc['url']

        dirs = path.parent_dirs(url)
        for fullpath in path.parent_paths(dirs):
            if fullpath not in self.index:
                template = self.get_index_template(fullpath)
                self.index[fullpath] = Collection(docs=[], template=template, urls=set())

            # Don't add documents more than once to a collection. Important to
            # check and add doc['url'], because url can be an index url like tags.
            if doc['url'] not in self.index[fullpath].urls:
                self.index[fullpath].urls.add(doc['url'])
                self.index[fullpath].docs.append(doc)
Esempio n. 4
0
    def _update_index(self, doc, url=None):
        """Add a doc to index determined from given url.

        For each directory in the URL except for the one containing the content
        file itself a collection is created, if it doesn't exist, and the
        document is added to it.
        """

        if url is None:
            url = doc['url']

        dirs = path.parent_dirs(url)
        for fullpath in path.parent_paths(dirs):
            if fullpath not in self.index:
                template = self.get_index_template(fullpath)
                self.index[fullpath] = Collection(docs=[], template=template, urls=set())

            # Don't add documents more than once to a collection. Important to
            # check and add doc['url'], because url can be an index url like tags.
            if doc['url'] not in self.index[fullpath].urls:
                self.index[fullpath].urls.add(doc['url'])
                self.index[fullpath].docs.append(doc)