示例#1
0
 def setUp(self):
     conf = {}
     if self.extra_plugins_dirs is not None:
         conf['EXTRA_PLUGINS_DIRS'] = self.extra_plugins_dirs
     self.site = Nikola(**conf)
     self.site.init_plugins()
     self.compiler = self.site.compilers['rest']
     return super(ReSTExtensionTestCase, self).setUp()
示例#2
0
    def _execute(self, options, args):
        """Manage the tags on the site."""

        try:
            import conf

        except ImportError:
            LOGGER.error("No configuration found, cannot run the console.")

        else:
            _reload(conf)
            nikola = Nikola(**conf.__dict__)
            nikola.scan_posts()

            if len(options['add']) > 0 and len(args) > 0:
                add_tags(nikola, options['add'], args, options['dry-run'])

            elif options['list']:
                list_tags(nikola, options['list_sorting'])

            elif options['merge'].count(',') > 0 and len(args) > 0:
                merge_tags(nikola, options['merge'], args, options['dry-run'])

            elif len(options['remove']) > 0 and len(args) > 0:
                remove_tags(nikola, options['remove'], args,
                            options['dry-run'])

            elif len(options['search']) > 0:
                search_tags(nikola, options['search'])

            elif options['tag'] and len(args) > 0:
                tagger = _AutoTag(nikola)
                for post in args:
                    tags = ','.join(tagger.tag(post))
                    add_tags(nikola, tags, [post], options['dry-run'])

            elif options['sort'] and len(args) > 0:
                sort_tags(nikola, args, options['dry-run'])

            else:
                print(self.help())
示例#3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Please don't edit this file unless you really know what you are doing.
# The configuration is now in conf.py

from doit.reporter import ExecutedOnlyReporter

from nikola.nikola import Nikola

import conf

DOIT_CONFIG = {
    'reporter': ExecutedOnlyReporter,
    'default_tasks': ['render_site'],
}
SITE = Nikola(**conf.__dict__)


def task_render_site():
    return SITE.gen_tasks()
示例#4
0
文件: dodo.py 项目: kadefor/nikola
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Please don't edit this file unless you really know what you are doing.
# The configuration is now in conf.py

import os

from doit.reporter import ExecutedOnlyReporter

from nikola.nikola import Nikola

import conf

DOIT_CONFIG = {
    'reporter': ExecutedOnlyReporter,
    'default_tasks': ['render_site'],
}
site = Nikola(**conf.__dict__)


def task_render_site():
    return site.gen_tasks()


if __name__ == "__main__":
    _nikola_main()
示例#5
0
def rss_feed_content(blog_url, config, default_locale):
    default_post = {
        "title": "post title",
        "slug": "awesome_article",
        "date": "2012-10-01 22:41",
        "author": None,
        "tags": "tags",
        "link": "link",
        "description": "description",
        "enclosure": "http://www.example.org/foo.mp3",
        "enclosure_length": "5",
    }
    meta_mock = mock.Mock(return_value=(defaultdict(str, default_post), None))
    with mock.patch("nikola.post.get_meta", meta_mock):
        with mock.patch("nikola.nikola.utils.os.path.isdir",
                        mock.Mock(return_value=True)):
            with mock.patch("nikola.nikola.Post.text",
                            mock.Mock(return_value="some long text")):
                example_post = Post(
                    "source.file",
                    config,
                    "blog_folder",
                    True,
                    {"en": ""},
                    "post.tmpl",
                    FakeCompiler(),
                )

                filename = "testfeed.rss"
                opener_mock = mock.mock_open()

                with mock.patch("nikola.nikola.io.open",
                                opener_mock,
                                create=True):
                    Nikola().generic_rss_renderer(
                        default_locale,
                        "blog_title",
                        blog_url,
                        "blog_description",
                        [
                            example_post,
                        ],
                        filename,
                        True,
                        False,
                    )

                opener_mock.assert_called_once_with(filename,
                                                    "w+",
                                                    encoding="utf-8")

                # Python 3 / unicode strings workaround
                # lxml will complain if the encoding is specified in the
                # xml when running with unicode strings.
                # We do not include this in our content.
                file_content = [
                    call[1][0] for call in opener_mock.mock_calls[2:-1]
                ][0]
                splitted_content = file_content.split("\n")
                # encoding_declaration = splitted_content[0]
                content_without_encoding_declaration = splitted_content[1:]
                yield "\n".join(content_without_encoding_declaration)