Modül:Coa/core
Bu modül için bir Modül:Coa/core/belge belgelendirmesi oluşturabilirsiniz
local getArgs = require('Module:Bağımsız değişkenler').getArgs
local data = require('Module:Coa/data')
local p = {}
local function find_key(key)
key = mw.ustring.lower(key) -- make lowercase
local patterns = {
-- "^%[%[file:",
-- "%|.*%]%]$",
-- "^house ",
-- "^coin of",
-- "%.png$",
-- "%.svg$",
-- "%.jpe?g$",
}
for _, pattern in pairs(patterns) do -- remove some words
key = mw.ustring.gsub(key, pattern, "")
end
local patterns2 = {
" of ",
" the ",
}
for _, pattern in pairs(patterns2) do -- remove some words, replace with space
key = mw.ustring.gsub(key, pattern, " ")
end
key = mw.ustring.gsub(key, "[^a-z0-9]", "") -- remove all non-alphanumeric characters
return key
end
local function get(key)
house = data[find_key(key)]
if house == nil then
error('"' .. key .. '" is not a valid COA')
else
return house
end
end
local function coa(file, link, text, size, format)
if format == 'file' then
return file
elseif format == 'image' then
return '[[File:' .. file .. '|' .. size .. '|link=' .. link .. ']]'
elseif format == 'text' then
if link == nil or text == nil then
return '[[File:' .. file .. '|' .. size .. '|link=]]'
else
return '[[File:' .. file .. '|' .. size .. '|link=' .. link .. ']] [[' .. link .. '|' .. text .. ']]'
end
end
end
local function get_size(size)
local sizes = {
xs = '16x18px',
s = '20x22px',
m = '32x35px',
l = '100x110px',
xl = '250x275px',
['infobox-l'] = '50x55px',
['infobox-m'] = '40x44px',
['infobox-s'] = '32x35px',
}
return sizes[size] or sizes['xs']
end
function p.main(frame)
local args = getArgs(frame)
local key = args[1]
if key == nil then
error("No key given")
end
local house = get(key)
local file = args['file'] or house['file'] or "None.svg"
local link = args['link'] or house['page'] or ""
local text = args['text'] or house['name'] or house['page']
local size = get_size(args['size'] or args[2])
local format = args['format']
local coa_ = coa(file, link, text, size, format)
if mw.ustring.find(find_key(key), "^none") then
return "[[Category:Explicitly unknown coat of arms]]" .. coa_
elseif mw.ustring.find(find_key(key), "^unknown") then
return "[[Category:Explicitly unknown coat of arms]]" .. coa_
else
return coa_
end
end
function p.list(frame)
local t = '{| class="wikitable"'
for key, house in pairs(data) do
t = t .. '\n|-\n| <code>' .. key .. '</code> || ' .. coa(
house['file'] or "None.svg",
house['page'],
house['name'] or house['page'],
'16x18px',
'text'
)
end
t = t .. '\n|}'
return t
end
function p.png_list(frame)
local t = '{| class="wikitable"'
for key, house in pairs(data) do
local file = house['file'] or "None.svg"
if mw.ustring.match(file, "%.svg$") == nil then
t = t .. '\n|-\n| <code>' .. key .. '</code> || ' .. coa(
file,
":File:" .. file,
file,
'100x110px',
'text'
)
end
end
t = t .. '\n|}'
return t
end
return p