[gi-docgen/prop-default-attribute] generate: Parse attribute for property defaults




commit b4fa40328666c027a7b1fb6fb5d07b260dbb0a8d
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Sep 27 20:53:50 2021 +0100

    generate: Parse attribute for property defaults
    
    Introspection data does not have a default value for properties, so we
    should allow library authors to define the default through an attribute.

 docs/attributes.rst    |  3 +++
 gidocgen/gdgenerate.py | 10 ++++++++++
 2 files changed, 13 insertions(+)
---
diff --git a/docs/attributes.rst b/docs/attributes.rst
index c467b34..b67625a 100644
--- a/docs/attributes.rst
+++ b/docs/attributes.rst
@@ -21,6 +21,9 @@ The following attributes apply to properties.
   Defines the setter method for a given property. The value of the attribute is
   the C symbol of the function.
 
+``org.gtk.Property.default`` = ``s``
+  Defines the default value for a given property.
+
 Methods
 -------
 
diff --git a/gidocgen/gdgenerate.py b/gidocgen/gdgenerate.py
index b6245aa..fdb23c9 100644
--- a/gidocgen/gdgenerate.py
+++ b/gidocgen/gdgenerate.py
@@ -441,6 +441,12 @@ class TemplateProperty:
             href = f"method.{t.name}.{func_name}.html"
             return Markup(f"<a href=\"{href}\"><code>{getter_func}</code></a>")
 
+        def transform_default_attribute(namespace, prop, default_value):
+            if default_value is None:
+                log.warning(f"Missing value in the default attribute for {prop.name}")
+                return None
+            return Markup (f"<code>{default_value}</code>")
+
         ATTRIBUTE_NAMES = {
             "org.gtk.Property.set": {
                 "label": "Setter method",
@@ -450,6 +456,10 @@ class TemplateProperty:
                 "label": "Getter method",
                 "transform": transform_get_attribute,
             },
+            "org.gtk.Property.default": {
+                "label": "Default value",
+                "transform": transform_default_attribute,
+            },
         }
 
         self.attributes = {}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]