Difference between revisions of "Template:Tree/Subtree"

From Green Family Wiki
Jump to: navigation, search
m (5 revisions imported: Initial import from smithfam)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>Apply a template to a string, and then recursively apply this function to each "child", as defined by a function.
+
<noinclude>Helper for [[Template:Tree]]: apply a template to a string, and then recursively apply this function to each "child", as defined by a function.
 
* First parameter: Delimiter to prefix future nodes
 
* First parameter: Delimiter to prefix future nodes
* Second parameter: Current delimiter to prefix parent
 
 
* ''current parent'': Parent of this subtree
 
* ''current parent'': Parent of this subtree
 
* ''depth'': Depth of parent
 
* ''depth'': Depth of parent
 
* ''index'': i, where parent is the ith child of its parent
 
* ''index'': i, where parent is the ith child of its parent
 
* ''template'': Template to apply to each node (first parameter is the node; ''depth'' and ''index'' are the tree coordinates, 1-based)
 
* ''template'': Template to apply to each node (first parameter is the node; ''depth'' and ''index'' are the tree coordinates, 1-based)
* ''children'': Function mapping a parent to children (first parameter is the node; second parameter is the requested index, 1-based; empty result indicates no more children)
+
* ''children'': Function mapping a parent to children (first parameter is the node; ''depth'' and ''index'' are the tree coordinates of the child, 1-based; empty result indicates no more children)
</noinclude><includeonly>{{Wrap|{{{2}}}|{{{{{template}}}|{{{current parent}}}|
+
</noinclude><includeonly>{{{{{template}}}|{{{current parent}}}|
 
   depth={{{depth}}}
 
   depth={{{depth}}}
 
| index={{{index}}}
 
| index={{{index}}}
 
}}{{Tree/Children|{{{1}}}|{{{1}}}|
 
}}{{Tree/Children|{{{1}}}|{{{1}}}|
 
| current parent={{{current parent}}}
 
| current parent={{{current parent}}}
| current child={{{{{children}}}|{{{current parent}}}|1}}
+
| current child={{{{{children}}}|{{{current parent}}}| depth={{#expr:{{{depth}}}+1}} | index=1}}
 
| depth={{#expr:{{{depth}}}+1}}
 
| depth={{#expr:{{{depth}}}+1}}
 
| index=1
 
| index=1

Latest revision as of 12:11, 7 December 2015

Helper for Template:Tree: apply a template to a string, and then recursively apply this function to each "child", as defined by a function.

  • First parameter: Delimiter to prefix future nodes
  • current parent: Parent of this subtree
  • depth: Depth of parent
  • index: i, where parent is the ith child of its parent
  • template: Template to apply to each node (first parameter is the node; depth and index are the tree coordinates, 1-based)
  • children: Function mapping a parent to children (first parameter is the node; depth and index are the tree coordinates of the child, 1-based; empty result indicates no more children)