Difference between revisions of "Module:Icon"
Jump to navigation
Jump to search
(removing documentation redundant with /docs page) |
(removing documentation redundant with /docs page) |
(No difference)
| |
Revision as of 22:59, 21 December 2019
Usage
This module is intended to back the rendering of more complicated Template:Icon cases. Currently it supports the following cases:
- Wyrmprints
In addition to main unnamed argument, it takes 3 additional optional named arguments:
- link: to specify a custom navigation link for the icon thumbnail
- size: to specify a custom size for the icon thumbnail
- text: (must be '1' for true or '0' for false) to specify if a text label should be appended after the icon. Defaults to false.
Example
Generally, this module should be called via the regular wikitext templates instead of directly. But here is example syntax for calling the functions from wikitext:
{{#invoke:Icon|Wyrmprint|Heralds of Hinomoto}}
Lua error: Error: Table Wyrmprints not found..
{{#invoke:Icon|Wyrmprint|Heralds of Hinomoto|size=60px}}
Lua error: Error: Table Wyrmprints not found..
{{#invoke:Icon|Wyrmprint|Heralds of Hinomoto|text=1}}
Lua error: Error: Table Wyrmprints not found..
{{#invoke:Icon|Wyrmprint|Heralds of Hinomoto|size=40px|link=Wyrmprints|text=1}}
Lua error: Error: Table Wyrmprints not found..
-- <includeonly> (prevents literal interpretation of links or categories within the module code)
-- Lua Templating for supporting Template:Icon.
local p = {}
local cargo = mw.ext.cargo
-- Usage: {{#invoke:Icon|Wyrmprint|<name>}}
function p.Wyrmprint(frame)
local name = mw.text.decode(frame.args[1], true)
local wyrmprint = cargoQuery{
tables = 'Wyrmprints',
fields = '_pageName,BaseId,Name',
args = {
where = '_pageName="'..name..'" OR Name="'..name..'"',
groupBy = '_pageName',
limit = 1
}
}[1] -- We only want the first result
if wyrmprint == nil then
return '[['..name..']]'
end
-- Format the content
local pageName = wyrmprint['_pageName']
local baseId = wyrmprint['BaseId']
local link = valueIfNotEmpty(frame.args['link']) or pageName
local size = valueIfNotEmpty(frame.args['size']) or '80px'
local text = frame.args['text'] == '1'
local thumbnail = '[[File:'..baseId..' 01.png|'..size..'|link='..link..']]'
if text then
return thumbnail..' [['..pageName..'|'..wyrmprint['Name']..']]'
else
return thumbnail
end
end
-- Helper functions
function cargoQuery(args)
return cargo.query(args.tables, args.fields, args.args)
end
-- Returns the string if it's not empty, otherwise returns false
function valueIfNotEmpty(s)
if (s == nil or s == '') then
return false
else
return s
end
end
return p
--</includeonly>