Difference between revisions of "Module:Icon"

Jump to navigation Jump to search
no edit summary
 
(12 intermediate revisions by 2 users not shown)
Line 2: Line 2:
local p = {}
local p = {}
local com = require('Module:Common')
local com = require('Module:Common')
require('Module:Icon/data')


local function _requirements(resource, value, link, text)
 
local function _requirements(resource, value, link, text, lang)
--[[ 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
resource = string.lower(com.trim(resource))
resource = string.lower(com.trim(resource))
resource = iconList[resource]
resource = iconList[resource]
Line 10: Line 18:
if resource ~= nil then
if resource ~= nil then
-- Init link here, will be nil if resource is nil
-- Init link here, will be nil if resource is nil
if com.exists(link) == false then
if not com.exists(link) then
link = resource['link']
link = resource['link']
end
end
Line 22: Line 30:
value = ''
value = ''
end
end
 
result = '[[file:'  
result = '[[file:'  
.. resource['file']  
.. resource['file']  
.. '|16px|link='
.. '|20px|link='
.. link
.. link
.. ']]'
.. ']]'
Line 32: Line 39:
if com.exists(text) then
if com.exists(text) then
if string.lower(text) ~= 'no' then
if string.lower(text) ~= 'no' then
result = result .. '[['
result = result .. ' [['
.. link
.. link
.. ']]'
.. ']]'
Line 50: Line 57:
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
end


function p.icon(resource, value, link, text)
function p.icon(resource, value, link, text, lang)
return _requirements(resource, value, link, text)
return _requirements(resource, value, link, text, lang)
end
end


function p.iconList(frame)
function p.iconList(frame)
list = string.gsub(string.gsub(frame.args[1], '%[%[', ''), '%]%]', '')
if string.match(string.lower(frame.args[1]), '%[%[file:') ~= nil then
-- list = string.gsub(string.gsub(list, '%{%{item%|', ''), '%}%}', '')
return frame.args[1] .. '[[Category:Material List with Embedded Templates]]'
-- list = string.gsub(list, '<br%s>', ';')
else
-- list = string.gsub(list, '%|', '-')
list = string.gsub(string.gsub(frame.args[1], '%[%[', ''), '%]%]', '')
mw.log(list)
mw.log(list)
list = mw.text.split(list, ';')
list = mw.text.split(list, ';')
result = ''
result = ''
for k, v in ipairs(list) do
for k, v in ipairs(list) do
vs = mw.text.split(v, '-')
vs = mw.text.split(v, '-')
result = result .. _requirements(vs[1], vs[2], nil, frame.args['text'])
result = result .. _requirements(vs[1], vs[2], nil, frame.args['text'], frame.args['lang'])
if k ~= table.getn(list) then
if k ~= table.getn(list) then
result = result .. '<br />'
result = result .. '<br />'
end
end
end
end
end
Line 76: Line 85:
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 97: 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'
106

edits

Navigation menu