Module:documentation: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
 
(21 intermediate revisions by the same user not shown)
Line 3: Line 3:
function export.show(frame)
function export.show(frame)
local source = frame.args[1] or frame.args["source"]
local source = frame.args[1] or frame.args["source"]
local title = mw.title.getCurrentTitle().fullText
local doc = ((type(source) == "string" and source ~= "") and mw.title.new(source))
local doc = ((type(source) == "string" and source ~= "") and mw.title.new(source))
or mw.title.new(mw.title.getCurrentTitle().fullText .. "/documentation")
or mw.title.new(title .. "/documentation")
if not doc.exists then
if not doc.exists then
return '<div style="margin-left:1em;"><i>This page has no documentation. [[' .. doc:fullUrl{action="edit"} .. '|Create it]].</div>'
local ret = '\n<div class="documentation" style="margin:1em 0 0; padding: .5em; border:1px solid #a8a8a8; background-color:#ecfcf4; clear:both;">'
ret = ret .. "\n'''This template has no documentation.'''"
ret = ret .. '\n\nPlease <span class="plainlinks">[' .. doc:fullUrl{action="edit"} .. ' create it]</span>.'
return ret .. '\n</div>\n'
end
end
local doc_content = doc:getContent()
local doc_content = frame:expandTemplate{title=doc.fullText}
if doc_content == nil then
local ret = '\n<div class="documentation" style="margin:1em 0 0; padding: 1em; border:1px solid #a8a8a8; background-color:#ecfcf4; clear:both;">'
error("Documentation page exists but content is nil")
ret = ret .. '\n<div style="padding-bottom:3px; border-bottom:1px solid #bfbfbf; margin-bottom:1ex;">'
end
ret = ret .. '<span style="font-size:125%; font-weight:bold;">[[File:TemplateDocumentation.svg|50px]] Template documentation</span>'
return '<div class="documentation">\nThe following documentation is located at [[' .. doc.fullText .. "]]. <sup>[[" .. doc:fullUrl{action="edit"} .. "|edit]]</sup>\n\n" .. doc:getContent() .. "\n</div>"
ret = ret .. ' <span class="mw-editsection-like plainlinks">'
ret = ret .. ' &#91;[[' .. doc.fullText .. '|view]]&#93;'
ret = ret .. ' &#91;[' .. doc:fullUrl{action="edit"} .. ' edit]&#93;'
ret = ret .. ' &#91;[[Special:Purge/' .. title .. '|purge]]&#93;'
ret = ret .. '</span>'
ret = ret .. '</div>\n' .. doc_content .. '\n</div>'
return ret
end
end


return export
return export

Latest revision as of 12:13, 7 August 2023

Documentation for this module may be created at Module:documentation/documentation

local export = {}

function export.show(frame)
	local source = frame.args[1] or frame.args["source"]
	local title = mw.title.getCurrentTitle().fullText
	local doc = ((type(source) == "string" and source ~= "") and mw.title.new(source))
		or mw.title.new(title .. "/documentation")
	if not doc.exists then
		local ret = '\n<div class="documentation" style="margin:1em 0 0; padding: .5em; border:1px solid #a8a8a8; background-color:#ecfcf4; clear:both;">'
		ret = ret .. "\n'''This template has no documentation.'''"
		ret = ret .. '\n\nPlease <span class="plainlinks">[' .. doc:fullUrl{action="edit"} .. ' create it]</span>.'
		return ret .. '\n</div>\n'
	end
	local doc_content = frame:expandTemplate{title=doc.fullText}
	local ret = '\n<div class="documentation" style="margin:1em 0 0; padding: 1em; border:1px solid #a8a8a8; background-color:#ecfcf4; clear:both;">'
	ret = ret .. '\n<div style="padding-bottom:3px; border-bottom:1px solid #bfbfbf; margin-bottom:1ex;">'
	ret = ret .. '<span style="font-size:125%; font-weight:bold;">[[File:TemplateDocumentation.svg|50px]] Template documentation</span>'
	ret = ret .. ' <span class="mw-editsection-like plainlinks">'
	ret = ret .. ' &#91;[[' .. doc.fullText .. '|view]]&#93;'
	ret = ret .. ' &#91;[' .. doc:fullUrl{action="edit"} .. ' edit]&#93;'
	ret = ret .. ' &#91;[[Special:Purge/' .. title .. '|purge]]&#93;'
	ret = ret .. '</span>'
	ret = ret .. '</div>\n' .. doc_content .. '\n</div>'
	return ret
end

return export