Module:Color2dec/doc

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

This is the documentation page for Module:Color2dec

Written a bit complicated, due to my poor LUA knowledge.

This module contains global functions, some functions which can be used either globally or locally, and local functions.

Function "convert"

[edit]

Converts a hexadecimal string (#rrggbb or #rgb) to a table of three decimal values (previosly: dec·hex function of D2x).

Function "tincture"

[edit]

Used also globally by template Igen/cbox
Converts the standard tinctures names to their hexadecimal color codes;
Color codes of six hexadecimal numbers #aabbcc are shortened to #ABC when possible (previosly: template D2s).
When the first two characters are 1) 2) 3) (for striping) they are removed.

when tincture comparison is not successful, the conversion of CSS names is tried;
other values are passed without check as-they-are, which may cause an error

Function "decode"

[edit]

Used also globally by template Igen/cbox and by other templates (same code as in modules Char and Igenmod)
Avoids the wiki problem with # * : ; at the first position

Function "tindec"

[edit]

Returns the hexdecimal color code for a color name

Function "stripe"

[edit]

Returns the stripe code for a legend

Function "remprf"

[edit]

Can remove special 2-byte-prefixes:

  • pairs as (), <>, [], {}
  • doubles ((, <<, &&, .. but of course not [[ and {{

or change a leading understroke to a leading space.

Function "rem2bp"

[edit]

Removes the 2-byte-prefix


      • Global functions:

Global function "tbcgen"

[edit]

"tbcgen" calls the template Tbc with the 5 parameters needed by that template;
accepts & needs two parameters, a color code and a descriptive text:

  • the color code may be a valid hexadecimal color triplet, as e.g."#ABCDEF" or "#80c";
    otherwise it is treated with the local/global function "tincture";
it may also be a valid tincture name, e.g. "céleste" (see examples)
from the many other color names just the set of the 148 CSS names is valid for conversion;
when a string not starting with "#" cannot find its hexadecimal representation, an error is raised.
  • when the descriptive text starts with "#" the local/global function "decode" replaces it
    by &#35;, its decimal numeric character reference.

Global function "cstring"

[edit]

Global init for e.g. {{ColorString}}, can split slash-separated params

Global function "colorts"

[edit]

Testfunction for drawing boxes with the calculated contrast color,
showing them at Category talk:Colorbox formatting templates; with all the colors like at Template talk:ColorString.

Global function "count"

[edit]

Returns the count of the occurrences of pattern (param. 2, default: " ") in a string (param. 1, default: "")

Also: function leftp, rigtp

Global function "colortab"

[edit]

Generates a 16 × 16 × 16 table, shown at Module talk:Color2dec