Module:Sandbox/Lord Farin

local p = {}

local priv = {} --Private functions function priv.isNull( arg ) return ( arg == nil or arg == "" ) end

function priv.defPage( def, cat ) local defPage if priv.isNull( def ) then defPage = "Definition:" .. cat elseif ( string.match( def, ":" ) == nil ) then defPage = "Definition:" .. def else defPage = def end return defPage end

function priv.defCat( cat, sortkey ) return "" end

function priv.initVars( frame ) local vars = {} vars.category  = mw.title.getCurrentTitle.subpageText vars.tpl_args  = frame:getParent.args return vars end

--Public functions (that is, main entry points)

function p.definitionCategory( frame ) local vars = priv.initVars( frame ) local tpl_args = vars.tpl_args local category = vars.category --[=[ defPage: Definition page link. def contains a ":"  " " def contains no ":" "Definition: " Default:            "Definition: " ]=] local defPage = priv.defPage( tpl_args.def, category ) --[=[ defLinkWikitext: Display of definition page link disp exists: " " Default:     "" ]=] local defLinkWikitext = ""  if priv.isNull( tpl_args.disp ) then    defLinkWikitext = defLinkWikitext .. defPage .. "" else defLinkWikitext = defLinkWikitext .. tpl_args.disp .. "]]" end --[=[ contextText: Display of context addendum "in the context of ..." contextdisp exists: " " context exists:    " " Default:           No addendum ]=] local contextText if priv.isNull( tpl_args.context ) then contextText = "" else contextText = " in the context of "   if priv.isNull( tpl_args.contextdisp ) then      contextText = contextText .. tpl_args.context .. "" else contextText = contextText .. tpl_args.contextdisp .. "]]"   end end --[=[ resultCatText: Display of link to associated results category nocat exists: No display Default: ]=] local resultCatText = "" if priv.isNull( tpl_args.nocat ) then resultCatText = frame:expandTemplate{ title = 'ProofsLink', args = { category } } end --[=[ transcludeText: Transclusion, if applicable, of the page linked to with  notrans exists: No display Default: ]=] local transcludeText = "" if priv.isNull( tpl_args.notrans ) then --Lua pcall construct to present graceful message when the to-be-transcluded page does not exist local exists, val = pcall( frame.expandTemplate, frame, { title = defPage } ) if exists then transcludeText = val else transcludeText = "Transclusion of " .. defPage .. " failed." end end --[=[ categoriesText: Adding the categories passed as numbered parameters See priv.defCat ]=] local categoriesText = "" local i = 1 while not priv.isNull( tpl_args[i] ) do   categoriesText = categoriesText .. priv.defCat( tpl_args[i], category ) end if i == 1 then categoriesText = "" end local result = mw.html.create result :wikitext( 'This category contains definitions related to ' .. defLinkWikitext .. contextText ) :wikitext( '. ' ) :wikitext( resultCatText ) :wikitext( '' ) :newline :wikitext( transcludeText ) :wikitext( categoriesText ) :newline:wikitext( 'End result of Lua' ) return result end

return p