dict2css.serializer¶
Serializer for cascading style sheets.
New in version 0.2.0.
Classes:
|
Serializes a dictionary to CSS. |
-
class
CSSSerializer(*, indent='\t', trailing_semicolon=None, indent_closing_brace=False, minify=False, sort_keys=False, check_circular=True, none_style='none')[source]¶ Serializes a dictionary to CSS.
This controls the formatting of the style sheet.
- Parameters
indent (
str) – The indent to use, such as a tab (\t), two spaces or four spaces. Default'\t'.trailing_semicolon (
Optional[bool]) – Whether to add a semicolon to the end of the final property. DefaultNone.minify (
bool) – Minify the CSS. Overrides all other options. DefaultFalse.sort_keys (
bool) – Sort dictionary keys alphabetically. DefaultFalse.check_circular (
bool) – Check for circular references. DefaultTrue.none_style (
Union[Literal['none'],Literal['None']]) – Whether to representNoneasNoneornone. Default'none'.
Changed in version 0.5.0: New implementation. Output may differ slightly from previous css-parser based one.
Changed in version 0.6.0: Added
none_styleoption.Methods:
default(obj)Override this method in a subclass to implement custom serialization for objects that are not serializable by default.
encode(obj)Return a CSS representation of a Python dictionary.
iterencode(obj)Encode the given dictionary and yield each part of the CSS string representation.
Reset the serializer to its default style.
use()No-op.
-
default(obj)[source]¶ Override this method in a subclass to implement custom serialization for objects that are not serializable by default.
This method should return a serializable object. If this method is not overridden, the encoder will raise a
ValueErrorwhen trying to encode an unsupported object.