Module:ComicsHF/Iterator

local Iterator = {} function Iterator.List( args ) local text = args['text'] or args[1] or nil local delimiter = args['delimiter'] or args[2] or ';' local contributorrole = args['role'] or nil local check = args['check'] or nil local storage = mw.text.split( text, delimiter ) end

-- Internal functions (used in this and other Modules --

-- This creates a link to a category, as well as placing it in that category. -- `sortkey` and `label` are optional -- If there's no `label` given, it will only place it in the category, -- which is what HF.Category is for. function CategoryLink( category, sortkey, label ) if label and label ~= '' then return LinkToCategory( category, label ) .. Category( category, sortkey ) else return Category( category, sortkey ) end end -- Adds a Category -- `sortkey` is optional function Category( category, sortkey ) if sortkey == nil then sortkey = '' else sortkey = '|' .. sortkey end return string.format(''..'Category:%s%s', category, sortkey) end -- Adds a link to a Category function LinkToCategory( category, label ) return string.format('%s', category,        label or 'Category:' .. category ) end -- Adds an internal link -- `label` is optional function Link( link, text ) if not HF.isempty( text ) then return string.format('%s', link, text) else return string.format(''..'%s', link) end end

-- Checks to see if there's an existing article at the target. -- If there is, creates a link. -- If there's not, only write the target's name as text. -- If it is passed a link, it will not perform this check and will only write the link. function Iterator:killredlinks( object ) if object:match("^%[%[(.*)%]%]$") then return object elseif mw.title.new( object ).exists == true then table.insert( self, Link( object ) ) else table.insert( self, object ) end end -- Checks to see if there's an existing category at the target. -- If there is, creates a link. -- If there's not, only write the target's name as text. function Iterator:killredcatlinks( object ) if mw.title.new( object, 'Category' ).exists == true then table.insert( self, Link( ':Category:'..object, object ) ) else table.insert( self, object ) end end -- Checks to see if there's an existing category at the target. -- If there is, creates a link. -- If there's not, only write the target's name as text. function HF.killemptycategories( object ) if mw.title.new( object, 'Category' ).exists == true then table.insert( self, Category( object, object, object) ) else table.insert( self, object ) end end

return Iterator