diff --git a/CHANGES.rst b/CHANGES.rst index b4472f0..d6856a2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,10 @@ Changes gets passed ``widget`` and ``data`` as of yafowil 3.0.0. [rnix] +- Parse values of attributes (data-Attributes) if type() is dict. + HTML5 Data-Attributes with i18n or callables are possible now. + [2silver] + **Breaking changes:** - Add ``python:`` expressions. Needed for cases where property callbacks not diff --git a/src/yafowil/yaml/parser.py b/src/yafowil/yaml/parser.py index 26bf5af..acbea4a 100644 --- a/src/yafowil/yaml/parser.py +++ b/src/yafowil/yaml/parser.py @@ -119,8 +119,7 @@ def load_yaml(self, path): def create_tree(self, data): def call_factory(defs): props = dict() - for k, v in defs.get('props', dict()).items(): - props[k] = self.parse_definition_value(v) + props = self.parse_attribute(defs.get('props', dict())) custom = dict() for custom_key, custom_value in defs.get('custom', dict()).items(): custom_props = list() @@ -171,6 +170,16 @@ def create_children(node, children_defs): create_children(root, data.get('widgets', [])) return root + def parse_attribute(self, value): + if not isinstance(value, dict): + return self.parse_definition_value(value) + for k, v in value.items(): + if isinstance(v, dict): + self.parse_attribute(v) + else: + value[k] = self.parse_definition_value(v) + return value + def parse_definition_value(self, value): if not isinstance(value, STR_TYPE): return value diff --git a/src/yafowil/yaml/tests.py b/src/yafowil/yaml/tests.py index 04f0091..6479935 100644 --- a/src/yafowil/yaml/tests.py +++ b/src/yafowil/yaml/tests.py @@ -85,6 +85,11 @@ def tearDown(self): label: i18n:First Field description: I am the description required: I am required + data: + flat: I am a flat data-attribute + i18n: i18n:nested_firstfield:i18n Nested First Field + nested: + nested-i18n: i18n:nested_firstfield:i18n Nested First Field - secondfield: factory: field:label:*custom_stuff:error:select value: ['a', 'b'] @@ -114,7 +119,14 @@ def test_load_yaml(self): 'props': { 'description': 'I am the description', 'label': 'i18n:First Field', - 'required': 'I am required' + 'required': 'I am required', + 'data': { + 'flat': 'I am a flat data-attribute', + 'i18n': 'i18n:nested_firstfield:i18n Nested First Field', + 'nested': { + 'nested-i18n': 'i18n:nested_firstfield:i18n Nested First Field' + } + } } } }, { @@ -253,9 +265,15 @@ def test_parse_from_yaml(self): id="form-demoform" method="post" novalidate="novalidate">