Content deleted Content added
m source → syntaxhighlight |
→Hierarchy and fields: expand with more common information |
||
Line 7:
<syntaxhighlight lang="lua">
place.type = {shield = "",
name = "",
link = "",
abbr = ""}
</syntaxhighlight>
The
*<code>shield</code> determines the shield that is displayed, if any
*<code>name</code> specifies the name of the route displayed by an infobox
*<code>link</code> specifies the target of a link generated, if any
*<code>abbr</code> determines the displayed abbreviation.
====Other types====
*<code>shieldmain</code> is used when a different shield is desired at the top of an infobox, such as for county roads.
<syntaxhighlight lang="lua">
USA.CR = {
shield = "CR %route% jct.svg",
shieldmain = "[county||%county% |]County %route%.svg",
name = "County Road %route%",
link = "",
abbr = "CR %route%"
}
</syntaxhighlight>
*<code>base</code> can be used for aliasing different types that have a similar base structure, such as U.S. Highway special routes.
*<code>banner</code> stores the name of the banner file, such as <code>[[:File:Business plate.svg|Business plate.svg]]</code>. Can be omitted when unused.
*<code>width</code> stores a code representing the width of the shield. It is most often helpful when used with <code>banner</code>. Can be omitted entirely when unused. Common values are <code>square</code> and <code>expand</code>.
Once a type is defined, it can be referred to later in the code. As seen here, it is common to define all parameters for main types like <code>US</code> and then to use aliases for subtypes such as <code>US-Alt</code>.
<syntaxhighlight lang="lua">
MO.US = {shield = "US %route%.svg",
base = "U.S. Route %route%",
link = "U.S. Route %route% in Missouri",
abbr = "US %route%",
Line 23 ⟶ 47:
MO["US-Alt"] = {shield = MO.US.shield,
link =
abbr =
banner = "Alternate plate.svg",
width = "expand"}
</syntaxhighlight>
<syntaxhighlight lang="lua">
HKG.Route = {shield = "HK Route%route%.svg",
Line 36 ⟶ 60:
HKG.route = HKG.Route
</syntaxhighlight>
====Inheriting types====
It is possible to predefine several types for a ___location by inheriting them from another module. In this example, the module for Albania inherits all of the specified types from the Europe module.
<syntaxhighlight lang="lua">
-- Albania
local ALB = {}
local util = require("Module:Road data/util")
util.addAll(ALB, require("Module:Road data/strings/EUR"))
</syntaxhighlight>
{{n.b.}} Only one module may be inherited at this time. <!-- if they don't intersect it might not be true -->
====Advanced uses====
It is possible to create multiple types based on a specified pattern using <code>ipairs</code>. In this example from [[Module:Road data/strings/USA/WA]], the <code>US 1926</code>, <code>US 1948</code>, and <code>US 1961</code> types are all created from the same code. At the bottom that is an override for <code>US 1961</code>'s <code>shieldmain</code>.
<syntaxhighlight lang="lua">
for _,year in ipairs({"1926", "1948", "1961"}) do
WA["US " .. year] = {
shield = format("US %%route%% (%s).svg", year),
shieldmain = format("US %%route%% Washington %s.svg", year),
base = WA.US.base,
name = WA.US.name,
link = WA.US.link,
abbr = WA.US.abbr,
width = "square",
}
end
WA["US 1961"].shieldmain = "US %route% (1961).svg"
</syntaxhighlight>
Similarly, subtypes can be created in the same manner. This example creates 9 subtypes each for <code>WA</code> and <code>SR</code>. The <code>aux</code> is inherited from [[Module:Road data/strings/USA]]. That, in turn, modifies <code>auxType</code> and <code>spec</code> accordingly.
<syntaxhighlight lang="lua">
for _,type in ipairs({'WA', 'SR'}) do
for _,auxType in ipairs({"Alt", "Bus", "Byp", "Conn", "Opt", "Scenic", "Spur", "Temp", "Truck"}) do
local spec = WA[" aux "][auxType]
WA[type .. "-" .. auxType] = {
shield = WA[type].shield,
shieldmain = WA[type].shieldmain,
name = WA[type].name .. " " .. spec.name,
link = WA[type].link .. " " .. spec.name .. suffix,
abbr = WA[type].abbr .. " " .. spec.abbrsuffix,
banner = spec.bannerprefix .. " plate.svg",
aux = spec.aux,
width = WA[type].width
}
end
end
</syntaxhighlight>
|