Module:SkillListLite

-- Imports

local cargo = mw.ext.cargo local aicon = require( 'Module:Ability icon' )._main local color = require( 'Module:Color' )._main local getArgs = require('Module:Arguments').getArgs

-- Strings

local i18n = { error = { category = 'Category:Pages with script errors', prefix = 'Lua error', input_error = 'Missing or incomplete input', no_data = 'Found no Cargo data for "%s - %s"', old_ability = '"%s - %s" is an old ability.' } }

-- Helper functions

local h = {}

--- Make a new li object. -- @param text: The object's text. -- @param background: The object's background-color. function h.make_li(text, background) return mw.html.create('li') :addClass('skilllist-lite') :css('background-color', background) :wikitext(text) end

--- Creates an error that fits into the list. -- @param message: The error message. function h.li_error(message) return h.make_li(string.format('%s: %s.%s', i18n.error.prefix, message, i18n.error.category), '#c00') end

-- Template

local p = {}

function p.main(frame) local args = getArgs(frame, {   wrappers = {      'Template:SkillListLite'    }  }) return p._main(args) end

function p._main(args) -- Check the input. We can't use assert here since we want our custom error. if not args and args.source and args.name then return h.li_error(i18n.error.input_error) end

-- Get the ability's data. local data = cargo.query( 'abilities', 'image, type, game', {   where='uid="' .. args.source .. '&' .. args.name .. '"',    groupBy='source, title',    limit=1  } )[1] if not data then return h.li_error(string.format(i18n.error.no_data, args.source, args.name)) end if #args.name > 0 and #data.game > 0 then return h.li_error(string.format(i18n.error.old_ability, args.source, args.name)) end data.image = aicon(args, data)

local image_link = string.format('24px|link=%s#%s', data.image, args.source, args.name) local source_link = string.format('%s', args.source, (args.sourcetext or args.source)) local name_link = string.format('%s', args.source, args.name, (args.nametext or args.name))

return h.make_li((image_link .. ' ' .. source_link .. ' – ' .. name_link), color{data.type}) end

-- Return

return p