Billy Barrow 1 hafta önce
ebeveyn
işleme
70dede1201
2 değiştirilmiş dosya ile 32 ekleme ve 4 silme
  1. 3 3
      examples/SimpleExample.vala
  2. 29 1
      src/Component.vala

+ 3 - 3
examples/SimpleExample.vala

@@ -12,7 +12,7 @@ class TestComponent : Component {
         <html>
         <body>
         <h1>Hello, World!</h1>
-        <spry-outlet id="content" />
+        <spry-outlet sid="content" />
         </body>
         </html>
         """;
@@ -40,12 +40,12 @@ class ContentComponent : Component {
 class UserContentComponent : Component {
     public override string markup { get {
         return """
-        <p>You said: <span id="message"></span></p>
+        <p>You said: <span sid="message"></span></p>
         """;
     }}
 
     public string message { set {
-        instance.get_element_by_id("message").text_content = value;
+        this["message"].text_content = value;
     }}
 
 }

+ 29 - 1
src/Component.vala

@@ -42,6 +42,30 @@ namespace Spry {
             return _instance;
         }}
 
+        protected MarkupNodeList get_elements_by_class_name(string class_name) {
+            return instance.get_elements_by_class_name(class_name);
+        }
+
+        protected MarkupNodeList get_elements_by_tag_name(string tag_name) {
+            return instance.get_elements_by_tag_name(tag_name);
+        }
+
+        protected new MarkupNodeList query(string xpath) {
+            return instance.select(xpath);
+        }
+
+        protected MarkupNode? query_one(string xpath) {
+            return instance.select_one(xpath);
+        }
+
+        protected MarkupNode get_element_by_global_id(string global_id) {
+            return instance.get_element_by_id(global_id);
+        }
+
+        protected new MarkupNode? @get(string spry_id) {
+            return instance.select_one(@"//*[@sid='$(spry_id)']");
+        }
+
         protected void add_outlet_child(string outlet_id, Component component) {
             _children.add(outlet_id, component);
         }
@@ -69,7 +93,7 @@ namespace Spry {
             var outlets = final_instance.select("//spry-outlet");
             foreach (var outlet in outlets) {
                 print(@"loop $(outlet.id)\n");
-                var nodes = _children.get_or_empty(outlet.id)
+                var nodes = _children.get_or_empty(outlet.get_attribute("sid"))
                     .attempt_select<MarkupDocument>(c => c.to_document())
                     .to_series() // To series first so we don't delete the document (which deletes the children internally)
                     .select_many<MarkupNode>(d => d.body.children);
@@ -86,6 +110,10 @@ namespace Spry {
             final_instance.select("//spry-control")
                 .iterate(n => n.replace_with_nodes(n.children));
 
+            // Finally, remove all internal SIDs
+            final_instance.select("//*[@sid]")
+                .iterate(n => n.remove_attribute("sid"));
+
             return final_instance;
         }