Beispiel #1
0
    def run(self, posts=None):
        posts = posts or self.posts
        page = Pagination(posts, base_url=self.base_url, posts_per_page=self.num_per_page)

        for n, p in enumerate(page.iterate()):
            content = self.render(p)
            logging.debug("Write file %s", p.file_path, prefix="   ↳  ")
            self.write_to_file(p.file_path, content)
Beispiel #2
0
    def run(self, posts=None):
        posts = posts or self.posts
        page = Pagination(posts,
                          base_url=self.base_url,
                          posts_per_page=self.num_per_page)

        for n, p in enumerate(page.iterate()):
            content = self.render(p)
            logging.debug('Write file %s', p.file_path, prefix='   ↳  ')
            self.write_to_file(p.file_path, content)
Beispiel #3
0
    def test_path(self):
        posts = []
        for i in range(0, 10):
            title = 'post_{}'.format(i)
            posts.append(Post(title, title, title))

        page = Pagination(posts, base_url='/tags/test')
        self.assertEqual(page.url, '/tags/test/')
        self.assertEqual(page.file_path, 'tags/test/index.html')

        page = Pagination(
            posts,
            base_url='/tags/test/index.html',
        ).next
        self.assertEqual(page.url, '/tags/test/page/2/index.html')
        self.assertEqual(page.file_path, 'tags/test/page/2/index.html')
Beispiel #4
0
    def test_pagination(self):
        posts = []
        for i in range(0, 10):
            title = "post_{}".format(i)
            posts.append(Post(title, title, title))

        page = Pagination(posts, base_url="tags/test/", posts_per_page=2)

        self.assertEqual(page.page, 1)
        self.assertEqual(page.total, 5)
        self.assertListEqual(page.posts, posts[0:2])

        self.assertIsNone(page.prev)

        next = page.next
        self.assertListEqual(next.posts, posts[2:4])

        n = 0
        for p in page.iterate():
            self.assertEqual(p.page, n + 1)
            self.assertListEqual(p.posts, posts[n * 2 : n * 2 + 2])
            n += 1
Beispiel #5
0
    def test_pagination(self):
        posts = []
        for i in range(0, 10):
            title = 'post_{}'.format(i)
            posts.append(Post(title, title, title))

        page = Pagination(posts, base_url='tags/test/', posts_per_page=2)

        self.assertEqual(page.page, 1)
        self.assertEqual(page.total, 5)
        self.assertListEqual(page.posts, posts[0:2])

        self.assertIsNone(page.prev)

        next = page.next
        self.assertListEqual(next.posts, posts[2:4])

        n = 0
        for p in page.iterate():
            self.assertEqual(p.page, n + 1)
            self.assertListEqual(p.posts, posts[n * 2:n * 2 + 2])
            n += 1