Module:Infobox Location
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Infobox Location/doc
--------------------------
-- Module for [[Template:Infobox Location]]
------------------------
local p = {}
local onmain = require('Module:Mainonly').on_main
local yesno = require('Module:Yesno')
local paramtest = require('Module:Paramtest')
local infobox = require('Module:Infobox')
local cleanimg = require('Module:Clean image').clean
-- Main function called with invokes
function p.main(frame)
local args = frame:getParent().args
local ret = infobox.new(args)
ret:defineParams{
{ name = 'image', func = { name = imgarg, params = { 'image' }, flag = { 'd' } } },
{ name = 'name', func = 'name' },
{ name = 'aka', func = 'has_content' },
{ name = 'location', func = 'has_content' },
}
ret:create()
ret:cleanParams()
ret:defineLinks({ links = {{ 'Template:%s/doc', 'Infobox' },
{ 'Template_talk:%s', 'Talk page' }}, colspan = '2' })
ret:defineName('Infobox Location')
ret:addButtonsCaption()
-- PARAMETER: image
ret:addRow{
{ tag = 'argd', content = 'image', class='infobox-image infobox-full-width-content', colspan = '2' }
}
-- PARAMETER: name
ret:addRow{
{ tag = 'argh', content = 'name', class='infobox-header', colspan = '2' }
}
-- PARAMETER: aka
if ret:paramDefined('aka') then
ret:addRow{
{ tag = 'th', content = 'Also called' },
{ tag = 'argd', content = 'aka' }
}
end
-- PARAMETER: location
if ret:paramDefined('location') then
ret:addRow{
{ tag = 'th', content = 'Location' },
{ tag = 'argd', content = 'location' }
}
end
ret:finish()
if onmain() then
local a1 = ret:param('all')
local a2 = ret:categoryData()
ret:wikitext(addcategories(a1, a2))
end
return ret:tostring()
end
function imgarg(arg)
if infobox.isDefined(arg) then
return cleanimg{ file = arg, width = 300, height = 300 }
end
return nil
end
function addcategories(args, catargs)
local ret = { 'Locations' }
-- combine table and format category wikicode
for i, v in ipairs(ret) do
if (v ~= '') then
ret[i] = string.format('[[Category:%s]]', v)
end
end
return table.concat(ret, '')
end
return p