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 = {}
p.returnString = ""
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);
local function appendToReturnString(text, concatChar)
if (p.returnString ~= "") then
p.returnString = p.returnString .. concatChar .. text
else
p.returnString = p.returnString .. text
end
return p.returnString
end
local function getReturnString()
return p.returnString
end
function p.address(frame)
local addressParts = {'ulice', 'cp', 'co', 'obec', 'psc', 'stat'};
local qualifiers = {obec = '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 entity = wd.formatStatementsFromLua(options);
--mw.logObject(entity)
if not (entity == nil) then
for k,v in pairs( addressParts ) do
if (v == 'obec') then
appendToReturnString(entity, ", ")
else
if (tobool(tostring(args[v])) == true) then
options.qualifier = qualifiers[v]
options.addClass = false
--mw.logObject(options)
local concat = ''
if (v == 'co' and tobool(tostring(args['cp'])) == true and tobool(tostring(args['co'])) == true ) then
concat = '/'
elseif (v == 'cp' and tobool(tostring(args['ulice'])) == true and tobool(tostring(args['cp'])) == true ) then
concat = ' '
else
concat = ', '
end
--mw.logObject(wd.getQualifier(options));
if (wd.getRawQualifier(options)) then
appendToReturnString(wd.getQualifier(options), concat)
end
--Wikidata.formatStatements(entity);
end
end
end
if tobool(tostring(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
appendToReturnString(statEntity, ", ")
end
end
end
if (tobool(tostring(args['addclass'])) == true) then
mw.logObject(lib.addWdClass(getReturnString()))
return lib.addWdClass(getReturnString());
else
mw.logObject(getReturnString())
return getReturnString();
end
end
return p