Module:Dochead: Difference between revisions

Ganaram inukshuk (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
implement headers; no categorizing code yet
Line 2: Line 2:
local getArgs = require("Module:Arguments").getArgs
local getArgs = require("Module:Arguments").getArgs
local ctg    = require("Module:Category handler")._category_handler
local ctg    = require("Module:Category handler")._category_handler
local yesno  = require("Module:Yesno")


local p = {}
local p = {}
Line 20: Line 21:


-- Detect whether a page exists, where pagename is "Namespace:Title"
-- Detect whether a page exists, where pagename is "Namespace:Title"
function p.page_exists(pagename)
function p.page_exists(fullpagename)
local pagename = pagename or "Template:Dochead"
local pagename = pagename or "Template:Dochead"
local title = mw.title.new(pagename)
local title = mw.title.new(pagename)
Line 32: Line 33:


function p._dochead(args)
function p._dochead(args)
local pagename = args["pagename"]
local namespace = args["namespace"]
local header   = args["header"] or "none"
local pagename = args["pagename" ]
local is_metause = args["is_metause"] or false
local header   = args["header"   ] or "none"
local corr_template = args["temp"   ] or "Template:" .. pagename
local corr_module  = args["mod"    ] or "Module"    .. pagename
-- If header is none, don't bother.
if header == "none" then return "" end
local result = ""
if namespace == "Module" then
if p.page_exists(corr_template) then
if header == "dualuse" then
result = string.format("This module may be invoked by templates by using its corresponding [[%s | template]], or used directly from other modules.", corr_template)
elseif header == "metatemplate" then
result = string.format("This module implements a metatemplate, and may be invoked by templates by using its corresponding [[%s | template]], or used directly from other modules.", corr_template)
elseif header == "noinvoke" then
result = string.format("This module should not be invoked directly; use its corresponding [[%s | template]] instead.", corr_template)
else
result = table.concat({header, string.format("This module implements [[%s]].", corr_template)}, " ")
end
else
if header == "library" or header == "metamodule" then
result = string.format("This module primarily serves as a library for other modules.")
else
result = header
end
end
elseif namespace == "Template" then
if header == "noinvoke" then header = "" end
if p.page_exists(corr_module) then
if header == "metatemplate" then
result = "This template is a metatemplate. It is used to build other templates and should not be used standalone, except for testing or simple usage." .. " " .. string.format("This template is implemented by the Lua module [[%s]].")
else
result = table.concat({header, string.format("This template is implemented by the Lua module [[%s]].")}, " ")
end
else
if header == "metatemplate" then
result = "This template is a metatemplate. It is used to build other templates and should not be used standalone, except for testing or simple usage."
else
result = header
end
end
else
result = "This template is in the wrong namespace. It should be used within the Template or Module namespaces."
end
return string.format(":''%s''", result)
end
end


function p.dochead(frame)
function p.dochead(frame)
local args = getArgs(frame)
local args = getArgs(frame) or {}
-- Get current title
local title = mw.title.getCurrentTitle()
args["namespace"] = args["namespace"] or title.nsText
args["pagename"]  = args["pagename" ] or title.text
args["header"] = args["header"] or "noinvoke"
--return p._dochead(args)
return args["header"]
end
end


return p
return p