Difference between revisions of "Template:ListEdges"

From AtlasWiki
Jump to: navigation, search
(Now handles multiple in edges of the same type from different node kinds)
(removing the trailing empty line from the tables)
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
If the parameter "parents" is given a comma-separated list of the parents of the node, inherited edges will also be listed.
 
If the parameter "parents" is given a comma-separated list of the parents of the node, inherited edges will also be listed.
</noinclude>{{#ask: [[edge to {{PAGENAME}}::+]]
+
</noinclude>{{#ask: [[permitted edge to {{PAGENAME}}::+]]
| ?edge to {{PAGENAME}}
+
| ?permitted edge to {{PAGENAME}}
 
| format=array
 
| format=array
 
| headers=hide
 
| headers=hide
| name=inEdges
+
| name=permittedInEdges
 +
}}{{#ask: [[specified edge to {{PAGENAME}}::+]]
 +
| ?specified edge to {{PAGENAME}}
 +
| format=array
 +
| headers=hide
 +
| name=specifiedInEdges
 +
}}{{#ask: [[permitted edge from {{PAGENAME}}::+]]
 +
| ?permitted edge from {{PAGENAME}}
 +
| format=array
 +
| headers=hide
 +
| name=permittedOutEdges
 +
}}{{#ask: [[specified edge from {{PAGENAME}}::+]]
 +
| ?specified edge from {{PAGENAME}}
 +
| format=array
 +
| headers=hide
 +
| name=specifiedOutEdges
 
}}<noinclude><!--
 
}}<noinclude><!--
  
Above, we've stored all the in edges in an array named "inEdges".
+
Above, we've stored all the in edges in an arrays named "permittedInEdges", "specifiedInEdges", "permittedOutEdges", and "specifiedOutEdges".
  
Each entry in the array is in this format:
+
Each entry in each array is in this format:
  
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]
Line 21: Line 36:
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]<MANY>[name of other predecessor]$SEP$[multiplicity]
 
[name of edge]<PROP>[name of predecessor]$SEP$[multiplicity]$SEP$[edge description]<MANY>[name of other predecessor]$SEP$[multiplicity]
  
...now we parse those into an "In Edge" table, if and only if there is at least one in edge:
+
...now we want similar information about inherited in edges:
 
+
--></noinclude>{{#switch:{{#arraysize:inEdges}}| 0 = | #default =
+
{{{!}} class="xcsgtable"
+
! In Edge !! Predecessor (Comes From) !! Multiplicity !! Description
+
{{!}}-
+
{{!}}{{#arrayprint:inEdges|{{!}}-
+
{{!}}|var|{{#arraydefine:edgeRelationships|var|<PROP>|}}{{#arraydefine:relationships|{{#arrayindex:edgeRelationships|1}}|<MANY>|}}{{#arrayprint:relationships|&#32;
+
{{!}}-
+
{{!}}|@@@@|[[{{#arrayindex:edgeRelationships|0}}]] {{!}}{{!}} [[{{#explode:@@@@|$SEP$|0}}]] {{!}}{{!}} {{#explode:@@@@|$SEP$|1}} {{!}}{{!}} {{ReconstructLinks|{{#explode:@@@@|$SEP$|2}}}} }}
+
{{!}}}
+
}}<noinclude><!--
+
 
+
If we were given inheritance information, discover and list the inherited edges as well...if there are any inherited edges.
+
 
+
--></noinclude>{{#if:{{{parents|}}}|{{#arraydefine:parents|{{{parents}}}|,|}}{{#if:{{#arrayprint:parents||@@@@|{{InheritEdgesTo|@@@@}}}}|
+
{{{!}} class="xcsgtable"
+
{{!}}-
+
! colspan="5" {{!}} Inherited In Edges
+
{{!}}-
+
! Inherited From !! In Edge  !! Predecessor (Comes From) !! Multiplicity !! Description
+
{{#arrayprint:parents||@@@@|&#32;
+
{{InheritEdgesTo|@@@@}}}}
+
{{!}}} }} }}<noinclude><!--
+
 
+
Next we get the out edges:
+
 
+
--></noinclude>{{#ask: [[edge from {{PAGENAME}}::+]]
+
| ?edge from {{PAGENAME}}
+
| format=array
+
| headers=hide
+
| propsep=$SEP$
+
| name=outEdges
+
}}<noinclude><!--
+
 
+
If both arrays have values, then we need to add the whitespace that goes between the two tables.
+
 
+
--></noinclude>{{#switch:{{#arraysize:inEdges}}| 0 = | #default = {{#switch:{{#arraysize:outEdges}}| 0 = |
+
 
+
}} }}<noinclude><!--
+
 
+
We print the out edges table:
+
 
+
--></noinclude>{{#switch:{{#arraysize:outEdges}}| 0 = | #default =
+
{{{!}} class="xcsgtable"
+
! Out Edge !! Successor (Points To) !! Multiplicity !! Description
+
{{!}}-
+
{{!}}{{#arrayprint:outEdges|{{!}}-
+
{{!}}|var|[[{{#explode:var|$SEP$|0}}]] {{!}}{{!}} [[{{#explode:var|$SEP$|1}}]] {{!}}{{!}} {{#explode:var|$SEP$|2}} {{!}}{{!}} {{ReconstructLinks|{{#explode:var|$SEP$|3}}}} }}
+
{{!}}}
+
}}<noinclude><!--
+
  
And the inherited out edges table:
+
--></noinclude>{{#arraydefine:parentsArray|{{{parents|}}}|,|}}<noinclude><!--
 +
 +
We gather the information on inherited edges as well, then defer to a helper template to print the actual tables
  
--></noinclude>{{#if:{{{parents|}}}|{{#if:{{#arrayprint:parents||@@@@|{{InheritEdgesFrom|@@@@}}}}|
+
There's one tricky bit here: we need to have a <PARENT_SEP> separator if and only if a parent actually contributes connections. We do that by not using the separator argument of the #arrayprint:parentsArray, and instead printing <PARENT_SEP> after each one...which results in one small problem: there's an extra <PARENT_SEP> on the end that we need to remove...so we parse the result into an array again, slice off the final element with #arrayslice, and re-print it using <PARENT_SEP> as the separator.
{{{!}} class="xcsgtable"
+
{{!}}-
+
--></noinclude>{{ListEdges.generateTable
! colspan="5" {{!}} Inherited Out Edges
+
| title = Specified In Edges
{{!}}-
+
| edgeTitle = In Edge
! Inherited From !! Out Edge !! Successor (Points To) !! Multiplicity !! Description
+
| nodeTitle = <abbr title="The node that the edge comes from">Predecessor</abbr>
{{#arrayprint:parents||@@@@|&#32;
+
| uninheritedEdges = {{#arrayprint:specifiedInEdges|<EDGE_SEP>}}
{{InheritEdgesFrom|@@@@}}}}
+
| inheritedEdges = {{#arraydefine:temp|{{#arrayprint:parentsArray||@@@@|{{#if:{{EdgesTo|@@@@|specified}}|@@@@<PARENT>{{EdgesTo|@@@@|specified}}<PARENT_SEP>}} }}|<PARENT_SEP>|}}{{#arrayslice:temp|temp|0|{{#expr:{{#arraysize:temp}}-1}}}}{{#arrayprint:temp|<PARENT_SEP>|@@@@|@@@@}}
{{!}}} }} }}<noinclude>[[Category:XCSG Templates]]</noinclude>
+
}}{{ListEdges.generateTable
 +
| title = Specified Out Edges
 +
| edgeTitle = Out Edge
 +
| nodeTitle = <abbr title="The node that the edge points to">Successor</abbr>
 +
| uninheritedEdges = {{#arrayprint:specifiedOutEdges|<EDGE_SEP>}}
 +
| inheritedEdges = {{#arraydefine:temp|{{#arrayprint:parentsArray||@@@@|{{#if:{{EdgesFrom|@@@@|specified}}|@@@@<PARENT>{{EdgesFrom|@@@@|specified}}<PARENT_SEP>}} }}|<PARENT_SEP>|}}{{#arrayslice:temp|temp|0|{{#expr:{{#arraysize:temp}}-1}}}}{{#arrayprint:temp|<PARENT_SEP>|@@@@|@@@@}}
 +
}}{{ListEdges.generateTable
 +
| title = Known Possible In Edges
 +
| edgeTitle = In Edge
 +
| nodeTitle = <abbr title="The node that the edge comes from">Predecessor</abbr>
 +
| uninheritedEdges = {{#arrayprint:permittedInEdges|<EDGE_SEP>}}
 +
| inheritedEdges = {{#arraydefine:temp|{{#arrayprint:parentsArray||@@@@|{{#if:{{EdgesTo|@@@@|permitted}}|@@@@<PARENT>{{EdgesTo|@@@@|permitted}}<PARENT_SEP>}} }}|<PARENT_SEP>|}}{{#arrayslice:temp|temp|0|{{#expr:{{#arraysize:temp}}-1}}}}{{#arrayprint:temp|<PARENT_SEP>|@@@@|@@@@}}
 +
}}{{ListEdges.generateTable
 +
| title = Known Possible Out Edges
 +
| edgeTitle = Out Edge
 +
| nodeTitle = <abbr title="The node that the edge points to">Successor</abbr>
 +
| uninheritedEdges = {{#arrayprint:permittedOutEdges|<EDGE_SEP>}}
 +
| inheritedEdges = {{#arraydefine:temp|{{#arrayprint:parentsArray||@@@@|{{#if:{{EdgesFrom|@@@@|permitted}}|@@@@<PARENT>{{EdgesFrom|@@@@|permitted}}<PARENT_SEP>}} }}|<PARENT_SEP>|}}{{#arrayslice:temp|temp|0|{{#expr:{{#arraysize:temp}}-1}}}}{{#arrayprint:temp|<PARENT_SEP>|@@@@|@@@@}}
 +
}}

Latest revision as of 14:03, 12 May 2014

For use on node kind pages, automatically lists edges declared on the current page.

If the parameter "parents" is given a comma-separated list of the parents of the node, inherited edges will also be listed.