Module:London Gazette util
Appearance
Utility module for {{London Gazette}}
row | |display-supp= | |supp= | condition | displayed result | url | comment |
---|---|---|---|---|---|---|
1 | – | – | – | <no supplement display> | /page/ |
most common non-supplement form |
2 | – | y | – | Supplement | /supplement/ |
unnumbered supplement |
3 | – | ## | – | {{{supp}}} <suffix> supplement |
/supplement/ |
specific numbered supplement |
4 | – | <text> | – | invalid |supp= |
/page/ |
invalid or out of range |
5 | none |
y | – | <no supplement display> | /supplement/ |
when page not at /page/ url
|
6 | y | – | – | Supplement | /supplement/ |
when unnumbered supplement not at /supplement/ url
|
7 | ## | – | – | {{{display-supp}}} <suffix> supplement |
/page/ |
when supplement not at /supplement/ url
|
8 | ## | y | – | {{{display-supp}}} <suffix> supplement |
/supplement/ |
specific numbered supplement (similar to 3) |
9 | ## | ## | {{{supp}}} == {{{display-supp}}} |
{{{display-supp}}} <suffix> supplement |
/supplement/ |
|supp= and |display-supp= must agree |
10 | ## | ## | {{{supp}}} != {{{display-supp}}} |
invalid |supp= |
/supplement/ |
ambiguous; which supplement number is correct? |
11 | <text> | – | – | {{{display-supp}}} |
/page/ |
user specified text; not at /supplement/ url
|
12 | <text> | y | – | {{{display-supp}}} |
/supplement/ |
user specified text |
13 | <text> | ## | – | {{{display-supp}}} |
/supplement/ |
user specified text |
14 | <text> | <text> | – | invalid |supp= |
/supplement/ |
|supp= invalid or out of range
|
key | ||||||
– | parameter is empty or missing; a condition does not apply | |||||
## | a number greater than zero and less than 100 | |||||
<suffix> | the appropriate ordinal suffix: 1st, 2nd, 3rd, 4th, ... | |||||
<text> | any characters that are not ## or the letter y (or, for |disp-supp= , not the keyword none )
| |||||
== |
logical equality; the statement A == B is true when A and B hold the same value | |||||
!= |
logical inequality; the statement A != B is true when A and B hold different values |
-- this module is created to support {{London Gazette}}
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local code_style="color:inherit; border:inherit; padding:inherit;";
local supp_error = '<span style="font-size:100%; font-weight:normal" class="error">invalid <code style="'..code_style..'">|supp=</code></span>';
local p = {}
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Whether variable is set or not. A variable is set when it is not nil and not empty.
]]
local function is_set( var )
return not (var == nil or var == '');
end
--[[--------------------------< O R D I N A L >----------------------------------------------------------------
render a numerical text string in ordinal form suitable for English language use. In this module, num_str is
limited by calling functions to the integer values 1-99.
TODO: use Module:Ordinal instead?
]]
local function ordinal (num_str)
if num_str:match ('^1[1-3]$') then -- do the 11-13 odd balls first to get them out of the way
return num_str .. 'th';
elseif '1' == num_str:match ('^%d?(%d)$') then -- 1, 21, 31, 41, ... 91
return num_str .. 'st';
elseif '2' == num_str:match ('^%d?(%d)$') then -- 2, 22, 32, 42, ... 92
return num_str .. 'nd';
elseif '3' == num_str:match ('^%d?(%d)$') then -- 3, 23, 33, 43, ... 93
return num_str .. 'rd';
else
return num_str .. 'th'; -- 4-9, 14-19, ... 94-99
end
end
--[[--------------------------< T Y P E _ P A R A M >----------------------------------------------------------
set the value that is assigned to the cite magazine |type= parameter using the values of the London Gazette
|supp= and |display-supp= parameters
<span style="font-size:100%; font-weight:normal" class="error">Empty name</span>
]]
function p.type_param (frame)
local args = getArgs(frame);
if not is_set (args['display-supp']) and not is_set (args.supp) then -- when both |display-supp= and |supp= are not set
return ''; -- [row 1]
end
if not is_set (args['display-supp']) and is_set (args.supp) then -- when only |supp= is set
if ('y' == args.supp) or ('yes' == args.supp) then
return 'Supplement'; -- [row 2]
elseif args.supp:match ('^%d%d?$') then -- one or two digits
if '1' == args.supp then
return 'Supplement'; -- [row 3]
else
return ordinal (args.supp) .. ' supplement'; -- [row 4]
end
else
return supp_error; -- [row 5] any other text not supported
end
end
if is_set (args['display-supp']) and not is_set (args.supp) then -- when only |display-supp= is set
if args['display-supp']:match ('^%d%d?$') then -- one or two digits
return ordinal (args['display-supp']) .. ' supplement'; -- [row 6]
else
return args['display-supp']; -- [row 10]
end
end
if args['display-supp']:match ('^%d%d?$') then
if ('y' == args.supp) or ('yes' == args.supp) then
return ordinal (args['display-supp']) .. ' supplement'; -- [row 7]
elseif args['display-supp'] == args.supp then
return ordinal (args['display-supp']) .. ' supplement'; -- [row 8]
else -- |supp= is not a number or number doesn't match
return supp_error; -- [row 9]
end
else
if ('y' == args.supp) or ('yes' == args.supp) then
return args['display-supp']; -- [row 11]
else
return supp_error; -- [row ??]
end
end
end
return p;