Module:Scale

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 data = require('Module:Scale/Data')

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, { wrappers= {'Template:Scale', 'Template:Scale/sandbox'} })) end

- -- EXPORTS - return { main=main, _main=_main, }