Modul:Adresa
Vzhled
Modul pro práci s adresou.
Použití
Do šablony umístěte {{#invoke:Adresa|address}} (přebírá z Wikidat) nebo {{#invoke:Adresa|addressFromArgs}} (přebírá z parametrů šablony).
Parametry
Funkce | parametr | hodnoty | popis |
---|---|---|---|
address | ulice | true nebo false | řídí zobrazení ulice |
cp | true nebo false | řídí zobrazení čp. | |
co | true nebo false | řídí zobrazení čo. | |
obec | true nebo false | řídí zobrazení města | |
stat | true nebo false | řídí zobrazení státu | |
psc | true nebo false | řídí zobrazení psč | |
misto | true nebo false | řídí zobrazení místa | |
addressFromArgs | ulice | wikitext | |
cp | wikitext | ||
co | wikitext | ||
obec | wikitext | ||
stat | wikitext | ||
psc | wikitext | ||
misto | wikitext |
local wd = require 'Modul:Wikidata'
local lib = require 'Modul:Wikidata/lib'
local getArgs = (require 'Modul:Arguments').getArgs
local p = {}
local function tobool(v)
return v and ( (type(v)=="number") and (v==1) or ( (type(v)=="string") and (v=="true") ) )
end
--mw.logObject(p.addressParts);
function p.address(frame)
local addressParts = {'ulice', 'cp', 'co', 'mesto', 'psc', 'stat'};
local qualifiers = {mesto = 'P159', ulice = 'P669', cp = 'P4856', co = 'P670', psc = 'P281', stat = 'P17'}
local options = {};
local args = getArgs(frame, { removeBlanks = true })
--options.id = 'Q270704';
options.property = 'P159';
options.addclass = false
local returnString = ''
local entity = wd.formatStatementsFromLua(options);
--mw.logObject(entity)
if not (entity == nil) then
returnString = entity
for k,v in pairs( addressParts ) do
if (tobool(args[v]) == true) then
options.qualifier = qualifiers[v]
options.addClass = false
--mw.logObject(options)
local concat = ''
if (tobool(args['cp']) == true and tobool(args['co']) == true ) then
if (v == 'co') then
concat = '/'
else
concat = ', '
end
else
concat = ', '
end
--mw.logObject(wd.getQualifier(options));
if (wd.getRawQualifier(options)) then
returnString = returnString .. concat
returnString = returnString .. wd.getQualifier(options);
end
--Wikidata.formatStatements(entity);
end
end
if tobool(args['stat']) == true then
local statOptions = {}
statOptions.id = wd.getRawValue(options)
statOptions.property = 'P17'
statOptions.addclass = false
statOptions.limit = 1
local statEntity = wd.formatStatementsFromLua(statOptions);
if not (statEntity == nil) then
returnString = returnString .. ', '
returnString = returnString .. statEntity
end
end
end
if (tobool(args['addclass']) == true) then
mw.logObject(lib.addWdClass(returnString))
return lib.addWdClass(returnString);
else
mw.logObject(returnString)
return returnString;
end
end
return p