|
@@ -11,7 +11,8 @@ namespace Spry {
|
|
|
ELEMENT_NOT_FOUND,
|
|
ELEMENT_NOT_FOUND,
|
|
|
TYPE_NOT_FOUND,
|
|
TYPE_NOT_FOUND,
|
|
|
PROPERTY_NOT_FOUND,
|
|
PROPERTY_NOT_FOUND,
|
|
|
- CONFLICTING_ATTRIBUTES;
|
|
|
|
|
|
|
+ CONFLICTING_ATTRIBUTES,
|
|
|
|
|
+ INVALID_TEMPLATE;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public abstract class Component : Object, Renderable {
|
|
public abstract class Component : Object, Renderable {
|
|
@@ -148,7 +149,7 @@ namespace Spry {
|
|
|
return final_instance;
|
|
return final_instance;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public async MarkupDocument to_fragment(string sid) throws Error {
|
|
|
|
|
|
|
+ internal async MarkupDocument get_fragment_document(string fragment) throws Error {
|
|
|
if(!_prepare_once_called) {
|
|
if(!_prepare_once_called) {
|
|
|
yield prepare_once();
|
|
yield prepare_once();
|
|
|
_prepare_once_called = true;
|
|
_prepare_once_called = true;
|
|
@@ -157,9 +158,9 @@ namespace Spry {
|
|
|
|
|
|
|
|
// Extract the fragment
|
|
// Extract the fragment
|
|
|
var final_instance = instance.copy();
|
|
var final_instance = instance.copy();
|
|
|
- var template_fragment = final_instance.select_one(@"//*[@sid='$sid']")?.outer_html;
|
|
|
|
|
|
|
+ var template_fragment = final_instance.select_one(@"//*[@spry-fragment='$fragment']")?.outer_html;
|
|
|
if(template_fragment == null) {
|
|
if(template_fragment == null) {
|
|
|
- throw new ComponentError.ELEMENT_NOT_FOUND(@"No spry-component with sid '$sid' found.");
|
|
|
|
|
|
|
+ throw new ComponentError.ELEMENT_NOT_FOUND(@"Could not find fragment names '$fragment'.");
|
|
|
}
|
|
}
|
|
|
final_instance.body.inner_html = template_fragment;
|
|
final_instance.body.inner_html = template_fragment;
|
|
|
|
|
|
|
@@ -168,6 +169,23 @@ namespace Spry {
|
|
|
return final_instance;
|
|
return final_instance;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public async MarkupDocument get_globals_document() throws Error {
|
|
|
|
|
+ if(!_prepare_once_called) {
|
|
|
|
|
+ yield prepare_once();
|
|
|
|
|
+ _prepare_once_called = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ yield prepare();
|
|
|
|
|
+
|
|
|
|
|
+ var final_instance = instance.copy();
|
|
|
|
|
+ yield transform_document(final_instance);
|
|
|
|
|
+
|
|
|
|
|
+ // Extract out globals
|
|
|
|
|
+ var globals = final_instance.select("//[@spry-global]");
|
|
|
|
|
+ var globals_document = new MarkupDocument();
|
|
|
|
|
+ globals_document.body.append_nodes(globals);
|
|
|
|
|
+ return globals_document;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public async HttpResult to_result() throws Error {
|
|
public async HttpResult to_result() throws Error {
|
|
|
var document = yield to_document();
|
|
var document = yield to_document();
|
|
@@ -210,6 +228,7 @@ namespace Spry {
|
|
|
transform_target_nodes(doc);
|
|
transform_target_nodes(doc);
|
|
|
transform_global_nodes(doc);
|
|
transform_global_nodes(doc);
|
|
|
transform_script_nodes(doc);
|
|
transform_script_nodes(doc);
|
|
|
|
|
+ transform_fragment_attributes(doc);
|
|
|
transform_continuation_nodes(doc);
|
|
transform_continuation_nodes(doc);
|
|
|
remove_internal_sids(doc);
|
|
remove_internal_sids(doc);
|
|
|
yield append_globals(doc);
|
|
yield append_globals(doc);
|
|
@@ -297,9 +316,8 @@ namespace Spry {
|
|
|
|
|
|
|
|
private async void append_globals(MarkupDocument doc) throws Error {
|
|
private async void append_globals(MarkupDocument doc) throws Error {
|
|
|
foreach(var source in _global_sources) {
|
|
foreach(var source in _global_sources) {
|
|
|
- var document = yield source.to_document();
|
|
|
|
|
- var globals = document.select("//*[@spry-global]");
|
|
|
|
|
- doc.body.append_nodes(globals);
|
|
|
|
|
|
|
+ var globals = yield source.get_globals_document();
|
|
|
|
|
+ doc.body.append_nodes(globals.body.children);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -312,6 +330,26 @@ namespace Spry {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void transform_fragment_attributes(MarkupDocument doc) throws Error {
|
|
|
|
|
+ var nodes = doc.select("//*[@spry-fragment]");
|
|
|
|
|
+ foreach (var node in nodes) {
|
|
|
|
|
+ var name = node.get_attribute("spry-fragment");
|
|
|
|
|
+
|
|
|
|
|
+ MarkupNode parent = node;
|
|
|
|
|
+ while((parent = parent.parent) != null) {
|
|
|
|
|
+ if(parent.has_attribute("spry-continuation"));
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(parent == null) {
|
|
|
|
|
+ throw new ComponentError.INVALID_TEMPLATE("A tag with a spry-fragment attribute must be the child of a tag with a spry-continuation attribute");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ node.set_attribute("sse-swap", @"_spry-fragment-$name");
|
|
|
|
|
+ node.set_attribute("hx-swap", "outerHTML");
|
|
|
|
|
+ node.remove_attribute("spry-fragment");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void transform_if_attributes(MarkupDocument doc, EvaluationContext? context = null) throws Error {
|
|
private void transform_if_attributes(MarkupDocument doc, EvaluationContext? context = null) throws Error {
|
|
|
var root = new PropertyDictionary();
|
|
var root = new PropertyDictionary();
|
|
|
root["this"] = new NativeElement<Component>(this);
|
|
root["this"] = new NativeElement<Component>(this);
|