Template:In5: Difference between revisions
(add interwiki) |
(rewrote as 10-space groups +other 1-10 spaces, cut expansion depth 3 to 1; added doc text for "Performance"; changed examples to 10, 14, 15, 25; +"Category:Wikipedia formatting and function templates") |
||
Line 4: | Line 4: | ||
-============================================================ |
-============================================================ |
||
- (see NOTES below) |
- (see NOTES below) |
||
-- |
|||
--></noinclude><includeonly>{{ |
|||
-------------------------------------------------------- |
|||
#switch: {{{1|5}}}<!--parameter 1 is space-count --> |
|||
-- put 10 spaces for each ten above 10, 20, 30, etc. |
|||
-- |
|||
--></noinclude>{{ |
|||
#ifexpr: {{{1|5}}} > 10 |
|||
| }}{{ |
|||
#ifexpr: {{{1|5}}} > 20 |
|||
| }}{{ |
|||
#ifexpr: {{{1|5}}} > 30 |
|||
| }}{{ |
|||
#ifexpr: {{{1|5}}} > 40 |
|||
| }}{{ |
|||
#switch: {{#expr:{{{1|5}}}-floor({{{1|5}}}/10)*10 }} |
|||
| 1 = |
| 1 = |
||
| 2 = |
| 2 = |
||
Line 15: | Line 27: | ||
| 8 = |
| 8 = |
||
| 9 = |
| 9 = |
||
| |
| 0 = |
||
}}<noinclude><!-- |
|||
-->}}<!--endswitch on 1-->{{ |
|||
---------------------------------------- Error message if >50 |
|||
#ifexpr:{{{1|5}}} > 10 | {{ |
|||
--></noinclude>{{#ifexpr:{{{1|5}}}>50 |
|||
|<br>'''[[Template:in5]]''' - count must be 1-50 spaces,<!-- |
|||
| 1 = |
|||
--> found: {{{1|0}}}.<br> |
|||
| 2 = |
|||
}}<noinclude><!--endif >50 --> |
|||
| 3 = |
|||
<br>The indenter '''Template:in5''' indents text by 5 spaces or |
|||
| 4 = |
|||
| 5 = |
|||
| 6 = |
|||
| 7 = |
|||
| 8 = |
|||
| 9 = |
|||
| <!--other-10--> <!-- |
|||
-->}}<!--endswitch on {1}-10 |
|||
-->}}<!--endifexpr {1}>10 -->{{ |
|||
#ifexpr:{{{1|5}}} > 20 | {{ |
|||
#switch: {{#expr:{{{1|5}}}-20}}<!--parameter 1 is count--> |
|||
| 1 = |
|||
| 2 = |
|||
| 3 = |
|||
| 4 = |
|||
| 5 = |
|||
| 6 = |
|||
| 7 = |
|||
| 8 = |
|||
| 9 = |
|||
| <!--other-10--> <!-- |
|||
-->}}<!--endswitch on {1}-20 |
|||
-->}}<!--endifexpr {1} > 20 -->{{ |
|||
#ifexpr:{{{1|5}}} > 30 | {{ |
|||
#switch: {{#expr:{{{1|5}}}-30}}<!--parameter 1 is count--> |
|||
| 1 = |
|||
| 2 = |
|||
| 3 = |
|||
| 4 = |
|||
| 5 = |
|||
| 6 = |
|||
| 7 = |
|||
| 8 = |
|||
| 9 = |
|||
| <!--other-10--> <!-- |
|||
-->}}<!--endswitch on {1}-30 |
|||
-->}}<!--endifexpr {1} > 30 -->{{ |
|||
#ifexpr:{{{1|5}}} > 40 | {{ |
|||
#switch: {{#expr:{{{1|5}}}-40}}<!--parameter 1 is count--> |
|||
| 1 = |
|||
| 2 = |
|||
| 3 = |
|||
| 4 = |
|||
| 5 = |
|||
| 6 = |
|||
| 7 = |
|||
| 8 = |
|||
| 9 = |
|||
| 10 = |
|||
|<!--other-none-->{{#ifexpr:{{{1|5}}}>50|<!--then |
|||
--><br>'''Template:in5''' - count must be 1-50 spaces,<!-- |
|||
--> found: {{{1|5}}}.<br>|<!--else-ok-->}}<!--endif |
|||
-->}}<!--endswitch on {1}-40 -- |
|||
-->}}<!--endifexpr {1}>40 -- |
|||
--></includeonly><noinclude><!-- |
|||
-->The indenter '''Template:in5''' indents text by 5 spaces or |
|||
the count specified by<br>parameter 1 (range: 1 to 50 spaces). |
the count specified by<br>parameter 1 (range: 1 to 50 spaces). |
||
<br><br> |
<br><br> |
||
Line 101: | Line 58: | ||
==Comparison with Template:spaces== |
==Comparison with Template:spaces== |
||
There are other templates that insert spaces, although none had allowed 50 spaces. For example, the [[Template:spaces]] has had a limit of about 15 spaces: |
There are other templates that insert spaces, although none had allowed 50 spaces. For example, the [[Template:spaces]] has had a limit of about 15 spaces (during 2009-2010): |
||
{| class=wikitable style="margin-left:40px" |
{| class=wikitable style="margin-left:40px" |
||
| valign=top | Example of <nowiki>{{spaces|10}}</nowiki><br>and...<br>with <nowiki>{{spaces| |
| valign=top | Example of <nowiki>{{spaces|10}}</nowiki><br>and...<br>with <nowiki>{{spaces|14}}</nowiki><br>with <nowiki>{{spaces|15}}</nowiki><br>with <nowiki>{{spaces|25}}</nowiki> || <nowiki>xx{{spaces|10}}</nowiki>yy, produces:<br>xx{{spaces|10}}yy<br>xx{{spaces|14}}yy<br>xx{{spaces|15}}yy<br>xx{{spaces|25}}yy |
||
|- |
|- |
||
| valign=top | Example of <nowiki>{{in5|10}}</nowiki><br>and...<br>with <nowiki>{{in5| |
| valign=top | Example of <nowiki>{{in5|10}}</nowiki><br>and...<br>with <nowiki>{{in5|14}}</nowiki><br>with <nowiki>{{in5|15}}</nowiki><br>with <nowiki>{{in5|25}}</nowiki><br>with <nowiki>{{in5|45}}</nowiki> || <nowiki>xx{{in5|10}}</nowiki>yy, produces:<br>xx{{in5|10}}yy<br>xx{{in5|14}}yy<br>xx{{in5|15}}yy<br>xx{{in5|25}}yy<br>xx{{in5|45}}yy |
||
|} |
|} |
||
Again, using {<font/>{in5}} reliably allows up to 50 spaces at a time. |
Again, using {<font/>{in5}} reliably allows up to 50 spaces at a time. |
||
==Performance== |
|||
Template {in5} generates a mix of &nbsp; and spaces to avoid the space compression done by the [[MediaWiki]] parser. Each   is stored inside the formatted page (such as seen by the browser option: <View><Source>). The output is optimized to be the shortest possible markup language for spaces, in a variety of different browsers. |
|||
Typically, {in5} runs much faster than [[Template:spaces]], generating 1/3 the markup per use (as 72% less text, over 50 fewer characters each time). Also, {in5} allows 50 spaces, whereas {spaces} has been limited to 15 spaces during 2009-2010. |
|||
==See also== |
==See also== |
||
Line 120: | Line 82: | ||
-- to handle each 10 spaces, as: {{in5|{{{1}}}-10}}; |
-- to handle each 10 spaces, as: {{in5|{{{1}}}-10}}; |
||
-- however, that could become dangerous if the template |
-- however, that could become dangerous if the template |
||
-- were edited by |
-- were edited by novices unaware of recursion dangers. |
||
-- |
|||
-- NOTE E2: To improve efficiency, the logic was rewritten to |
|||
-- output groups of 10 spaces, followed by 1-10 for the |
|||
-- remaining spaces of n - floor(n/10)*10. There were |
|||
-- several improvements (18Dec2010): |
|||
-- * The expansion nesting was reduced from 4 levels to 2. |
|||
-- * The if-logic was reduced to 6 steps: 1 switch, not 5. |
|||
-- * The template size was reduced by 60% less coding. |
|||
-- |
|||
-- NOTE N3: The nesting level of this template is only 2 levels |
|||
-- deep of the MediaWiki "expansion depth limit" (was 40 |
|||
-- levels as the expansion limit during 2008-2010). |
|||
-- |
-- |
||
-------------------------------------------------------------- |
-------------------------------------------------------------- |
||
Line 130: | Line 104: | ||
-- 25Sep09 Fixed/removed 2 sets of "{{" 20min after update. |
-- 25Sep09 Fixed/removed 2 sets of "{{" 20min after update. |
||
-- 31Oct09 Put "Comparison" showing limit as {{spaces|15}}. |
-- 31Oct09 Put "Comparison" showing limit as {{spaces|15}}. |
||
-- 18Dec10 Rewrote as 4 groups of 10 spaces & switch 1-10. |
|||
-- |
|||
-- 18Dec10 Rewrote as +1 level of "expansion limit" (was +3). |
|||
-- 18Dec10 Added "Performance" description to doc text. |
|||
--> |
--> |
||
<!--[[Category:Smart formatting templates|In5]]--> |
<!--[[Category:Smart formatting templates|In5]]--> |
||
[[Category:Wikipedia formatting and function templates|In5]] |
|||
[[vi:Bản mẫu:In5]] |
[[vi:Bản mẫu:In5]] |
||
</noinclude> |
</noinclude> |
Revision as of 16:32, 18 December 2010
The indenter Template:in5 indents text by 5 spaces or
the count specified by
parameter 1 (range: 1 to 50 spaces).
- Usage: {{in5}} <--indents by 5 spaces
- Usage: {{in5|8}} <--indents by 8 spaces
- Usage: {{in5|47}} <--indents by 47
- Usage: {{in5}} <--indents by 5 spaces
Spaces outside the double braces will add an extra space on either
side,
such as the 12 spaces inserted by: " {{in5|10}} ".
NOTE: The name "in5" was chosen because other names were debated, such as
the name "in" being redefined as 6 different uses.
Examples
The following are examples showing larger amounts of spacing:
- Example 1: xx{{in5|10}}yy{{in5|10}}zz, produces: xx yy zz
- Example 2: xx{{in5|10}}yy{{in5|15}}zz, produces: xx yy zz
- Example 3: aa{{in5|20}}bb{{in5|20}}cc, produces: aa bb cc
- Example 4: "32.0{{in5|7}}" produces: "32.0 "
The example 4 shows the ability to put trailing spaces, such as spaces after a number in a wikitable column (coded as: | 32.0{{in5}} ). Typical numbers (with "align=right"), in a table column, often appear crowded at the right-hand side, so appending "{{in5}}" can improve readability, in tables with lines between columns.
Universal template
This Template:in5 is intended as a universal template, with the same name on all Wikipedia sites. The name "in5" with the digit "5" is unlikely to conflict with other-language Wikipedias. Care must be taken not to name a universal template with a name that would be an awkward or peculiar word in the other languages. However, in some cases, a universal template might need a different name in a few conflicting languages.
Comparison with Template:spaces
There are other templates that insert spaces, although none had allowed 50 spaces. For example, the Template:spaces has had a limit of about 15 spaces (during 2009-2010):
Example of {{spaces|10}} and... with {{spaces|14}} with {{spaces|15}} with {{spaces|25}} |
xx{{spaces|10}}yy, produces: xxTemplate:Spacesyy xxTemplate:Spacesyy xxTemplate:Spacesyy xxTemplate:Spacesyy |
Example of {{in5|10}} and... with {{in5|14}} with {{in5|15}} with {{in5|25}} with {{in5|45}} |
xx{{in5|10}}yy, produces: xx yy xx yy xx yy xx yy xx yy |
Again, using {{in5}} reliably allows up to 50 spaces at a time.
Performance
Template {in5} generates a mix of and spaces to avoid the space compression done by the MediaWiki parser. Each   is stored inside the formatted page (such as seen by the browser option: <View><Source>). The output is optimized to be the shortest possible markup language for spaces, in a variety of different browsers.
Typically, {in5} runs much faster than Template:spaces, generating 1/3 the markup per use (as 72% less text, over 50 fewer characters each time). Also, {in5} allows 50 spaces, whereas {spaces} has been limited to 15 spaces during 2009-2010.
See also
- Template:indent - forces newline break before indenting