当前位置: 首页>>代码示例>>Python>>正文


Python plugins.BasePlugin方法代码示例

本文整理汇总了Python中mkdocs.plugins.BasePlugin方法的典型用法代码示例。如果您正苦于以下问题:Python plugins.BasePlugin方法的具体用法?Python plugins.BasePlugin怎么用?Python plugins.BasePlugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mkdocs.plugins的用法示例。


在下文中一共展示了plugins.BasePlugin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: conf

# 需要导入模块: from mkdocs import plugins [as 别名]
# 或者: from mkdocs.plugins import BasePlugin [as 别名]
def conf(self):
        """
        Dictionary containing of the whole config file (by default: mkdocs.yml)

        This property may be useful if the code in the module needs to access
        general configuration information.

        NOTE: this property is called 'conf', because there is already
              a 'config' property in a BasePlugin object,
              which is the data connected to the macros plugin
              (in the yaml file)
        """
        try:
            return self._conf
        except AttributeError:
            raise AttributeError("Conf property of macros plugin "
                                 "was called before it was initialized!") 
开发者ID:fralau,项目名称:mkdocs_macros_plugin,代码行数:19,代码来源:plugin.py

示例2: test_plugin_config_with_options

# 需要导入模块: from mkdocs import plugins [as 别名]
# 或者: from mkdocs.plugins import BasePlugin [as 别名]
def test_plugin_config_with_options(self, mock_class):

        cfg = {
            'plugins': [{
                'sample': {
                    'foo': 'foo value',
                    'bar': 42
                }
            }]
        }
        option = config.config_options.Plugins()
        cfg['plugins'] = option.validate(cfg['plugins'])

        self.assertIsInstance(cfg['plugins'], plugins.PluginCollection)
        self.assertIn('sample', cfg['plugins'])
        self.assertIsInstance(cfg['plugins']['sample'], plugins.BasePlugin)
        expected = {
            'foo': 'foo value',
            'bar': 42,
            'dir': None,
        }
        self.assertEqual(cfg['plugins']['sample'].config, expected) 
开发者ID:mkdocs,项目名称:mkdocs,代码行数:24,代码来源:plugin_tests.py

示例3: load_plugin

# 需要导入模块: from mkdocs import plugins [as 别名]
# 或者: from mkdocs.plugins import BasePlugin [as 别名]
def load_plugin(self, name, config):
        if name not in self.installed_plugins:
            raise ValidationError('The "{}" plugin is not installed'.format(name))

        Plugin = self.installed_plugins[name].load()

        if not issubclass(Plugin, plugins.BasePlugin):
            raise ValidationError('{}.{} must be a subclass of {}.{}'.format(
                Plugin.__module__, Plugin.__name__, plugins.BasePlugin.__module__,
                plugins.BasePlugin.__name__))

        plugin = Plugin()
        errors, warnings = plugin.load_config(config, self.config_file_path)
        self.warnings.extend(warnings)
        errors_message = '\n'.join(
            "Plugin value: '{}'. Error: {}".format(x, y)
            for x, y in errors
        )
        if errors_message:
            raise ValidationError(errors_message)
        return plugin 
开发者ID:mkdocs,项目名称:mkdocs,代码行数:23,代码来源:config_options.py

示例4: test_plugin_config_without_options

# 需要导入模块: from mkdocs import plugins [as 别名]
# 或者: from mkdocs.plugins import BasePlugin [as 别名]
def test_plugin_config_without_options(self, mock_class):

        cfg = {'plugins': ['sample']}
        option = config.config_options.Plugins()
        cfg['plugins'] = option.validate(cfg['plugins'])

        self.assertIsInstance(cfg['plugins'], plugins.PluginCollection)
        self.assertIn('sample', cfg['plugins'])
        self.assertIsInstance(cfg['plugins']['sample'], plugins.BasePlugin)
        expected = {
            'foo': 'default foo',
            'bar': 0,
            'dir': None,
        }
        self.assertEqual(cfg['plugins']['sample'].config, expected) 
开发者ID:mkdocs,项目名称:mkdocs,代码行数:17,代码来源:plugin_tests.py

示例5: test_plugin_config_none_with_default

# 需要导入模块: from mkdocs import plugins [as 别名]
# 或者: from mkdocs.plugins import BasePlugin [as 别名]
def test_plugin_config_none_with_default(self, mock_class):
        # Default is used.
        cfg = {'plugins': None}
        option = config.config_options.Plugins(default=['sample'])
        cfg['plugins'] = option.validate(cfg['plugins'])

        self.assertIsInstance(cfg['plugins'], plugins.PluginCollection)
        self.assertIn('sample', cfg['plugins'])
        self.assertIsInstance(cfg['plugins']['sample'], plugins.BasePlugin)
        expected = {
            'foo': 'default foo',
            'bar': 0,
            'dir': None,
        }
        self.assertEqual(cfg['plugins']['sample'].config, expected) 
开发者ID:mkdocs,项目名称:mkdocs,代码行数:17,代码来源:plugin_tests.py


注:本文中的mkdocs.plugins.BasePlugin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。