106
edits
| (41 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
--<nowiki> | --<nowiki> | ||
local p = {} | local p = {} | ||
local com = require('Module:Common') | |||
local function | local function _requirements(resource, value, link, text, lang) | ||
if string. | --[[ Language switch isn't acctually needed, but stems from early design when | ||
all languages would have a single wiki, leaving in as this may change in the | |||
future ]] | |||
if lang and string.lower(lang) == 'en' then | |||
require('Module:Icon/en') | |||
else | |||
require('Module:Icon/en') -- if no language is supplied or code is invalid, fallback to english | |||
end | end | ||
resource = string.lower(com.trim(resource)) | |||
resource = iconList[resource] | |||
if | if resource ~= nil then | ||
-- Init link here, will be nil if resource is nil | |||
if not com.exists(link) then | |||
link = resource['link'] | |||
end | |||
end | |||
--No point trimming the value if it won't be used | |||
value = com.trim(value) | |||
--Check after trim as may be whitespace only | |||
if com.exists(value) then | |||
value = ' (' .. value .. ')' | |||
else | else | ||
value = '' | |||
end | end | ||
result = | |||
if text | result = '[[file:' | ||
.. resource['file'] | |||
.. '|20px|link=' | |||
.. link | |||
.. ']]' | |||
if com.exists(text) then | |||
if string.lower(text) ~= 'no' then | if string.lower(text) ~= 'no' then | ||
result = result .. '[[' | result = result .. ' [[' | ||
.. link | |||
.. ']]' | |||
end | end | ||
end | end | ||
result = result .. value | |||
else | else | ||
result = 'Icon does not exist[[Category:Missing Icon]]' | result = 'Icon does not exist[[Category:Missing Icon]]' | ||
| Line 48: | Line 53: | ||
function p.requirements(frame) | function p.requirements(frame) | ||
r = | r = frame.args['resource'] | ||
v = frame.args['value'] | v = frame.args['value'] | ||
l = frame.args['link'] | l = frame.args['link'] | ||
t = frame.args[1] | t = frame.args[1] | ||
return _requirements(r, v, l, t) | l = frame.args['lang'] | ||
return _requirements(r, v, l, t, l) | |||
end | |||
function p.icon(resource, value, link, text, lang) | |||
return _requirements(resource, value, link, text, lang) | |||
end | end | ||
function p.iconList(frame) | function p.iconList(frame) | ||
list = | if string.match(string.lower(frame.args[1]), '%[%[file:') ~= nil then | ||
return frame.args[1] .. '[[Category:Material List with Embedded Templates]]' | |||
else | |||
list = string.gsub(string.gsub(frame.args[1], '%[%[', ''), '%]%]', '') | |||
mw.log(list) | |||
list = mw.text.split(list, ';') | |||
result = '' | |||
for k, v in ipairs(list) do | |||
vs = mw.text.split(v, '-') | |||
result = result .. _requirements(vs[1], vs[2], nil, frame.args['text'], frame.args['lang']) | |||
if k ~= table.getn(list) then | |||
result = result .. '<br />' | |||
end | |||
end | end | ||
end | end | ||
return result | return result | ||
end | end | ||
function p.documentation() | function p.documentation(frame) | ||
require('Module:Icon/en') | |||
keys = {} | keys = {} | ||
for z in pairs(iconList) do | for z in pairs(iconList) do | ||
| Line 90: | Line 107: | ||
dataTable[i] = dataTable[i] | dataTable[i] = dataTable[i] | ||
.. '| ' .. v | .. '| ' .. v | ||
.. ' || ' .. _requirements(v, '', '', '') | .. ' || ' .. _requirements(v, '', '', '', '') | ||
.. ' || ' .. iconList[v]['link'] | .. ' || ' .. iconList[v]['link'] | ||
.. '\n|-\n' | .. '\n|-\n' | ||
| Line 98: | Line 115: | ||
i = i + 1 | i = i + 1 | ||
end | end | ||
end | end | ||
edits