Module:Location Table
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Module:Location Table/doc. [edit] [history] [purge]
Module:Location Table requires Module:Edit button.
Module:Location Table requires Module:Param Parse.
Module:Location Table requires strict.
Module powering {{Location Table}}
.
To use directly, _main takes a table with arguments in the same format as the template.
require('strict')
local parse = require('Module:Param Parse')
local edit = 'Unknown <span class="small plainlinks">' .. require('Module:Edit button')() .. '</span>'
local p = {}
function p.main(frame)
return p._main(frame:getParent().args)
end
function p._main(args)
local tbl = mw.html.create('table')
:addClass('wikitable sortable filterable sticky-header loctable autosort=1,a')
:css{ ['text-align'] = 'center' }
:tag('tr')
:tag('th'):wikitext('Location'):done()
:tag('th'):wikitext('Episode'):done()
:tag('th'):wikitext('Qty.'):done()
:done()
local loc_version = args.version
local location_object = mw.title.getCurrentTitle().fullText
local id_prefix = 'LOC_'
if loc_version then
location_object = location_object .. '#' .. loc_version
id_prefix = id_prefix .. loc_version .. '_'
end
local loc_json = {}
for i = 1, 9007199254740992 do
local loc = args['loc'..i]
if not loc then
break
end
local qty = args['qty'..i]
qty = tonumber(qty or '')
loc_json[loc] = qty or -1
local loc_link = ('[[%s]]'):format(loc)
local episode = mw.smw.ask{loc_link, '?Episode#=', 'mainlabel=-'}
episode = episode and episode[1][1]
local id = id_prefix .. loc
tbl:tag('tr')
:attr{ id = id }
:tag('td'):wikitext(loc_link)
:tag('td'):wikitext(parse.episode_func(episode)):done()
:tag('td'):wikitext(qty or edit):done()
:done()
mw.smw.subobject({
['Location object'] = location_object,
['Located in'] = loc,
['Location quantity'] = qty or 'Unknown'
}, id)
end
if loc_version then
mw.smw.subobject({ ['Location JSON'] = mw.text.jsonEncode(loc_json) }, loc_version)
else
mw.smw.set{ ['Location JSON'] = mw.text.jsonEncode(loc_json) }
end
return tbl
end
return p