모듈:Deck
외관
이 모듈에 대한 설명문서는 모듈:Deck/설명문서에서 만들 수 있습니다
local p = {}
function p.render(f)
local args = f:getParent().args
if args['items'] == nil then
args = f.args
end
local deck = mw.html.create('div'):addClass('kawa-deck')
if args['gap'] then
deck:css('gap', mw.text.trim(args['gap']))
end
local lines = (args['items'] or ''):gmatch("([^\n]+)")
local items = {}
for line in lines do
line = mw.text.trim(line)
if line ~= '' then
local key, value = line:match('^([%w%s]+)=(.+)$')
if key and value then
key = mw.text.trim(key):lower()
value = mw.text.trim(value)
if key ~= '' then
items[#items][key] = value
end
else
table.insert(items, {
url = line
})
end
end
end
-- HTML
local html = ''
for _, item in ipairs(items) do
local url = item.url or '#'
local icon = item.icon or ''
local title = mw.text.trim(item.title or '')
html = html .. '[' .. url .. ' ' .. tostring(mw.html.create('span'):wikitext(icon)) ..
tostring(mw.html.create('span'):wikitext(title)) .. ']'
end
deck:wikitext(html)
return f:preprocess(tostring(deck))
end
return p