Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:StrictTemplate

From Net 7 Portal Wiki

Module:StrictTemplate/doc

This module is just an example template for creating modules and implements the template {{StrictTemplate}}, see the documentation there.


The above doc is transcluded from Module:StrictTemplate/doc. (edit | history)
Add categories to the /doc subpage, not here. Subpages of this template.


local getArgs
local yesno = require('Module:Yesno')
local error = require('Module:Vrix').error
require('strict')

--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------

local function _args(frame)
    if not getArgs then
        getArgs = require('Module:Arguments').getArgs
    end
    local args = getArgs(frame, {
        trim = true,
        removeBlanks = true,
        wrappers = {
            -- see for an example of calling this module from a wrapper template
            'Template:StrictTemplate',
        }
    })
    return args
end

--------------------------------------------------------------------------------
-- StrictTemplate class definition
--------------------------------------------------------------------------------

local StrictTemplate = {}
StrictTemplate.__index = StrictTemplate

function StrictTemplate.new(args)
    local obj = {}

    -- code populating obj and ultimately obj.wikitext here
    obj.wikitext="'''hello " .. args.text .. "!'''"

    return setmetatable(obj, StrictTemplate)
end

function StrictTemplate:export()
    return tostring(mw.html.create()
        :wikitext(self.wikitext)
    )
end

--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------

local p, mt = {}, {}

function p._exportClasses()
    -- For testing.
    return {
        StrictTemplate = StrictTemplate
    }
end

function p.main(k, args)
    local strictTemplate = StrictTemplate.new(args)
    return strictTemplate:export()
end

function mt.__index(t, k)
    return function (frame)
        return t.main(k, _args(frame))
    end
end

return setmetatable(p, mt)