Module:Location Table
Module documentation
This documentation is transcluded from Module:Location Table/doc. [edit] [history] [purge]
Module:Location Table's function bottom is invoked by Template:LocTableBottom.
Module:Location Table's function head is invoked by Template:LocTableHead.
Module:Location Table's function line is invoked by Template:LocLine.
Module:Location Table requires Module:Break Isolation.
Module:Location Table requires Module:Edit button.
Module:Location Table requires Module:Param Parse.
Module:Location Table requires strict.
This module is used by {{LocTableHead}}
, {{LocLine}}
and {{LocTableBottom}}
.
In {{LocTableHead}}
: Saves the {{{version}}}
argument.
In {{LocLine}}
: Sets a smw subobject for each location, saves the location and quantity and generates the table row.
In {{LocTableBottom}}
: Retrieves the location and quantity each LocLine was called with and stores the Property:Location JSON.
require('strict')
local persistant = require('Module:Break Isolation').get_module_store('Module:Location Table')
local parse = require('Module:Param Parse')
local edit = 'Unknown <span class="small plainlinks">' .. require('Module:Edit button')() .. '</span>'
persistant.counter = persistant.counter or 0
local p = {}
function p.head(frame)
local args = frame:getParent().args
assert(not persistant.in_table, 'Second Template:LocTableHead (Missing Template:LocTableBottom?)')
persistant.in_table = true
persistant.json = {}
persistant.version = args.version
persistant.location_object = mw.title.getCurrentTitle().fullText
if args.version then
persistant.location_object = persistant.location_object .. '#' .. args.version
end
end
function p.line(frame)
assert(persistant.in_table, 'Template:LocLine when not in a location table (Missing Template:LocTableHead?)')
local args = frame:getParent().args
local loc = args.loc
local qty = args.quantity
qty = tonumber(qty or '')
persistant.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]
persistant.counter = persistant.counter + 1
local id = 'LOC_' .. persistant.counter
mw.smw.subobject({
['Location object'] = persistant.location_object,
['Located in'] = loc,
['Location quantity'] = qty or 'Unknown'
}, id)
return mw.html.create('tr')
:attr{ id = id }
:tag('td'):wikitext(loc_link):done()
:tag('td'):wikitext(parse.episode_func(episode)):done()
:tag('td'):wikitext(qty or edit):done()
:done()
end
function p.bottom(frame)
assert(persistant.in_table, 'Template:LocTableBottom when not in a location table (Missing Template:LocTableHead?)')
if persistant.version then
mw.smw.subobject({ ['Location JSON'] = mw.text.jsonEncode(persistant.json) }, persistant.version)
else
mw.smw.set{ ['Location JSON'] = mw.text.jsonEncode(persistant.json) }
end
persistant.in_table = nil
persistant.json = nil
persistant.version = nil
persistant.location_object = nil
end
return p