Editing Module:Sandbox/User:Microbrews/Variants
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 13: | Line 13: | ||
local query = { |
local query = { |
||
'[[Variant of::'..variant_name..']]', |
'[[Variant of::'..variant_name..']]', |
||
'? |
'?Name', |
||
'?Profession A #', -- Adding a # to this query makes it return plaintext instead of a link |
'?Profession A #', -- Adding a # to this query makes it return plaintext instead of a link |
||
'?Profession B #', |
'?Profession B #', |
||
Line 33: | Line 33: | ||
function p.variants_header(args) |
function p.variants_header(args) |
||
local smw_data = get_table_info(args) |
local smw_data = get_table_info(args) |
||
local main_variant = args[1] |
local main_variant = args[1] |
||
local contents |
local contents |
||
if smw_data then |
if smw_data then |
||
local formatted = {} |
local formatted = {} |
||
for _, entry in ipairs(smw_data) do |
for _, entry in ipairs(smw_data) do |
||
local name = entry[' |
local name = entry['Name'] |
||
local variant_name = name:gsub(main_variant, '', 1) |
local variant_name = name:gsub(' ' .. main_variant .. '$', '', 1) |
||
variant_name = variant_name:gsub('^%s*(.-)%s*$', '%1') -- trim whitespace |
|||
variant_name = variant_name:gsub('%((.-)%)$', '%1') -- trim parentheses |
|||
variant_name = variant_name:gsub("^%l", string.upper) -- capitalize first letter |
|||
table.insert(formatted, '[[' .. name .. '|' .. variant_name .. ']]') |
table.insert(formatted, '[[' .. name .. '|' .. variant_name .. ']]') |
||
end |
end |
||
Line 49: | Line 46: | ||
contents = '[[Category:Empty variant list]]' |
contents = '[[Category:Empty variant list]]' |
||
end |
end |
||
contents = '[[' .. main_variant .. ']]' .. ' : ' .. contents |
|||
return mw.html.create('div') |
return mw.html.create('div') |
||
:addClass('variants-header') |
:addClass('variants-header') |
||
Line 113: | Line 111: | ||
:tag('td') |
:tag('td') |
||
:css{ ['border-left'] = 'none' } |
:css{ ['border-left'] = 'none' } |
||
:wikitext( |
:wikitext(entry[1]) |
||
:done() |
:done() |
||
:tag('td') |
:tag('td') |