Module
WorldPills
From Dogcraft Wiki
(adding multi world support) |
m (smaller world pills) |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} --p stands for package | local p = {} --p stands for package | ||
local worldTools = require('Module:World') | |||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
function pill (text, color) | function pill (text, color) | ||
return ('[[' .. text .. '|<span class="world-pill" style="background:' .. color .. | return ('[[' .. text .. '|<span class="world-pill" style="background:' .. color .. | ||
'; padding: 3px 7px; color: white | '; padding: 3px 7px; color: white; border-radius: 7.5px; display: inline-block; margin-bottom:3px; font-size: 12px; letter-spacing: .4px;">' .. text .. '</span>]]') | ||
end | end | ||
Line 38: | Line 12: | ||
function p.single(frame) | function p.single(frame) | ||
color = frame.args[color] or 'lightslategray' | color = frame.args[color] or 'lightslategray' | ||
world = | world= worldTools.extractWorld(frame.args[1] .. frame.args[2]) | ||
subworld = | subworld = worldTools.extractSubworld(frame.args[1] .. frame.args[2]) | ||
if (subworld ~= '') then | if (subworld ~= '') then | ||
return (pill(world, color) .. ' ' .. pill(subworld, color)) | return (pill(lang:ucfirst(world), color) .. ' ' .. pill(lang:ucfirst(subworld), color)) | ||
elseif (world ~= '') then | elseif (world ~= '') then | ||
return (pill(world, color)) | return (pill(lang:ucfirst(world), color)) | ||
else | else | ||
return '' | return '' | ||
Line 55: | Line 29: | ||
frame.args[2] = frame.args[2] or '' | frame.args[2] = frame.args[2] or '' | ||
input = mw.ustring.lower(frame.args[1] .. frame.args[2]) | input = mw.ustring.lower(frame.args[1] .. frame.args[2]) | ||
out = '' | out = '' | ||
for key,value in ipairs(worlds) do | for key,value in ipairs(worldTools.worlds) do | ||
if (mw.ustring.find(input, value, 1, true) ~= nil) then | if (mw.ustring.find(input, value, 1, true) ~= nil) then | ||
value = lang:ucfirst(value) | value = lang:ucfirst(value) | ||
out = out .. pill(value, color) .. ' ' | out = out .. pill(value, color) .. ' ' | ||
end | end | ||
end | end | ||
Latest revision as of 01:25, 6 September 2024
Documentation for this module may be created at Module:WorldPills/doc
local p = {} --p stands for package
local worldTools = require('Module:World')
local lang = mw.language.getContentLanguage()
function pill (text, color)
return ('[[' .. text .. '|<span class="world-pill" style="background:' .. color ..
'; padding: 3px 7px; color: white; border-radius: 7.5px; display: inline-block; margin-bottom:3px; font-size: 12px; letter-spacing: .4px;">' .. text .. '</span>]]')
end
function p.single(frame)
color = frame.args[color] or 'lightslategray'
world= worldTools.extractWorld(frame.args[1] .. frame.args[2])
subworld = worldTools.extractSubworld(frame.args[1] .. frame.args[2])
if (subworld ~= '') then
return (pill(lang:ucfirst(world), color) .. ' ' .. pill(lang:ucfirst(subworld), color))
elseif (world ~= '') then
return (pill(lang:ucfirst(world), color))
else
return ''
end
end
function p.multi(frame)
color = frame.args[color] or 'lightslategray'
frame.args[2] = frame.args[2] or ''
input = mw.ustring.lower(frame.args[1] .. frame.args[2])
out = ''
for key,value in ipairs(worldTools.worlds) do
if (mw.ustring.find(input, value, 1, true) ~= nil) then
value = lang:ucfirst(value)
out = out .. pill(value, color) .. ' '
end
end
return out
end
return p