summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com>2017-08-11 13:31:07 +0200
committerJuergen Bocklage-Ryannel <jbocklage-ryannel@luxoft.com>2017-08-11 13:31:07 +0200
commit370e6f62437d11a7c6974cd5ed71e6a8f0761ded (patch)
tree85616efa0429148acbb96c6070638014609a63a8
parentda9c49bcb3bd3982f8f247394c3913ae5520de0f (diff)
downloadqtivi-qface-370e6f62437d11a7c6974cd5ed71e6a8f0761ded.tar.gz
Changed the logic for preserved documents in a rule file.
To make a document preserve you just move the target/source pair into the preserve tag of the rule.
-rw-r--r--docs/extending.rst10
-rw-r--r--qface/generator.py8
2 files changed, 7 insertions, 11 deletions
diff --git a/docs/extending.rst b/docs/extending.rst
index 042f094..a678ea8 100644
--- a/docs/extending.rst
+++ b/docs/extending.rst
@@ -140,9 +140,9 @@ The features are passed to the generator in your custom generator code. The exis
Here the plugin rule will only be run when the feature set contains a 'plugin_enabled' string.
-.. rubric:: Preserve
+.. rubric:: Preserving Documents
-Documents can be marked as preserved to prevent them to be overwritten when the user has edited them. the rules documents has an own marker for this called ``preserve``. This is a list of target documents which shall be be marked preserved by the generator.
+Documents can be moved to the ``preserve`` tag to prevent them to be overwritten. The rules documents has an own marker for this called ``preserve``. This is the same dictionary of target/source documents which shall be be marked preserved by the generator.
.. code-block:: yaml
@@ -151,12 +151,10 @@ Documents can be marked as preserved to prevent them to be overwritten when the
interface:
documents:
'{{interface|lower}}.h': 'plugin/interface.h'
- '{{interface|lower}}.cpp': 'plugin/interface.cpp'
preserve:
- - '{{interface|lower}}.h'
- - '{{interface|lower}}.cpp'
+ '{{interface|lower}}.cpp': 'plugin/interface.cpp'
-In the example above the two interface documents will not be overwritten during a second generator call and can be edited by the user.
+In the example above the preserve listed documents will not be overwritten during a second generator run and can be edited by the user.
.. rubric:: Destination and Source
diff --git a/qface/generator.py b/qface/generator.py
index 176ef28..d96d649 100644
--- a/qface/generator.py
+++ b/qface/generator.py
@@ -218,12 +218,10 @@ class RuleGenerator(Generator):
self.context.update(rule.get('context', {}))
self.destination = rule.get('destination', None)
self.source = rule.get('source', None)
- preserved = rule.get('preserve', [])
- if not preserved:
- preserved = []
for target, source in rule.get('documents', {}).items():
- preserve = target in preserved
- self.write(target, source, preserve=preserve)
+ self.write(target, source)
+ for target, source in rule.get('preserve', {}).items():
+ self.write(target, source, preserve=True)
def _shall_proceed(self, obj):
conditions = obj.get('when', [])