Difference between revisions of "Template:Color Icons"

From mtgpq wiki
Jump to: navigation, search
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude>
 
<noinclude>
 
==Usage==
 
==Usage==
Replace a string representing one or more colours with a series of icons.
+
Given a string of 1 to 5 letters representing colors, produces a corresponding series of space-separated color icons.
 +
 
 +
The first parameter is a sequence of upper-case letters from the set WUBRGCL.
 +
 
 +
The second parameter (optional) is the size of the icons (default = 14).
 +
 
 +
The third parameter (optional) is a wiki link for each icon (default: Mana).
 +
 
 +
The fourth parameter (optional) is hover text for each icon (default: the full name of the color).
 +
 
 +
The named "sep" parameter (optional) is the separator between icons.  (Default: '')
 +
 
 +
The named "noinline" parameter (optional) is a flag which skips inlining on the color icons if present.  (Default: '')
 +
 
 +
The named "skipnowrap" parameter (optional) is a flag which skips the nowrap action on the color icons if present. (Default: '')
  
The template parameter is a sequence of upper-case letters from the set WUBRGCL.
 
  
 
==Example==
 
==Example==
 
The following mark-up:
 
The following mark-up:
 
<pre><nowiki>
 
<pre><nowiki>
{{Color Icons|UBR}}
+
{{Color Icons|UBR}
 +
{{Color Icons|UBR|24|sep=&amp;thinsp;}}
 
</nowiki></pre>
 
</nowiki></pre>
  
Line 14: Line 28:
  
 
{{Color Icons|UBR}}
 
{{Color Icons|UBR}}
 +
 +
{{Color Icons|UBR|24|sep=&thinsp;}}
 +
 +
== Implementation details ==
 +
The following optimisations are applied to reduce output html size:
 +
* Apply the inline span to the whole set of icons rather than each icon individually
 +
* Skip the "nowrap" span if a single icon is produced
 +
 +
These optimisations are necessary to avoid a "Pages where template include size is exceeded" error on some large pages (e.g. elite pack contents pages).
  
 
[[Category:Symbol templates]]
 
[[Category:Symbol templates]]
  
</noinclude><includeonly>{{nowrap|{{replace|{{replace|{{replace|{{replace|{{replace|{{replace|{{replace|
+
</noinclude><includeonly>{{#ifeq:{{#invoke:String|sub|{{{1}}}|1|1}}|[||<!--
{{{1}}}
+
-->{{Inline|{{nowrap|<!--
|W|{{W}} }}
+
-->{{Symbol|{{#invoke:String|sub|{{{1}}}|1|1}}|{{{2|14}}}|{{{3|}}}|{{{4|}}}|noinline=1}}<!--
|U|{{U}} }}
+
-->{{#ifexpr:{{#invoke:String|len|{{{1}}}}} > 1|{{#if:{{{3|}}}|[[{{{3}}}|{{#if:{{{4|}}}|<span title="{{{4|}}}">{{{sep|}}}</span>|{{{sep|}}}}}]]|{{{sep|}}}}}<!--
|B|{{B}} }}
+
-->{{Symbol|{{#invoke:String|sub|{{{1}}}|2|2}}|{{{2|14}}}|{{{3|}}}|{{{4|}}}|noinline=1}}}}<!--
|R|{{R}} }}
+
-->{{#ifexpr:{{#invoke:String|len|{{{1}}}}} > 2|{{#if:{{{3|}}}|[[{{{3}}}|{{#if:{{{4|}}}|<span title="{{{4|}}}">{{{sep|}}}</span>|{{{sep|}}}}}]]|{{{sep|}}}}}<!--
|G|{{G}} }}
+
-->{{Symbol|{{#invoke:String|sub|{{{1}}}|3|3}}|{{{2|14}}}|{{{3|}}}|{{{4|}}}|noinline=1}}}}<!--
|C|{{C}} }}
+
-->{{#ifexpr:{{#invoke:String|len|{{{1}}}}} > 3|{{#if:{{{3|}}}|[[{{{3}}}|{{#if:{{{4|}}}|<span title="{{{4|}}}">{{{sep|}}}</span>|{{{sep|}}}}}]]|{{{sep|}}}}}<!--
|L|{{L}} }}
+
-->{{Symbol|{{#invoke:String|sub|{{{1}}}|4|4}}|{{{2|14}}}|{{{3|}}}|{{{4|}}}|noinline=1}}}}<!--
}}</includeonly>
+
-->{{#ifexpr:{{#invoke:String|len|{{{1}}}}} > 4|{{#if:{{{3|}}}|[[{{{3}}}|{{#if:{{{4|}}}|<span title="{{{4|}}}">{{{sep|}}}</span>|{{{sep|}}}}}]]|{{{sep|}}}}}<!--
 +
-->{{Symbol|{{#invoke:String|sub|{{{1}}}|5|5}}|{{{2|14}}}|{{{3|}}}|{{{4|}}}|noinline=1}}}}<!--
 +
-->|{{#ifeq:{{#invoke:String|len|{{{1}}}}}|1|1}}{{{skipnowrap|}}}}}|{{{noinline|}}}}}}}</includeonly>

Latest revision as of 10:22, 13 May 2020

Usage

Given a string of 1 to 5 letters representing colors, produces a corresponding series of space-separated color icons.

The first parameter is a sequence of upper-case letters from the set WUBRGCL.

The second parameter (optional) is the size of the icons (default = 14).

The third parameter (optional) is a wiki link for each icon (default: Mana).

The fourth parameter (optional) is hover text for each icon (default: the full name of the color).

The named "sep" parameter (optional) is the separator between icons. (Default: )

The named "noinline" parameter (optional) is a flag which skips inlining on the color icons if present. (Default: )

The named "skipnowrap" parameter (optional) is a flag which skips the nowrap action on the color icons if present. (Default: )


Example

The following mark-up:

{{Color Icons|UBR}
{{Color Icons|UBR|24|sep=&thinsp;}}

Produces:

BlueBlackRed

BlueBlackRed

Implementation details

The following optimisations are applied to reduce output html size:

  • Apply the inline span to the whole set of icons rather than each icon individually
  • Skip the "nowrap" span if a single icon is produced

These optimisations are necessary to avoid a "Pages where template include size is exceeded" error on some large pages (e.g. elite pack contents pages).