Module:Scale

local data = require('Module:Scale/Data')

local std = require('Module:std') local table = require('Module:std/table') local fp = require('Module:std/functional') local getArgs = require('Module:Arguments').getArgs local fileLink = require('Module:File link')._main local wikitable = require('Module:Wikitable')

local function validate(system) local validSystems = std.tostring(table.keys(data.notes)) if(system == nil or system == '') then error('No system provided. Must be one of: ' .. validSystems) end if(data.notes[system] == nil) then error('Invalid system "' .. system .. '". Must be one of: ' .. validSystems) end end

local function symbolToNote(system) return function(symbol) local result = data.notes[system][symbol] if(result == nil) then local validNotes = std.tostring(table.keys(data.notes[system])) error('Invalid symbol "' .. symbol .. '". Valid symbols for ' .. system .. ' are ' .. validNotes) end return result end end

local function addFileLink(note) n = mw.clone(note) n.file= fileLink{ file= note.file, link= '', size= '12px', }   return n end

local function noteToPositionedElement(system) local numPositions = table.size(data.notes[system]) return function(note) local position = data.relativePositions[numPositions][note.position] return mw.html.create('span') :css({               position= 'relative',                top= position .. 'px',            }) :wikitext(note.file, ' ') end end

local function symbolToPositionedElement(system) return fp.compose(       symbolToNote(system),        addFileLink,        noteToPositionedElement(system)    ) end

local function makeDiv(noteElems) local div = mw.html.create('div') :css({           display= 'inline-block',            ['line-height']= '28px',        }) for _, elem in ipairs(noteElems) do       div:node(elem) end return div end

- -- MAIN -

local function _main(args) local system = args[1] validate(system) local noteSymbols = mw.text.split(args[2], '') local notes = fp.map(symbolToPositionedElement(system), noteSymbols) return makeDiv(notes) end

local function main(frame) return _main(getArgs(frame)) end - -- EXPORTS - return { main= main, _main= _main, documentation= function local tableData = fp.map(function(systemNotes)   		local system = systemNotes[1]    		local listOfRows = fp.map(function(note) return { note[1], -- Note symbol (e.g. >) tostring(_main{system, note[1]}), -- Rendered note 'File:'..note[2].file..'', --image link }			end, table.enpair(systemNotes[2]))   		return {    			system, -- A system, e.g. N64 (a tab in the table)    			{    				{'Note', 'Result', 'Image'}, --Header row					table.unpack(listOfRows)				}			}		end, table.enpair(data.notes)) return wikitable.create3DTable{tables=tableData, headerColumn=true} end }