Module:Road data/strings/doc: Difference between revisions

Content deleted Content added
Continuing
Mostly finished
Line 112:
link = "",
abbr = "B%route%"}
</source>
 
===Hooks===
Due to technical limitations, these string modules cannot contain functions. Rather than force functionality into the string framework, the parser can call functions in a separate hooks module. The functions in this module, [[Module:Road data/parser/hooks]], are more-or-less fully functional functions. The exact functionalities of these hooks are beyond the scope of this documentation. Descriptions of these hooks may be found on their documentation page.
 
Generally speaking, a hook is called by setting the <code>hook</code> field in a table as equal to the name of a hook. Hooks receive two arguments, both tables: <code>parameters</code>, which is the table in the definition; and <code>args</code>, which is simply the table of arguments normally passed to the parser. The hook returns a string, which is then parsed as usual. A powerful feature of hooks is that they can add arbitrary values to the argument table, which may be referenced in the string returned by the hook. Generally, the format string returned by the hook is specified in some form by the <code>default</code> field of the table, though there are exceptions. Here is an example of a hook (from [[Module:Road data/strings/MEX]]):
<source lang="lua">
MEX.SH = {shield = {ifexists = true,
arg = "state",
SON = "HIGHWAYSON %route%.jpg",
NLE = "Nuevo Leon State Highway %route%.PNG",
default = ""},
link = {hook = "mask",
mask = "Road data/masks/MEX",
base = "state",
masked = "fullstate",
default = "%fullstate% State Highway %route%"},
abbr = "SH&nbsp;%route%"}
</source>
 
In this example, the parser will process the link by calling the <code>mask</code> hook. In short, this hook takes the argument referenced in <code>base</code>, passes it through the mask module specified in <code>mask</code>, and stores it in the field in the arguments noted in <code>masked</code>. The hook returns the string given in <code>default</code>, which has access to the <code>fullstate</code> argument added by the hook.
 
===Other functionality===
Functionality exists to display multiple shields for one route, which is used to display tolled and free shields for routes where they differ. This is done by supplying a table with two values, which are listed without indices. The parser is called twice by the calling module, and it returns one shield per call. An example may be found in [[Module:Road data/strings/USA/TX|Texas]]:
<source lang="lua">
TX.Both = {shield = {"Texas %route%.svg", "Toll Texas %route% new.svg"},
link = "Texas State Highway %route%",
abbr = "SH&nbsp;%route%",
width = 40}
</source>