Module:D'ni Tools

From Guild of Archivists
Revision as of 23:26, 20 July 2016 by BladeLakem (talk | contribs) (Created page with " local p = {} local args = {} local origArgs local output = '' local function parseArg(input) local output = '' local word = mw.text.trim(input) local first...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Documentation for this module may be created at Module:D'ni Tools/doc

 
local p = {}

local args = {}
local origArgs

local output = ''

local function parseArg(input)

    local output = ''

    local word = mw.text.trim(input)
    local first = mw.ustring.sub(word,1,1)
    local last = mw.ustring.sub(word,-1,-1)

    if (word == '') then
        output = ' '
    elseif (first == '-') then
        output = '[[Dictionary:'..mw.ustring.sub(word,2,-1)..'|'..word..']]'
    elseif (last == '-') then
        output = '[[Dictionary:'..mw.ustring.sub(word,1,-2)..'|'..word..']]'
    elseif (first == '.') then
        output = '.[[Dictionary:'..mw.ustring.sub(word,2,-1)..'|'..word..']]'
    else
        output = '[[Dictionary:'..word..']]'
    end

    return output
end

function p.parsed_dni(frame)
    -- If called via #invoke, use the args passed into the invoking template.
    -- Otherwise, for testing purposes, assume args are being passed directly in.
    if frame == mw.getCurrentFrame() then
        origArgs = frame:getParent().args
    else
        origArgs = frame
    end

    for word in pairs(origArgs) do
        output = output..parseArg(word)
    end

    return output
end
 
return p