Module:Convert/show explained

-- Prepare tables of wikitext to display simple documentation about-- specified units. Data is obtained by calling Module:Convert.-- Also provides a function to show convert usage examples.

local Collection -- a table to hold itemsCollection = Collection.__index = Collection

local function strip(text) -- Return text with no leading/trailing whitespace. return text:match("^%s*(.-)%s*$")end

local function fakeFrame(selfArgs, parentArgs) -- Simulate enough of a MediaWiki module frame for convert. -- This is a cheap way to call convert with specified arguments. return end

local cvtFunctionlocal function callConvert(args) if not cvtFunction then cvtFunction = require('Module:Convert').convert end return cvtFunction(fakeFrame(args))end

local function makeTable(frame, results, units) results:add('

Unit code Unit symbol Unit name US name, if different') for i, ucode in ipairs(units) do local row = Collection.new row:add(ucode) local args = row:add(callConvert(args)) args.abbr = 'off' local name1 = callConvert(args) row:add(name1) args.sp = 'us' local name1_us = callConvert(args) if name1_us

name1 then row:add() else row:add(name1_us) end results:add('

-') results:add(strip('' .. row:join(' '))) end results:add('
') results:add()end

-- Commonly used units for main documentation.-- Can only be input units (not combinations or multiples).local commonUnits =

-- Order in which sections are wanted when doing all common units.local commonSections =

local function _showExamples(frame, results, examples, wantTable) local fmt if wantTable then results:add('

%s%s' else fmt = '*%s → %s' end for i, item in ipairs(examples) do if wantTable and i > 1 then results:add('-') end item = item:gsub('!', '') item = '' results:add(fmt:format(mw.text.nowiki(item), frame:preprocess(item))) end if wantTable then results:add('
') endend

local function _showLinks(frame, results, args) local sandbox = args[1]