Jump to content

Module:Sandbox/isaacl/ExpandPageAbbreviation

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Isaacl (talk | contribs) at 03:02, 28 February 2013 (modify output format). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- For unit tests, see [[Module:Sandbox/isaacl/ExpandPageAbbreviation/tests]]

local moduleSelf = { 
-- mw.loadData() not supported, so do not need to access this module for now
--    mw = require("Module:Mw")
      outputForAbbr = { }
    }

-- mw.loadData() not supported, so use require() in the meantime
-- moduleSelf.phraseForAbbr = moduleSelf.mw.loadData('Module:Sandbox/isaacl/ExpandPageAbbreviation/data')
moduleSelf.phraseForAbbr =require('Module:Sandbox/isaacl/ExpandPageAbbreviation/data')

function moduleSelf._expand(abbr)
    if moduleSelf.phraseForAbbr[abbr] == nil then
        return abbr
    else
        if moduleSelf.outputForAbbr[abbr] ~= nil then
            return moduleSelf.outputForAbbr[abbr]
        else
            moduleSelf.outputForAbbr[abbr] = string.format("%s (%s)",
                moduleSelf.phraseForAbbr[abbr], abbr)
            return moduleSelf.outputForAbbr[abbr]
        end
    end
end  -- function _expand()

function moduleSelf.expand(frame)
    local abbr = frame.args[1]
    return moduleSelf._expand(abbr)
end

return moduleSelf