Module:Based on/sandbox
Appearance
| This is the module sandbox page for Module:Based on (diff). |
| This Lua module is used on approximately 31,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module implements {{Based on}}. If more than one individual is listed, the entries are formatted with {{Unbulleted list}}.
Usage
[edit]To directly call this module (all arguments except work name optional):
{{#invoke:Based on|lua_main|Work name|Writer 1|Writer 2|...}}
To call it from a template, passing on the arguments from it:
{{#invoke:Based on|main}}
local p = {}
function p.lua_main(frame)
local s = frame.args[1]
local indent = frame.args['indent']
indent = indent and indent:lower() or ""
local do_indent = indent == "yes" or indent == "y" or indent == "true" or indent == "1"
if frame.args[3] then
local args = {}
for i, v in ipairs(frame.args) do
if i >= 2 then
args[#args+1] = v
end
end
args['style'] = 'display: inline'
args['list_style'] = 'display: inline'
args['item1_style'] = 'display: inline'
h = mw.html.create('div')
h:addClass('template-based-on')
local expanded = frame:expandTemplate{ title = 'Unbulleted list', args = args }
if do_indent then
s = '<div style="padding-left: 1em; text-indent: -1em;">' .. s .. '</div>'
h:wikitext(s)
h:wikitext('<span style="margin-left:1em;">by </span>')
expanded = expanded:gsub("<li>", "<li style='padding-left: 1em;'>")
expanded = expanded:gsub("<br />", "<br /><span style='margin-left:1em;'>")
h:wikitext(expanded)
else
h:wikitext(s)
h:tag('br') -- h:newline() is not working for some reason
h:wikitext('by ')
h:wikitext(expanded)
end
return h
elseif frame.args[2] then
if do_indent then
s = '<div class="template-based-on" style="padding-left: 1em; text-indent: -1em;">' .. s .. '<br />by ' .. frame.args[2] .. '</div>'
else
s = '<div class="template-based-on">' .. s .. '<br />by ' .. frame.args[2] .. '</div>'
end
return s
end
return s
end
function p.main(frame)
return p.lua_main(frame:getParent())
end
return p