Module:Motifs
From The Seven Sages of Rome
Documentation for this module may be created at Module:Motifs/doc
local p = {}
function p.renderBadges(frame)
local raw = frame.args[1] or ''
if raw == '' then
return ''
end
local smw = mw.smw
local html = mw.html.create()
for motif in mw.text.gsplit(raw, ';', true) do
motif = mw.text.trim(motif)
if motif ~= '' then
local data = smw.ask({
'[[' .. motif .. ']]',
'?Is Child Of',
mainlabel = '-'
})
local parent = nil
if data and data[1] and data[1]['Is Child Of'] then
parent = data[1]['Is Child Of']
if type(parent) == 'table' then
parent = parent[1]
end
end
local badge = html
:tag('span')
:addClass('badge badge-pill badge-motif mr-1')
:attr('title', parent and ('Child of: ' .. parent) or 'Top-level motif')
if parent then
badge
:tag('span')
:addClass('motif-parent')
:wikitext(parent .. ' › ')
:done()
end
badge:wikitext(frame:preprocess(
'{{#formredlink:target=' .. motif .. '|form=Content}}'
))
end
end
return tostring(html)
end
return p