本文整理汇总了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!")
示例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)
示例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
示例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)
示例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)