-- Implement .
local _precision = require('Module:Math')._precisionlocal function precision(text) -- Input like 'Jan precipitation inch = trace' calls this with text = 'trace' -- which would cause _precision to throw an error since it is not numeric. -- Workaround: Return 0 as the precision if an error occurs. local success, result = pcall(_precision, text) if success then return result end return 0end
local function stripToNil(text) -- If text is a non-empty string, return its trimmed content. -- Otherwise, return nothing (text is an empty string or is not a string). if type(text)
local function isAny(args, suffix) local months = for _, month in ipairs(months) do if stripToNil(args[month .. suffix]) then return true end endend
local function makeLabel(args, options, is_first, base, what) local first if isAny(args, ' ' .. what .. ' cm') then first = 'cm' elseif isAny(args, ' ' .. what .. ' mm') then first = 'mm' else first = (what:sub(1, 4)
local function makeSources(frame, args) local source1 = stripToNil(args.source) or stripToNil(args['source 1']) local source2 = stripToNil(args['source 2']) or stripToNil(args['source2']) local result = '|-\n|colspan="14" style="text-align:center;font-size:95%;"|' local text if source1 or source2 then if source1 and source2 then text = 'Source 1: ' .. source1 .. '\n' .. result .. 'Source 2: ' .. source2 else text = 'Source: ' .. (source1 and source1 or source2) end else text = frame:expandTemplate end return result .. text .. '\n|}'end
local function wantSingle(parm) -------------------------------------------------------------------------------- -- Result before July 2022 for single_line setting: -- blank/omitted : separate table rows for metric and imperial (two rows) -- N : bug: only one row with either metric or imperial (not both) -- but heading like "cm (inches)" -- Y/junk : single row with both metric/imperial in same cell -------------------------------------------------------------------------------- -- Intend changing in July 2022 so single_line=Y is the default and -- need single_line=N for separate lines. -- However, this release (1 July 2022) keeps blank/omitted as meaning "no" -- so the other large changes can be tested before switching the default. parm = (parm or ):lower return not (parm
'n' or parm
local function getDefinitions(frame, args, options) -- Return a list of tables or strings that define each row. local function _if(parm, a, b) return stripToNil(args[parm]) and a or b or end local function _ifset(parm, a) return stripToNil(args[parm]) and args[parm] or a end local function _ifany(suffix) return isAny(args, suffix) end local function _ifSingle(a, b) return options.wantSingleLine and a or b or end local function _colorscheme(what, default) return stripToNil(args[what .. ' colour']) or stripToNil(args[what .. ' color']) or default end local function _margin if stripToNil(args.margin) then return 'margin:' .. args.margin .. ';' end return end local location = _if('location', args.location, '') -- show "" to alert editor if parameter is blank local navbarText if not stripToNil(args.open) then if stripToNil(args.name) then local navbar = require('Module:Navbar')._navbar navbarText = navbar end end return