Module:Road data/strings/doc
![]() | This is a documentation subpage for Module:Road data/strings. It may contain usage information, categories and other content that is not part of the original module page. |
This module is used to store type data for use with several road templates, including {{jct}} and {{routelist row}}. Background information and a summary of the syntax are listed below.
Syntax
Hierarchy and fields
At its most basic level, this module is a nested table of strings. At the top is the root table, usually the abbreviation of a country, state, or province. This table stores the type data for a particular place, which is named in the comment in the first line, and is returned at the end of the module. The table is composed of further tables, one per type. The basic syntax for a type table is:
place.type = {shield = "",
link = "",
abbr = ""}
The three main fields in a type table are shield
, link
, and abbr
. Generally, shield
determines the shield that is displayed, if any; link
specifies the target of the link generated by a including module, if any; and abbr
determines the displayed abbreviation. Currently, these are the three types used by all countries. By convention, they are always specified, using an empty string if there is no value.
Two additional fields are used in the United States. banner
stores the name of the banner file, while width
stores a code representing the width of the shield. Unlike the three main fields, these are generally omitted entirely when unused.
Once a type is defined, it can be referred to later in the code. A common idiom used for bannered types is defining the shield to be the shield field of the base type (from Module:Road data/strings/USA/MO):
MO.US = {shield = "US %route%.svg",
link = "U.S. Route %route% in Missouri",
abbr = "US %route%",
width = "expand"}
MO["US-Alt"] = {shield = MO.US.shield,
link = "U.S. Route %route% Alternate ([dab||%dab%, |]Missouri)",
abbr = "US %route% Alt.",
banner = "Alternate plate.svg",
width = "expand"}
Another common idiom is defining a type alias by setting an entry in the root table equal to a previously defined type (from Module:Road data/strings/HKG):
HKG.Route = {shield = "HK Route%route%.svg",
link = "Route %route% (Hong Kong)",
abbr = "Route %route%"}
HKG.route = HKG.Route
Parser arguments
When the parser function of Module:Road data/parser is called, it is passed up to three parameters. The second one is the field to parse, and the last one is a rarely-used option designed for multiple-shield types. The first and most important parameter is a table of arguments collected by the calling module, which generally includes the state, country, or both; the type and number of the route; and a few miscellaneous arguments. This table of arguments forms the basis of the parser's format string syntax.
The table accessible by the strings includes the following entries by default:
state
: The state or province the route is located in.country
: The country the route is located in. If the country is not passed by the calling module, the parser will attempt to include it.
The above entries are primarily used to find the string module itself, so they should not be a concern for module writers.
type
: The type of the route. This determines the entry of the root table that is used by the parser.route
: The route "number". This is easily the most important argument for module writers.
The following entries are used less often:
county
: The county the route is located in. This is usually used for county routes in the United States.township
: This entry is similar in function and utility to thecounty
entry.dab
: A tag used to disambiguate the link target. This is mostly used for bannered routes in the United States.denom
: This rare entry is used exclusively for West Virginia county routes.
Parser hooks, which will be described later, can add entries to this table that may be used by strings.
Basic string syntax
The most basic value that can be used for most type table fields is a specially formatted string, which will be referred to in this documentation as a format string. This is the string that will ultimately be parsed and returned by the parser. A format string is an ordinary string object. The power of these strings comes in the form of two special instructions that are recognized by the parser.
The first is anything in %argument%
form. The parser will replace such a statement with the value of the argument
entry in the arguments table described earlier. This is what allows the route number to be spliced into a shield or link name.
The second special string is in the form of [arg|equals|then|else]
. This functions as a rudimentary if-then-else statement. The parser tests the value of arg
to see if it is equal to the value specified in equals
. equals
may be empty, in which case the parser tests the existence of the arg
argument. If the result of the test is true, the statement is replaced with the value of the then
block. Otherwise, it is replaced with the value of the else
block.
The two statements may be combined. The parser will parse the if-then-else statement first, and then perform the argument inclusion. This combination is commonly used with bannered routes in the United States, where the dab
argument is tested and the link disambiguation is adjusted accordingly, as follows (from Module:Road data/strings/USA/AL):
AL["US-Bus"] = {shield = "US %route%.svg",
link = "U.S. Route %route% Business ([dab||%dab%, |]Alabama)",
abbr = "US-%route% Bus.",
banner = "Business plate.svg",
width = "expand"}
When parsing the link
field, the parser first checks to see if the dab
argument was provided. If so, it replaces the statement with %dab%,
. If not, the statement is replaced with the empty string placed in the else
block. Then, the parser replaces %route%
with the route number and, if the dab
argument was provided, %dab%
with the value of that argument.