Last active
April 19, 2020 09:26
-
-
Save lucamauri/6cf9c68299936e0f743815e53800deb8 to your computer and use it in GitHub Desktop.
LUA module to automatically create example of a template in MediaWiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local p = {} --p stands for package | |
function p.TemplateExample(frame) | |
local SubPageName | |
local SubPageTitle | |
local Title | |
local Content | |
local pre = mw.html.create('pre') | |
local DoubleLF = string.char(10) .. string.char(10) | |
if not frame.args[1] then | |
SubPageName='Example' | |
else | |
SubPageName=frame.args[1] | |
end | |
Title = mw.title.getCurrentTitle() | |
SubPageTitle = mw.title.makeTitle(Title.namespace, Title.text .. '/' .. SubPageName) | |
local Intro = 'This example is automatically generated via LUA script from the code in the page <code>[[' .. SubPageTitle.prefixedText .. ']]</code>' | |
local CodeString = 'The code' | |
local ReturnString = 'renders as' | |
Content = SubPageTitle:getContent() | |
if not Content then | |
return "Page <code>[[" .. SubPageTitle.prefixedText .. "]]</code> does not exist: it is not possible to extract any text to generate example with" | |
else | |
pre | |
:css( 'width', '65%' ) | |
:wikitext(mw.text.nowiki(SubPageTitle:getContent())) | |
return Intro .. DoubleLF .. CodeString .. DoubleLF .. tostring(pre) .. DoubleLF .. ReturnString .. DoubleLF .. frame:expandTemplate{ title = SubPageTitle } | |
end | |
end | |
return p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment