Difference between revisions of "Template:EnsureNamespace"

From AtlasWiki
Jump to: navigation, search
(Make parameter "optional", with no output if no parameter provided (instead of a horrible mess))
(Undo accidental replacement with a different template)
 
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
This template is designed to help in discovering distinct parents that can be reached over "extends" relationships among XCSG elements within a specific number of inheritance steps.
+
Ensures that the parameter passed in starts with a namespace, if none is present, the XCSG namespace is assumed to be correct, and is automatically added.
 
+
</noinclude><includeonly>{{#arraydefine:arg|{{{1|}}}|:|}}{{#if:{{#arrayindex:arg|1}}|{{{1}}}|XCSG:{{{1}}}}}</includeonly>
Note that the results of this template will always include the parameters, and will always trim off the XCSG namespace from both inputs and results.
+
 
+
For example: <nowiki>{{DiscoverParents|{{PAGENAME}}}}</nowiki> should return a comma-separated list of parents of the current page, which also includes the current page itself. <nowiki>{{FULLPAGENAME}}</nowiki> instead should produce exactly the same results.
+
 
+
<nowiki>{{DiscoverParents|{{DiscoverParents|{{PAGENAME}}}}</nowiki> should find all parents and grandparents, with each listed only once in case a diamond pattern occurs, and will again include the current page itself.
+
 
+
To avoid including the current page, combine use of this template with the [[Template:ParentsOf]] template:
+
 
+
<nowiki>{{DiscoverParents|{{ParentsOf|{{FULLPAGENAME}}}}}}</nowiki> will return two levels of parents of
+
 
+
This template can also be used to find the union of the parents of two or more unrelated XCSG nodes or edges, for example, this query would find the union of the parents and grand-parents of X and Y: <nowiki>{{DiscoverParents|{{ParentsOf|X}}, {{ParentsOf|Y}}}}</nowiki>
+
</noinclude><noinclude><!--
+
 
+
 
+
First, we define the result as an empty array.
+
 
+
--></noinclude>{{#arraydefine:parents}}<noinclude><!--
+
 
+
Next, we split up our input parameters into an array.
+
 
+
--></noinclude>{{#arraydefine:children|{{{1|}}}|, |}}<noinclude><!--
+
 
+
Then, we find the parents of each child, storing them in an array.
+
Still within that arrayprint instruction, we union that array with our result set.
+
 
+
--></noinclude>{{#arrayprint:children||@@@@|{{#arraydefine:moreParents|{{ParentsOf|@@@@}}|, |}}{{#arrayunion:parents|parents|moreParents}}|}}<noinclude><!--
+
 
+
We also need to union with the original parameters.
+
 
+
--></noinclude>{{#arrayunion:parents|children|parents}}<noinclude><!--
+
 
+
There's one remaining small issue: in a few cases we can end up with both "page" and "XCSG:page" in the results, so we need to define a new array to eliminate that issue...
+
 
+
--></noinclude>{{#arraydefine:simplified|{{#arrayprint:parents|,|@@@@|{{EnsureNamespace|@@@@}}|}}|,|unique}}<noinclude><!--
+
 
+
Finally, print out our simplified list of parents with namespaces removed.
+
 
+
--></noinclude>{{#arrayprint:simplified|,|@@@@|@@@@}}<noinclude>[[Category:XCSG Templates]]</noinclude>
+

Latest revision as of 13:14, 22 May 2014

Ensures that the parameter passed in starts with a namespace, if none is present, the XCSG namespace is assumed to be correct, and is automatically added.