Editing Module:Demo
From MINR.ORG WIKI
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 4: | Line 4: | ||
--unless a table containing a list keys of not to inherit is provided | --unless a table containing a list keys of not to inherit is provided | ||
function disinherit(frame, onlyTheseKeys) | function disinherit(frame, onlyTheseKeys) | ||
− | local parent = frame:getParent() | + | local orphan, parent, args = frame:newChild{}, frame:getParent(), {} |
− | + | orphan.getParent = (parent or frame).getParent --returns nil | |
− | orphan.getParent = parent.getParent --returns nil | + | --setmetatable(orphan.args, {index = args}) |
− | orphan.args = | + | --if 1 then return orphan, frame end |
if onlyTheseKeys then | if onlyTheseKeys then | ||
− | + | for _, f in ipairs(parent and {parent.args, frame.args} or {frame.args})do | |
− | + | for k, v in pairs(f) do | |
− | for k, v in pairs( | + | args[k] = args[k] or v |
− | |||
end | end | ||
end | end | ||
− | |||
− | |||
for _, k in ipairs(onlyTheseKeys) do | for _, k in ipairs(onlyTheseKeys) do | ||
− | + | args[k] = nil | |
end | end | ||
+ | orphan.args = args | ||
end | end | ||
− | return orphan, | + | return orphan, frame |
end | end | ||
Line 42: | Line 40: | ||
return { | return { | ||
source = noWiki or code, | source = noWiki or code, | ||
− | output = orphan:preprocess(code | + | output = orphan:preprocess(code), |
frame = frame | frame = frame | ||
} | } | ||
Line 65: | Line 63: | ||
'demo_main', | 'demo_main', | ||
'demo_br', | 'demo_br', | ||
− | 'demo_result_arg | + | 'demo_result_arg' |
− | |||
}) | }) | ||
+ | --if 1 then return mw.dumpObject(orphan.args) end | ||
local template = frame.args.demo_template and 'Template:'..frame.args.demo_template | local template = frame.args.demo_template and 'Template:'..frame.args.demo_template | ||
local demoFunc = frame.args.demo_module_func or 'main\n' | local demoFunc = frame.args.demo_module_func or 'main\n' | ||
Line 73: | Line 71: | ||
frame.args.br, frame.args.result_arg = frame.args.demo_br, frame.args.demo_result_arg | frame.args.br, frame.args.result_arg = frame.args.demo_br, frame.args.demo_result_arg | ||
if demoModule then | if demoModule then | ||
− | local | + | local source = {insert = function(self, ...) table.insert(self, ...) return self end, '{{', template and '' or '#invoke:', frame.args.demo_template or frame.args.demo_module, template and '' or '|', not template and demoFunc or '\n'} |
− | |||
− | |||
− | |||
− | |||
− | |||
for k, v in pairs(orphan.args) do | for k, v in pairs(orphan.args) do | ||
local nan, insert = type(k) ~= 'number', {v} | local nan, insert = type(k) ~= 'number', {v} | ||
− | + | source:insert'|' | |
− | |||
if nan then | if nan then | ||
− | + | source:insert(k):insert'=':insert'\n' | |
− | table.insert(insert, 1, # | + | table.insert(insert, 1, #source) |
end | end | ||
− | + | source:insert(unpack(insert)) | |
− | + | if v:match('nowiki') then | |
− | + | orphan.args = orphan:preprocess(mw.text.unstripNoWiki(v)) | |
− | orphan.args | ||
end | end | ||
end | end | ||
source:insert'}}' | source:insert'}}' | ||
− | |||
return p.main(orphan, { | return p.main(orphan, { | ||
source = mw.text.encode(table.concat(source), "<>'|=~"), | source = mw.text.encode(table.concat(source), "<>'|=~"), | ||
− | output = tostring(demoModule(orphan) | + | output = tostring(demoModule(orphan)), |
frame = frame | frame = frame | ||
}) | }) |