User:FeRDNYC/Sandbox/ComicsHF

-- HF stands for High Frequency. -- This Module augments the built-in HF local HF = mw.InfoboxBuilderHF

-- Libraries of functions --

-- Parses invocation parameters, trims whitespace, and removes blanks HF.getArgs = require('Dev:Arguments').getArgs

-- Since this should only be evaluated once per pageview, it's now global _G.vars = { Pagename = mw.title.getCurrentTitle.text }

-- Local functions (used only in this Module) --

function invokeInt(funcName) -- This wrapper allows invocation of an internal function from a frame. -- In other words, it translates from a Template: to an internal function. return function (frame) local args = HF.getArgs(frame, { trim = true, removeBlanks = true }) return HF[funcName](args, vars) end end

-- -- Public functions (called from a Template or article) -- --

-- Takes a list (or array) of items in a field that are on a single line -- and separated by a delimiter, and does something with them. -- (Does not implement a specific Template. Called from invoke.) HF.Iterator = invokeInt('_Iterator')

- -- Internal functions (used in this and other Modules) -- - -- eliminates whitespace from the front and back of a string function HF.trim(s) if type(s) == 'string' then return (s:gsub("^%s*(.-)%s*$", '%1')) else return false end end

-- I think this is for padding with zeros function HF.AddZeros( s, len ) local output = ""

local sLength = string.len( tostring( s ) ) local diff = tonumber( len ) - tonumber( sLength )

if diff > 0 then for i = 1, diff do     output = output .. "0"   end end

output = output .. s

return output end

function HF._Iterator( args ) local text = args['text'] or args[1] or nil local delimiter = args['delimiter'] or args[2] or ';' local storage = mw.text.split( text, delimiter ) local output = {}

for i, item in ipairs( storage ) do       item = HF.trim(item) check = HF.trim(check) if not string.match(item, '%S') then break end table.insert(output, item) end end return table.concat(output, ' · ') end

HF.TrimOverflow = invokeInt('_TrimOverflow')

function HF._TrimOverflow( args ) local input = args[1] local breakat = args['TrimBreak'] or ' ' local limit = args['TrimLimit'] or 1000 local morelabel = args['TrimMoreLabel'] or 'more...' local lesslabel = args['TrimLessLabel'] or 'less...' if not input then return nil end if mw.ustring.len( input ) > limit then local primary  = mw.ustring.sub( input, 1, limit ) local secondary = mw.ustring.sub( input, limit ) local shiftatbreak = '' if not args['TrimBreak'] and string.find(primary, '·') then breakat = '·' elseif not args['TrimBreak'] and string.find(primary, ';') then breakat = ';' elseif not args['TrimBreak'] and string.find(primary, ' ') then breakat = ' ' end primary, shiftatbreak = mw.ustring.match( primary, '(.*)'..breakat..'(.*)$') secondary = shiftatbreak .. secondary local morebox = mw.html.create('div') :addClass('expansion-tag') :addClass('mw-collapsible') :addClass('mw-collapsed') :attr('data-expandtext',morelabel) :attr('data-collapsetext',lesslabel) :wikitext(secondary):allDone return primary .. tostring(morebox) else return input end end

- -- Output (send it back to whatever called it) -- - return HF