API¶
-
class
settingscascade.
ElementSchema
(configManager)¶ Class that defines the schema for a particular element in your settings heirarchy. Subclass this and add annotations to define the allowed values for this element type-
class Element(ElementSchema): color: str height: int
-
property
context
¶ The context stack that will be used to look up settings for this object
-
load
()¶ Loads the settings for this schema into a python dictionary. Looks up the value for each property using the current context stack for this object.
Note
This will throw an error if there are settings defined on the schema that can’t be found in any level!
-
property
-
class
settingscascade.
SettingsManager
(data: List[dict], els: Optional[List[Type[settingscascade.element_schema.ElementSchema]]] = None)¶ A Settingsmanager object.
- Parameters
data – a list of settings dictionaries
els – a List of ElementSchema objects, If not specified, no elements will be created
-
context
(new_context: str = '')¶ Add context onto the current context. This takes a string and appends it to the existing context. For example (using html elements-)
with config.context("body h1.intro"): with config.context("div.myel"): config.current_context == "body h1.intro div.myel"
-
property
current_context
¶ Gets a string that represents the current context used for settings lookups :return: str
-
load_data
(data: dict, next_item: str = '', selector: str = '')¶ Loads a settings dictionary into the rule stack.
- Parameters
data – A settings dictionary. Keys should either be selectors or value names.
next_item – The key for this rule-set. Pulled from the parent dict when loading recursively.
selector – The full context selector for any parent rule-sets that should be added to the selector for this one