Difference between revisions of "Template:Clade example/doc"

From blackwiki
Jump to navigation Jump to search
imported>Jts1882
(add example of intended result)
imported>Jts1882
(Add description of parameters)
Line 17: Line 17:
 
}}
 
}}
 
|}
 
|}
The goal of this template was to display example code and executed results in a table. This was to make writing the documentation easier and avoid the need for repeating the code twice, once enclosed in the pre tag and once without.
 
  
Unfortunately the attempt was unsuccessful. Parameters are transcluded when used unless in certain tags (pre, nowiki). One idea was to stip the tags from a transclusion protected parameter using the Lua module, but code wrapped in pre tags isn't passed to the module. Instead it passes a [https://www.mediawiki.org/wiki/Strip_marker strip marker].
+
This template is designed to aid writing documentation of the {{tl|clade}} by showing examples of code and the executed output, with option description and comment. It creates a table with four columns:
 +
* a description of what the example in the row shows
 +
* the code wrapped in <nowiki><pre></nowiki> tags,
 +
* the executed code, and
 +
* a comment on the example
 +
 
 +
Columns may be omitted option, e.g. just showing the code and output (as shown on the right).
 +
* <code>|description=</code> indicates that the description column should be shown. If used with a value it will set the header (default: Description).
 +
* <code>|code=</code>  indicates that the code column should be shown. A value will be used as the header (default: Code).
 +
* <code>|output=</code>  indicates that the output column should be shown. A value will be used as the header (default: Output).
 +
* <code>|comment=</code>  indicates that the comment column should be shown. A value will be used as the header (default: Commment).
 +
 
 +
The content of the rows is used using the parameters with a numerical suffix indicating the row number:
 +
** <code>|description1=</code> contains text describing the example in the first row. Similarly for |description2= ... |descriptionN.
 +
** <code>|code1=</code> contains the clade code for the first row wrapped <nowiki><pre></nowiki> tags.
 +
** <code>|output1=</code> contains the transcluded output of the clade code.
 +
** <code>|comment1=</code> contains a comment
 +
 
 +
Other options include:
 +
* <code>|align=</code> left | right | center
 +
 
 +
{{clear}}
 +
 
 +
<code><nowiki>
 +
 
 +
{{Clade example
 +
|align=left
 +
|description=
 +
|code=
 +
|output=
 +
|comment=
 +
|description1=Simple clade element
 +
|code1=<pre>{{clade
 +
|label1=Label
 +
|1={{clade
 +
  |1=Leaf A
 +
  |2=Leaf B
 +
  }}
 +
}}</pre>
 +
|output1={{clade
 +
      |label1=Label
 +
      |1={{clade |1=Leaf A |2=Leaf B}}
 +
      }}
 +
|comment1=Two child elements
 +
|description2=A more complex clade structure
 +
|code2=<pre>{{clade
 +
|label1=Label
 +
|1={{clade
 +
  |1=Node A (terminal)
 +
  |label2=Node B
 +
  |sublabel2=(internal)
 +
  |2={{clade
 +
      |1=Leaf 1
 +
      |2=Leaf 2
 +
      }}
 +
  }}
 +
}}</pre>
 +
|output2={{clade
 +
|label1=Label
 +
|1={{clade
 +
  |1=Node A (terminal)
 +
  |label2=Node B
 +
  |sublabel2=(internal)
 +
  |2={{clade
 +
      |1=Leaf 1
 +
      |2=Leaf 2
 +
      }}
 +
  }}
 +
}}
 +
|comment2=Two levels. The second clade element is nested in the first.
 +
|description3=description 3|code3=code 3 |output3=output 3 |comment3=comment 3
 +
|description4=description 4|code4=code 4 |output4=output 4 |comment4=comment 4
 +
 
 +
}}
 +
 
 +
</nowiki></code>
 +
 
 +
{{Clade example
 +
|align=left
 +
|description=
 +
|code=
 +
|output=
 +
|comment=
 +
|description1=Simple clade element
 +
|code1=<pre>{{clade
 +
|label1=Label
 +
|1={{clade
 +
  |1=Leaf A
 +
  |2=Leaf B
 +
  }}
 +
}}</pre>
 +
|output1={{clade
 +
      |label1=Label
 +
      |1={{clade |1=Leaf A |2=Leaf B}}
 +
      }}
 +
|comment1=Two child elements
 +
|description2=A more complex clade structure
 +
|code2=<pre>{{clade
 +
|label1=Label
 +
|1={{clade
 +
  |1=Node A (terminal)
 +
  |label2=Node B
 +
  |sublabel2=(internal)
 +
  |2={{clade
 +
      |1=Leaf 1
 +
      |2=Leaf 2
 +
      }}
 +
  }}
 +
}}</pre>
 +
|output2={{clade
 +
|label1=Label
 +
|1={{clade
 +
  |1=Node A (terminal)
 +
  |label2=Node B
 +
  |sublabel2=(internal)
 +
  |2={{clade
 +
      |1=Leaf 1
 +
      |2=Leaf 2
 +
      }}
 +
  }}
 +
}}
 +
|comment2=Two levels. The second clade element is nested in the first.
 +
|description3=description 3|code3=code 3 |output3=output 3 |comment3=comment 3
 +
|description4=description 4|code4=code 4 |output4=output 4 |comment4=comment 4
 +
 
 +
}}
 +
 
 +
P.S. The original goal of this template was to make writing the documentation easier by avoiding the need to repeating the code twice, once enclosed in the pre tag and once without. Unfortunately this is not possible. Parameters are transcluded when used unless in certain tags (pre, nowiki). Unfortunately these tags are passed to the module as [https://www.mediawiki.org/wiki/Strip_marker strip markers] so it is not possible to strip the tags from a transclusion protected parameter in the Lua module.
 
{{clear}}
 
{{clear}}
  

Revision as of 10:32, 18 August 2018

Template code Resulting output
{{clade
|label1=label 
|1={{clade 
   |1=leaf1 
   |2=leaf2 
   }}
}}
label

leaf1

leaf2

This template is designed to aid writing documentation of the {{clade}} by showing examples of code and the executed output, with option description and comment. It creates a table with four columns:

  • a description of what the example in the row shows
  • the code wrapped in <pre> tags,
  • the executed code, and
  • a comment on the example

Columns may be omitted option, e.g. just showing the code and output (as shown on the right).

  • |description= indicates that the description column should be shown. If used with a value it will set the header (default: Description).
  • |code= indicates that the code column should be shown. A value will be used as the header (default: Code).
  • |output= indicates that the output column should be shown. A value will be used as the header (default: Output).
  • |comment= indicates that the comment column should be shown. A value will be used as the header (default: Commment).

The content of the rows is used using the parameters with a numerical suffix indicating the row number:

    • |description1= contains text describing the example in the first row. Similarly for |description2= ... |descriptionN.
    • |code1= contains the clade code for the first row wrapped <pre> tags.
    • |output1= contains the transcluded output of the clade code.
    • |comment1= contains a comment

Other options include:

  • |align= left | right | center

{{Clade example |align=left |description= |code= |output= |comment= |description1=Simple clade element |code1=<pre>{{clade |label1=Label |1={{clade |1=Leaf A |2=Leaf B }} }}</pre> |output1={{clade |label1=Label |1={{clade |1=Leaf A |2=Leaf B}} }} |comment1=Two child elements |description2=A more complex clade structure |code2=<pre>{{clade |label1=Label |1={{clade |1=Node A (terminal) |label2=Node B |sublabel2=(internal) |2={{clade |1=Leaf 1 |2=Leaf 2 }} }} }}</pre> |output2={{clade |label1=Label |1={{clade |1=Node A (terminal) |label2=Node B |sublabel2=(internal) |2={{clade |1=Leaf 1 |2=Leaf 2 }} }} }} |comment2=Two levels. The second clade element is nested in the first. |description3=description 3|code3=code 3 |output3=output 3 |comment3=comment 3 |description4=description 4|code4=code 4 |output4=output 4 |comment4=comment 4 }}

DescriptionCodeOutputComment
Simple clade element
{{clade
|label1=Label
|1={{clade 
   |1=Leaf A 
   |2=Leaf B
   }}
}}
Label

Leaf A

Leaf B

Two child elements
A more complex clade structure
{{clade
|label1=Label
|1={{clade 
   |1=Node A (terminal)
   |label2=Node B
   |sublabel2=(internal)
   |2={{clade
      |1=Leaf 1
      |2=Leaf 2
      }}
   }}
}}
Label

Node A (terminal)

Node B

Leaf 1

Leaf 2

(internal)
Two levels. The second clade element is nested in the first.
description 3 code 3 output 3 comment 3
description 4 code 4 output 4 comment 4

P.S. The original goal of this template was to make writing the documentation easier by avoiding the need to repeating the code twice, once enclosed in the pre tag and once without. Unfortunately this is not possible. Parameters are transcluded when used unless in certain tags (pre, nowiki). Unfortunately these tags are passed to the module as strip markers so it is not possible to strip the tags from a transclusion protected parameter in the Lua module.

Usage