Module:Road data/parser/hooks/doc
Hetta er kunningarsíðan viðvíkjandi Module:Road data/parser/hooks
This module includes hook functions that provide extra functionality to Module:Road data/parser and its associated string modules.
Basics
[rætta wikitekst]Each hook is simply a function stored in the p
package table exported by this module. Each function accepts two arguments:
parameters
: The table in the string module that references the hook. In this example, this argument would be the table stored in theshield
field of the type table (from Module:Road data/strings/USA/KY):
KY["KY 1966"] = {shield = {hook = "split",
split = 100,
below = "Elongated circle %route%.svg",
above = "Circle sign %route%.svg"},
link = KY.KY.link,
abbr = KY.KY.abbr}
args
: The arguments originally passed to the parser.
Hooks may modify the argument table by simply setting a new key as equal to a computed value. Modifying existing values is allowed, but discouraged.
The return value of a hook is an ordinary format string, which may be computed within the function or pulled from the parameters
argument. Generally, if the hook does not compute the format string to be returned, the hook should return parameters.default
, which should equal a format string.
Hooks
[rætta wikitekst]split
[rætta wikitekst]This hook determines the format string to be used by the parser based on whether the route number is above or below a particular number.
Parameters:
split
: The number on which to split.below
: The format string to use if the route number is belowsplit
.above
: The format string to use if the route number is equal to or abovesplit
.
splitlen
[rætta wikitekst]This hook operates in a similar fashion to split
, but tests the length of the route number instead of its value.
Parameters:
split
: The length on which to split.below
: The format string to use if the route number's length is belowsplit
.above
: The format string to use if the route number's length is equal to or abovesplit
.
between
[rætta wikitekst]This hook determines the format string to be used by the parser based on whether the route number is between two given numbers.
Parameters:
lower
: The lower limit of the test (inclusive).upper
: The upper limit of the test (exclusive).yes
: The format string to use if the route number is betweenlower
andupper
.no
: The format string to use if the route number is not betweenlower
andupper
.
mask
[rætta wikitekst]This hook adds an argument to the args
table based on the result of applying a supplied mask to a particular argument.
Parameters:
base
: The argument to be masked.masked
: The key used to store the mask result in theargs
table.mask
: The name of the module to be used as a mask, without the "Module:" prefix. The module must return a table which maps abase
argument to the value stored in themasked
field ofargs
.default
: The format string to be processed by the parser. This string may reference the argument stored inargs
by this hook.
padroute
[rætta wikitekst]This hook zero-pads the route number so that the route number has a particular number of digits.
Parameters:
paddedLength
: The length to which the route number should be zero-padded.default
: The format string to be processed by the parser. This string may reference the zero-padded route number as thepaddedRoute
argument.
lowercase
[rætta wikitekst]This hook converts the route "number" to lowercase.
Parameters:
default
: The format string to be processed by the parser. This string may reference the lowercased route number as thelowercase
argument.