ਮੌਡਿਊਲ:ParticlesThis module was used to replace {{Subatomic particle}} in List of baryons to remove that article from Category:Pages where template include size is exceeded. Prior to the replacement, half of the article was not displayed correctly. Usage
These items are built-in to the module:
Any other item must an identifier for a particle (not case sensitive). If an item is not recognized, an error message is displayed. Each identifier is defined in Module:Particles/data. Any br item divides the result into lines, and each line is enclosed in a nowrap span. If there are no br items, the result is a single line enclosed in a nowrap span. Examples
ModulesThe following modules are used:
-- Low-overhead version of {{Subatomic particle|...}} to avoid exceeding
-- template include size at [[List of baryons]].
local particleTable, supsub
local function stripToNil(text)
-- If text is a string, return its trimmed content, or nil if empty.
-- Otherwise return text (which may, for example, be nil).
if type(text) == 'string' then
text = text:match('(%S.-)%s*$')
end
return text
end
local BREAK = "__BR__"
-- A group is a list of one or more particles with optional separating text.
-- Some items are defined with special meanings:
-- Parameter Output
-- / " / "
-- + " + "
-- or " or "
-- seen " (seen) "
-- _word1_word2 " word1 word2" (wordN is any text)
-- (text) "(text)" (text is any text)
-- br "<br />" (and separates the group into logical lines)
-- Each logical line in the final text is in a nowrap span.
local Group
Group = {
add = function (self, item)
if item ~= nil then
if item == BREAK then
self:purgeCurrent()
else
self.nrCurrent = self.nrCurrent + 1
self.current[self.nrCurrent] = item
end
end
end,
new = function ()
return setmetatable({
nrCurrent = 0,
current = {},
nrLines = 0,
lines = {},
}, Group)
end,
purgeCurrent = function (self)
if self.nrCurrent > 0 then
self.nrLines = self.nrLines + 1
self.lines[self.nrLines] =
'<span style="white-space:nowrap;">' ..
table.concat(self.current) ..
'</span>'
self.nrCurrent = 0
self.current = {}
end
end,
text = function (self)
self:purgeCurrent()
return table.concat(self.lines, '<br />')
end,
}
Group.__index = Group
local keyitems = {
['/'] = " / ",
['+'] = " + ",
['or'] = " or ",
['seen'] = " (seen) ",
['br'] = BREAK,
}
local function expand(item, wantLink)
-- Return text after expanding given item.
-- Throw an error if item is not recognized.
local function quit(reason)
reason = reason or 'has an invalid definition'
error('Particle "' .. item .. '" ' .. reason, 0)
end
local function su(sup, sub, align)
local options = {
align = align,
lineHeight = '1.0em',
}
return supsub(sup, sub, options)
end
local kw = keyitems[item]
if kw then
return kw
end
if item:sub(1, 1) == '_' then
return item:gsub('_', ' ')
end
if item:sub(1, 1) == '(' and item:sub(-1) == ')' then
return item -- no space wanted
end
local particle = particleTable[item:lower()] or quit('is not defined')
local prefix, suffix
if wantLink then
prefix = '[[' .. (particle.link or quit('has no link defined')) .. '|'
suffix = ']]'
else
prefix = ''
suffix = ''
end
local symbol = particle[1] or quit('has no symbol defined')
if particle.anti then
symbol = '<span style="text-decoration:overline;">' .. symbol .. '</span>'
end
return
prefix ..
su(particle.TL, particle.BL, 'r') ..
symbol ..
su(particle.TR, particle.BR, 'l') ..
suffix
end
local function main(frame, wantLink)
-- Arguments are passed using #invoke in an article to avoid double-expansion.
local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''
particleTable = mw.loadData('Module:Particles/data' .. sandbox).particles
supsub = require('Module:Su')._main
local group = Group.new()
for _, arg in ipairs(frame.args) do
arg = stripToNil(arg)
if arg then
group:add(expand(arg, wantLink))
end
end
return group:text()
end
local function link(frame)
return main(frame, true)
end
local function nolink(frame)
return main(frame, false)
end
return {
link = link,
nolink = nolink,
}
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia