Pyjoyment.Plugin.YAMLConfig - YAML configuration plugin¶
# myapp.yml (it's just YAML with embedded Python)
---
foo: bar
baz:
- ♥
music_dir: <%= app.home.child('music') %>
# Pyjoyment
config = app.plugin('YAMLConfig')
print(config['foo'])
# Pyjoyment.Lite
config = plugin('YAMLConfig')
print(config['foo'])
# foo.html.ep
%= config()['foo']
# The configuration is available application-wide
config = app.config()
print(config['foo'])
# Everything can be customized with options
config = plugin('YAMLConfig', file='/etc/myapp.conf')
Pyjoyment.Plugin.YAMLConfig is a YAML configuration plugin that
preprocesses its input with Pyjo.Template. By default it uses
Pyjo.YAML for parsing, which is not the best YAML module available, but
good enough for most config files. If you need something more correct you can
use a different module like PyYAML with the module option.
The application object can be accessed via app. A default configuration
filename in the application home directory will be generated from the value
of Pyjoyment.Pyjoyment_App.moniker ($moniker.yml). You can extend
the normal configuration file $moniker.yml with mode specific ones
like $moniker.$mode.yml, which will be detected automatically.
These configuration values are currently reserved:
config_overrideIf this configuration value has been set in
Pyjoyment.Pyjoyment_App.config()when this plugin is loaded, it will not do anything besides loading deployment specific plugins.
plugins
plugins:
- SetUserGroup:
user: sri
group: staff
One or more deployment specific plugins that should be loaded right after
this plugin has been loaded.
The code of this plugin is a good example for learning to build new plugins, you’re welcome to fork it.
See Pyjoyment.Plugins for a list of plugins that are available by
default.
Options¶
Pyjoyment.Plugin.YAMLConfig inherits all options from
Pyjoyment.Plugin.JSONConfig and supports the following new ones.
module
# Pyjoyment.Lite
plugin('YAMLConfig', module='yaml')
plugin('YAMLConfig', module=yaml.safe_load)
Alternative YAML module to use for parsing, whose function safe_load, or
load, takes a string, or such a function.
See also¶
Pyjoyment, https://mojolicious.org.
Ported from Mojolicious::Plugin::NotYAMLConfig of Mojolicious 9.49.
Classes¶
- class Pyjoyment.Plugin.YAMLConfig.Pyjoyment_Plugin_YAMLConfig¶
Pyjoyment.Plugin.YAMLConfiginherits all methods fromPyjoyment.Plugin.JSONConfigand implements the following new ones.- parse(content: str, file: str, conf: dict[str, Any], app: Pyjoyment_App) dict[str, Any]¶
plugin.parse(content, file, conf, app)
Process content with
render()and parse it withPyjo.YAML.def parse(self, content, file, conf, app): ... content = self.render(content, file, conf, app) ... return config
- register(app: Pyjoyment_App, conf: dict[str, Any] | None = None) dict[str, Any]¶
config = plugin.register(Pyjoyment.new()) config = plugin.register(Pyjoyment.new(), {'file': '/etc/foo.conf'})
Register plugin in
Pyjoymentapplication and merge configuration.