Module:CharList: Difference between revisions

Undo revision 839175 by Ritsu (talk)
(Created page with "require('Module:CommonFunctions'); local getArgs = require('Module:Arguments').getArgs local p = {} -- Main process function p.main(frame) local args = getArgs(frame) local named_list = {} local chars = frame:preprocess('{{:MediaWiki:NavSidebar/Character}}') -- Get rid of link wikitext. :gsub('%[%[', ''):gsub('%]%]', '') -- Replace star separators to distinct strings to make it easier. :gsub('%*%*%*', 'SEP1'):gsub('%*%*', 'SEP2'):gsub('%*',...")
 
(Undo revision 839175 by Ritsu (talk))
Tag: Undo
 
(16 intermediate revisions by the same user not shown)
Line 4: Line 4:


-- Main process
-- Main process
function p.main(frame)
function p.main(frame, lang)
     local args = getArgs(frame)
     local args = getArgs(frame)


     local named_list = {}
     local named_list = {}
     local chars = frame:preprocess('{{:MediaWiki:NavSidebar/Character}}')
    local not_exist = {}
    lang = lang or args.lang
    if lang then lang = '/' .. lang else lang = '' end
     local chars = frame:preprocess('{{:MediaWiki:NavSidebar' .. lang  .. '/Character}}')
     -- Get rid of link wikitext.
     -- Get rid of link wikitext.
     :gsub('%[%[', ''):gsub('%]%]', '')
     :gsub('%[%[', ''):gsub('%]%]', '')
Line 29: Line 32:
                     named_list[base] = chars[k]
                     named_list[base] = chars[k]
                     -- Save the order of iteration, because Lua doesn't remember it.
                     -- Save the order of iteration, because Lua doesn't remember it.
                     table.insert(base_order, base);
                     table.insert(base_order, trim(base));
                 end
                 end
             end
             end
         end
         end
     end
     end
    local placeholder = '%#!%|'


     -- Shift the new table's indexes up after getting rid of the base name.
     -- Shift the new table's indexes up after getting rid of the base name.
Line 41: Line 46:
             -- Remove link placeholders.
             -- Remove link placeholders.
             for k2, v2 in ipairs(named_list[k][i]) do
             for k2, v2 in ipairs(named_list[k][i]) do
                 named_list[k][i][k2] = trim(named_list[k][i][k2]:gsub('%#!%|', ''));
                 local name = trim(named_list[k][i][k2]:gsub('</div>', ''):gsub("<div id='nav'>", ''))
                local name_replace = name:gsub(placeholder, '');
                named_list[k][i][k2] = name_replace
 
                -- Create a table of characters with placeholders, marked as not released.
                if string.match(name, placeholder) then
                    table.insert(not_exist, name_replace);
                end
             end
             end


Line 54: Line 66:
     -- Output point
     -- Output point
     local char_list = {
     local char_list = {
         base_order, named_list
         base_order, named_list, not_exist
     }
     }
    if args.dump then return dump(char_list) end
      
      
     return dump(char_list)
     return char_list


end
end


return p
return p