Module:Sandbox/User:Microbrews/Variants: Difference between revisions

no edit summary
(Created page with "require('Module:Mw.html extension') local p = {} function sort_entries(entry1, entry2) -- Sort the variants based on the sum of the profession levels local entry1_value = (entry1['Profession Level A'] or 0) + (entry1['Profession Level B'] or 0) local entry2_value = (entry2['Profession Level A'] or 0) + (entry2['Profession Level B'] or 0) return entry1_value < entry2_value end function get_table_info(args, get_images) local variant_name = args.variant or mw.title.g...")
 
No edit summary
 
(21 intermediate revisions by the same user not shown)
Line 13:
local query = {
'[[Variant of::'..variant_name..']]',
'?Name#-=page',
'?Profession A #', -- Adding a # to this query makes it return plaintext instead of a link
'?Profession B #',
Line 33:
function p.variants_header(args)
local smw_data = get_table_info(args)
local main_variant = args[1]:gsub('%(', '%%%('):gsub('%)', '%%%)') -- it's going to be a pattern, so escape the parentheses
local contents
if smw_data then
local formatted = {}
for _, entry in ipairs(smw_data) do
local name = entry['Namepage']
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 .. ']]')
end
Line 46 ⟶ 49:
contents = '[[Category:Empty variant list]]'
end
contents = '[[' .. main_variant .. ']]' .. '&nbsp;:&nbsp;' .. contents
return mw.html.create('div')
:addClass('variants-header')
Line 111 ⟶ 113:
:tag('td')
:css{ ['border-left'] = 'none' }
:wikitext('[['..entry[1'page']..']]')
:done()
:tag('td')
291

edits