Beispiel #1
0
    def test_intrasite_link_markdown_spaces(self):
        # Markdown introduces %20 instead of spaces, this tests that
        # we support markdown doing this.
        cls_name = '_DummyArticle' if six.PY3 else b'_DummyArticle'
        article = type(cls_name, (object,), {'url': 'article-spaces.html'})

        args = self.page_kwargs.copy()
        args['settings'] = get_settings()
        args['source_path'] = 'content'
        args['context']['filenames'] = {'article spaces.rst': article}

        # An intrasite link via filename with %20 as a space
        args['content'] = (
            'A simple test, with a '
            '<a href="|filename|article%20spaces.rst">link</a>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'A simple test, with a '
            '<a href="http://notmyidea.org/article-spaces.html">link</a>'
        )
Beispiel #2
0
    def generate_context(self):
        all_pages = []
        hidden_pages = []
        for f in self.get_files(os.path.join(self.path,
                                             self.settings['PAGE_DIR']),
                                exclude=self.settings['PAGE_EXCLUDES']):
            try:
                content, metadata = read_file(f, settings=self.settings)
            except Exception as e:
                logger.warning('Could not process %s\n%s' % (f, str(e)))
                continue
            signals.pages_generate_context.send(self, metadata=metadata)
            page = Page(content,
                        metadata,
                        settings=self.settings,
                        source_path=f,
                        context=self.context)
            if not is_valid_content(page, f):
                continue

            self.add_source_path(page)

            if page.status == "published":
                all_pages.append(page)
            elif page.status == "hidden":
                hidden_pages.append(page)
            else:
                logger.warning("Unknown status %s for file %s, skipping it." %
                               (repr(page.status), repr(f)))

        self.pages, self.translations = process_translations(all_pages)
        self.hidden_pages, self.hidden_translations = (
            process_translations(hidden_pages))

        self._update_context(('pages', ))
        self.context['PAGES'] = self.pages

        signals.pages_generator_finalized.send(self)
Beispiel #3
0
 def generate_context(self):
     all_pages = []
     hidden_pages = []
     for f in self.get_files(os.path.join(self.path,
                                          self.settings['PAGE_DIR']),
                             exclude=self.settings['PAGE_EXCLUDES']):
         try:
             content, metadata = read_file(f, settings=self.settings)
         except Exception, e:
             logger.warning(u'Could not process %s\n%s' % (f, str(e)))
             continue
         signals.pages_generate_context.send(self, metadata=metadata)
         page = Page(content, metadata, settings=self.settings, filename=f)
         if not is_valid_content(page, f):
             continue
         if page.status == "published":
             all_pages.append(page)
         elif page.status == "hidden":
             hidden_pages.append(page)
         else:
             logger.warning(
                 u"Unknown status %s for file %s, skipping it." %
                 (repr(unicode.encode(page.status, 'utf-8')), repr(f)))
Beispiel #4
0
    def test_intrasite_link_source_and_generated(self):
        """Test linking both to the source and the generated article
        """
        cls_name = '_DummyAsset'

        args = self.page_kwargs.copy()
        args['settings'] = get_settings()
        args['source_path'] = 'content'
        args['context']['generated_content'] = {
            'article.rst': type(cls_name, (object, ), {'url': 'article.html'})
        }
        args['context']['static_content'] = {
            'article.rst': type(cls_name, (object, ), {'url': 'article.rst'})
        }

        args['content'] = (
            'A simple test, with a link to an'
            '<a href="{filename}article.rst">article</a> and its'
            '<a href="{static}article.rst">source</a>')
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content, 'A simple test, with a link to an'
            '<a href="http://notmyidea.org/article.html">article</a> and its'
            '<a href="http://notmyidea.org/article.rst">source</a>')
Beispiel #5
0
 def gen_page_and_html_from_rst(self, rstPath):
     content, metadata = self.reader.read(rstPath)
     page = Page(content=content, metadata=metadata)
     context = self.settings.copy()
     context['generated_content'] = {}
     context['static_links'] = set()
     context['static_content'] = {}
     context['localsiteurl'] = self.settings['SITEURL']
     generator = PagesGenerator(context=context,
                                settings=self.settings,
                                path=CONTENT_DIR,
                                theme=self.settings['THEME'],
                                output_path=OUTPUT_DIR)
     generator.generate_context()
     f = lambda a: True if (a.slug == page.slug) else False
     result = list(filter(f, generator.context["pages"]))[0]
     self.writer.write_file(result.save_as,
                            generator.get_template('page'),
                            generator.context,
                            page=result)
     soup = BeautifulSoup(
         open("./" + self.writer.output_path + '/' + result.save_as),
         "html.parser")
     return (result, soup)
Beispiel #6
0
 def test_summary_from_metadata(self):
     # If a :summary: metadata is given, it should be used
     page = Page(**self.page_kwargs)
     self.assertEqual(page.summary, TEST_SUMMARY)
Beispiel #7
0
    def test_intrasite_link_more(self):
        # type does not take unicode in PY2 and bytes in PY3, which in
        # combination with unicode literals leads to following insane line:
        cls_name = '_DummyAsset' if six.PY3 else b'_DummyAsset'

        args = self.page_kwargs.copy()
        args['settings'] = get_settings()
        args['source_path'] = 'content'
        args['context']['filenames'] = {
            'images/poster.jpg': type(
                cls_name, (object,), {'url': 'images/poster.jpg'}),
            'assets/video.mp4': type(
                cls_name, (object,), {'url': 'assets/video.mp4'}),
            'images/graph.svg': type(
                cls_name, (object,), {'url': 'images/graph.svg'}),
            'reference.rst': type(
                cls_name, (object,), {'url': 'reference.html'}),
        }

        # video.poster
        args['content'] = (
            'There is a video with poster '
            '<video controls poster="{filename}/images/poster.jpg">'
            '<source src="|filename|/assets/video.mp4" type="video/mp4">'
            '</video>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'There is a video with poster '
            '<video controls poster="http://notmyidea.org/images/poster.jpg">'
            '<source src="http://notmyidea.org/assets/video.mp4"'
            ' type="video/mp4">'
            '</video>'
        )

        # object.data
        args['content'] = (
            'There is a svg object '
            '<object data="{filename}/images/graph.svg"'
            ' type="image/svg+xml">'
            '</object>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'There is a svg object '
            '<object data="http://notmyidea.org/images/graph.svg"'
            ' type="image/svg+xml">'
            '</object>'
        )

        # blockquote.cite
        args['content'] = (
            'There is a blockquote with cite attribute '
            '<blockquote cite="{filename}reference.rst">blah blah</blockquote>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'There is a blockquote with cite attribute '
            '<blockquote cite="http://notmyidea.org/reference.html">'
            'blah blah'
            '</blockquote>'
        )
Beispiel #8
0
    def test_intrasite_link(self):
        # type does not take unicode in PY2 and bytes in PY3, which in
        # combination with unicode literals leads to following insane line:
        cls_name = '_DummyArticle' if six.PY3 else b'_DummyArticle'
        article = type(cls_name, (object,), {'url': 'article.html'})

        args = self.page_kwargs.copy()
        args['settings'] = get_settings()
        args['source_path'] = 'content'
        args['context']['filenames'] = {'article.rst': article}

        # Classic intrasite link via filename
        args['content'] = (
            'A simple test, with a '
            '<a href="|filename|article.rst">link</a>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'A simple test, with a '
            '<a href="http://notmyidea.org/article.html">link</a>'
        )

        # fragment
        args['content'] = (
            'A simple test, with a '
            '<a href="|filename|article.rst#section-2">link</a>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'A simple test, with a '
            '<a href="http://notmyidea.org/article.html#section-2">link</a>'
        )

        # query
        args['content'] = (
            'A simple test, with a '
            '<a href="|filename|article.rst'
            '?utm_whatever=234&highlight=word">link</a>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'A simple test, with a '
            '<a href="http://notmyidea.org/article.html'
            '?utm_whatever=234&highlight=word">link</a>'
        )

        # combination
        args['content'] = (
            'A simple test, with a '
            '<a href="|filename|article.rst'
            '?utm_whatever=234&highlight=word#section-2">link</a>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'A simple test, with a '
            '<a href="http://notmyidea.org/article.html'
            '?utm_whatever=234&highlight=word#section-2">link</a>'
        )

        # also test for summary in metadata
        args['metadata']['summary'] = (
            'A simple summary test, with a '
            '<a href="|filename|article.rst">link</a>'
        )
        args['context']['localsiteurl'] = 'http://notmyidea.org'
        p = Page(**args)
        self.assertEqual(
            p.summary,
            'A simple summary test, with a '
            '<a href="http://notmyidea.org/article.html">link</a>'
        )
Beispiel #9
0
 def test_slug(self):
     """If a title is given, it should be used to generate the slug."""
     page = Page(**self.page_kwargs)
     self.assertEqual(page.slug, 'foo-bar')
Beispiel #10
0
 def test_mandatory_properties(self):
     """If the title is not set, must throw an exception."""
     self.assertRaises(AttributeError, Page, 'content')
     page = Page(**self.page_kwargs)
     page.check_properties()
Beispiel #11
0
    def test_intrasite_link(self):
        cls_name = '_DummyArticle'
        article = type(cls_name, (object, ), {'url': 'article.html'})

        args = self.page_kwargs.copy()
        args['settings'] = get_settings()
        args['source_path'] = 'content'
        args['context']['generated_content'] = {'article.rst': article}

        # Classic intrasite link via filename
        args['content'] = ('A simple test, with a '
                           '<a href="|filename|article.rst">link</a>')
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content, 'A simple test, with a '
            '<a href="http://notmyidea.org/article.html">link</a>')

        # fragment
        args['content'] = (
            'A simple test, with a '
            '<a href="|filename|article.rst#section-2">link</a>')
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content, 'A simple test, with a '
            '<a href="http://notmyidea.org/article.html#section-2">link</a>')

        # query
        args['content'] = ('A simple test, with a '
                           '<a href="|filename|article.rst'
                           '?utm_whatever=234&highlight=word">link</a>')
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content, 'A simple test, with a '
            '<a href="http://notmyidea.org/article.html'
            '?utm_whatever=234&highlight=word">link</a>')

        # combination
        args['content'] = (
            'A simple test, with a '
            '<a href="|filename|article.rst'
            '?utm_whatever=234&highlight=word#section-2">link</a>')
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content, 'A simple test, with a '
            '<a href="http://notmyidea.org/article.html'
            '?utm_whatever=234&highlight=word#section-2">link</a>')

        # also test for summary in metadata
        parsed = ('A simple summary test, with a '
                  '<a href="|filename|article.rst">link</a>')
        linked = ('A simple summary test, with a '
                  '<a href="http://notmyidea.org/article.html">link</a>')
        args['settings']['FORMATTED_FIELDS'] = ['summary', 'custom']
        args['metadata']['summary'] = parsed
        args['metadata']['custom'] = parsed
        args['context']['localsiteurl'] = 'http://notmyidea.org'
        p = Page(**args)
        # This is called implicitly from all generators and Pelican.run() once
        # all files are processed. Here we process just one page so it needs
        # to be called explicitly.
        p.refresh_metadata_intersite_links()
        self.assertEqual(p.summary, linked)
        self.assertEqual(p.custom, linked)
Beispiel #12
0
    def test_intrasite_link_more(self):
        cls_name = '_DummyAsset'

        args = self.page_kwargs.copy()
        args['settings'] = get_settings()
        args['source_path'] = 'content'
        args['context']['static_content'] = {
            'images/poster.jpg':
                type(cls_name, (object,), {'url': 'images/poster.jpg'}),
            'assets/video.mp4':
                type(cls_name, (object,), {'url': 'assets/video.mp4'}),
            'images/graph.svg':
                type(cls_name, (object,), {'url': 'images/graph.svg'}),
        }
        args['context']['generated_content'] = {
            'reference.rst':
                type(cls_name, (object,), {'url': 'reference.html'}),
        }

        # video.poster
        args['content'] = (
            'There is a video with poster '
            '<video controls poster="{static}/images/poster.jpg">'
            '<source src="|static|/assets/video.mp4" type="video/mp4">'
            '</video>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'There is a video with poster '
            '<video controls poster="http://notmyidea.org/images/poster.jpg">'
            '<source src="http://notmyidea.org/assets/video.mp4"'
            ' type="video/mp4">'
            '</video>'
        )

        # object.data
        args['content'] = (
            'There is a svg object '
            '<object data="{static}/images/graph.svg"'
            ' type="image/svg+xml">'
            '</object>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'There is a svg object '
            '<object data="http://notmyidea.org/images/graph.svg"'
            ' type="image/svg+xml">'
            '</object>'
        )

        # blockquote.cite
        args['content'] = (
            'There is a blockquote with cite attribute '
            '<blockquote cite="{filename}reference.rst">blah blah</blockquote>'
        )
        content = Page(**args).get_content('http://notmyidea.org')
        self.assertEqual(
            content,
            'There is a blockquote with cite attribute '
            '<blockquote cite="http://notmyidea.org/reference.html">'
            'blah blah'
            '</blockquote>'
        )
Beispiel #13
0
 def test_slug(self):
     # if a title is given, it should be used to generate the slug
     page = Page('content', {'title': 'foobar is foo'})
     self.assertEqual(page.slug, 'foobar-is-foo')
 def test_props_must_exist(self):
     page = Page('content')
     self.assertFalse(page._has_valid_mandatory_properties())
     new_page = Page('content', metadata={'title': 'Pelican'})
     self.assertTrue(new_page._has_valid_mandatory_properties())