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

Content deleted Content added
Style
Structure
Line 3:
==Syntax==
===Hierarchy and fields===
At its most basic level, this module is a nested table of strings. At the top is the root table, usuallynamed for 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:
 
<source lang="lua">
Line 142:
width = 40}
</source>
 
==Structure==
#Each Startcountry has its own module. In the United States and Canada, each state/territory/province also has its own module. Each module begins with thea comment stating the name of the country or state, followed by the root table declaration, as follows (from [[Module:Road data/strings/USA/AS]]):
<source lang="lua">
-- American Samoa
local AS = {}
</source>
 
The root table is named based on the established abbreviation for the country or state, which is the same as the abbreviation used in the module title. This table stores the various types used in that particular place. Most of the remaining code in the module defines these various types. The module ends by returning the root table:
<source lang="lua">
return AS
</source>
 
===Aliasing===
There are two ways to define a type as an alias. If the type is defined within the module, simply set the new type as equal to the type being aliased, as shown above (from [[Module:Road data/strings/HKG]]):
<source lang="lua">
HKG.Route = {shield = "HK Route%route%.svg",
link = "Route %route% (Hong Kong)",
abbr = "Route&nbsp;%route%"}
HKG.route = HKG.Route
</source>
 
If the type is defined in a separate module, such as a state highway type being used in another state's module, a special syntax may be used to refer to that module (from [[Module:Road data/strings/USA/NJ]]):
<source lang="lua">
NJ.NY = {alias = {module = "USA/NY", type = "NY"}}
</source>
 
This code sets the <code>NY</code> type as a link to the <code>NY</code> type in [[Module:Road data/strings/USA/NY]]. The parser will import that module and process the type as if the original module had declared it itself. The alias declaration may not add or override any data in the type table it points to.
 
==Style==
There are a few style guidelines that should be followed:
# Align table fields using spaces. All tables should be aligned so that fields line up with each other, as shown in the above examples.
# Do not endplace tablesa table's closing brace on a separate linesline.
# Each table field should be on its own line.
# Add spaces to either side of an assignment operator (equals sign).
# Leave a blank line between types. Type aliases should be set off from their base type by a blank line, but no blank lines should be placed between the aliases themselves.
# Start each module with the comment stating the name of the country or state, followed by the root table declaration, as follows (from [[Module:Road data/strings/USA/AS]]):
<source lang="lua">
-- American Samoa
local AS = {}
</source>