Jump to content

Module:Sidebar: Difference between revisions

if args.name isn't specified, let Module:Navbar try to guess the name (it does a slightly better job than the current page's title, which is almost always wrong)
use Module:Arguments
Line 5: Line 5:
local p = {}
local p = {}
   
   
local getArgs
local HtmlBuilder = require('Module:HtmlBuilder')
local HtmlBuilder = require('Module:HtmlBuilder')
local navbar = require('Module:Navbar')._navbar
local navbar = require('Module:Navbar')._navbar
Line 275: Line 276:
function makeWrapper(func)
function makeWrapper(func)
return function(frame)
return function(frame)
local origArgs
if not getArgs then
if frame == mw.getCurrentFrame() then
getArgs = require('Module:Arguments').getArgs
-- We're being called via #invoke. If the invoking template passed any args, use
-- them. Otherwise, use the args that were passed into the template.
origArgs = frame:getParent().args
for k, v in pairs(frame.args) do
origArgs = frame.args
break
end
else
-- We're being called from another module or from the debug console, so assume
-- the args are passed in directly.
origArgs = frame
end
-- ParserFunctions considers the empty string to be false, so to preserve the previous
-- behavior of the template, change any empty arguments to nil, so Lua will consider
-- them false too.
local args = {}
for k, v in pairs(origArgs) do
if v ~= '' then
args[k] = v
end
end
end
return func(getArgs(frame))
return func(args)
end
end
end
end