本文整理匯總了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)