https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AParticles Module:Particles - Revision history 2025-05-27T19:59:26Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.2 https://en.wikipedia.org/w/index.php?title=Module:Particles&diff=831353959&oldid=prev Johnuniq: better error message if a particle has no link defined 2018-03-20T04:25:52Z <p>better error message if a particle has no link defined</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 04:25, 20 March 2018</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 99:</td> <td colspan="2" class="diff-lineno">Line 99:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local prefix, suffix</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local prefix, suffix</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if wantLink then</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if wantLink then</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> prefix = '[[' .. (particle.link or quit()) .. '|'</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> prefix = '[[' .. (particle.link or quit(<ins style="font-weight: bold; text-decoration: none;">'has no link defined'</ins>)) .. '|'</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> suffix = ']]'</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> suffix = ']]'</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td> </tr> <tr> <td colspan="2" class="diff-lineno">Line 105:</td> <td colspan="2" class="diff-lineno">Line 105:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> suffix = ''</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> suffix = ''</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> local symbol = particle[1] or quit()</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local symbol = particle[1] or quit(<ins style="font-weight: bold; text-decoration: none;">'has no symbol defined'</ins>)</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if particle.anti then</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if particle.anti then</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> symbol = '&lt;span style="text-decoration:overline;"&gt;' .. symbol .. '&lt;/span&gt;'</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> symbol = '&lt;span style="text-decoration:overline;"&gt;' .. symbol .. '&lt;/span&gt;'</div></td> </tr> </table> Johnuniq https://en.wikipedia.org/w/index.php?title=Module:Particles&diff=830971834&oldid=prev Johnuniq: efficient implementation of Template:Subatomic particle for List of baryons or other related articles with template expansion size problem 2018-03-18T00:30:09Z <p>efficient implementation of <a href="/wiki/Template:Subatomic_particle" title="Template:Subatomic particle">Template:Subatomic particle</a> for <a href="/wiki/List_of_baryons" title="List of baryons">List of baryons</a> or other related articles with template expansion size problem</p> <p><b>New page</b></p><div>-- Low-overhead version of {{Subatomic particle|...}} to avoid exceeding<br /> -- template include size at [[List of baryons]].<br /> <br /> local particleTable, supsub<br /> <br /> local function stripToNil(text)<br /> -- If text is a string, return its trimmed content, or nil if empty.<br /> -- Otherwise return text (which may, for example, be nil).<br /> if type(text) == &#039;string&#039; then<br /> text = text:match(&#039;(%S.-)%s*$&#039;)<br /> end<br /> return text<br /> end<br /> <br /> local BREAK = &quot;__BR__&quot;<br /> <br /> -- A group is a list of one or more particles with optional separating text.<br /> -- Some items are defined with special meanings:<br /> -- Parameter Output<br /> -- / &quot; / &quot;<br /> -- + &quot; + &quot;<br /> -- or &quot; or &quot;<br /> -- seen &quot; (seen) &quot;<br /> -- _word1_word2 &quot; word1 word2&quot; (wordN is any text)<br /> -- (text) &quot;(text)&quot; (text is any text)<br /> -- br &quot;&lt;br /&gt;&quot; (and separates the group into logical lines)<br /> -- Each logical line in the final text is in a nowrap span.<br /> local Group<br /> Group = {<br /> add = function (self, item)<br /> if item ~= nil then<br /> if item == BREAK then<br /> self:purgeCurrent()<br /> else<br /> self.nrCurrent = self.nrCurrent + 1<br /> self.current[self.nrCurrent] = item<br /> end<br /> end<br /> end,<br /> new = function ()<br /> return setmetatable({<br /> nrCurrent = 0,<br /> current = {},<br /> nrLines = 0,<br /> lines = {},<br /> }, Group)<br /> end,<br /> purgeCurrent = function (self)<br /> if self.nrCurrent &gt; 0 then<br /> self.nrLines = self.nrLines + 1<br /> self.lines[self.nrLines] =<br /> &#039;&lt;span style=&quot;white-space:nowrap;&quot;&gt;&#039; ..<br /> table.concat(self.current) ..<br /> &#039;&lt;/span&gt;&#039;<br /> self.nrCurrent = 0<br /> self.current = {}<br /> end<br /> end,<br /> text = function (self)<br /> self:purgeCurrent()<br /> return table.concat(self.lines, &#039;&lt;br /&gt;&#039;)<br /> end,<br /> }<br /> Group.__index = Group<br /> <br /> local keyitems = {<br /> [&#039;/&#039;] = &quot; / &quot;,<br /> [&#039;+&#039;] = &quot; + &quot;,<br /> [&#039;or&#039;] = &quot; or &quot;,<br /> [&#039;seen&#039;] = &quot; (seen) &quot;,<br /> [&#039;br&#039;] = BREAK,<br /> }<br /> <br /> local function expand(item, wantLink)<br /> -- Return text after expanding given item.<br /> -- Throw an error if item is not recognized.<br /> local function quit(reason)<br /> reason = reason or &#039;has an invalid definition&#039;<br /> error(&#039;Particle &quot;&#039; .. item .. &#039;&quot; &#039; .. reason, 0)<br /> end<br /> local function su(sup, sub, align)<br /> local options = {<br /> align = align,<br /> lineHeight = &#039;1.0em&#039;,<br /> }<br /> return supsub(sup, sub, options)<br /> end<br /> local kw = keyitems[item]<br /> if kw then<br /> return kw<br /> end<br /> if item:sub(1, 1) == &#039;_&#039; then<br /> return item:gsub(&#039;_&#039;, &#039; &#039;)<br /> end<br /> if item:sub(1, 1) == &#039;(&#039; and item:sub(-1) == &#039;)&#039; then<br /> return item -- no space wanted<br /> end<br /> local particle = particleTable[item:lower()] or quit(&#039;is not defined&#039;)<br /> local prefix, suffix<br /> if wantLink then<br /> prefix = &#039;[[&#039; .. (particle.link or quit()) .. &#039;|&#039;<br /> suffix = &#039;]]&#039;<br /> else<br /> prefix = &#039;&#039;<br /> suffix = &#039;&#039;<br /> end<br /> local symbol = particle[1] or quit()<br /> if particle.anti then<br /> symbol = &#039;&lt;span style=&quot;text-decoration:overline;&quot;&gt;&#039; .. symbol .. &#039;&lt;/span&gt;&#039;<br /> end<br /> return<br /> prefix ..<br /> su(particle.TL, particle.BL, &#039;r&#039;) ..<br /> symbol ..<br /> su(particle.TR, particle.BR, &#039;l&#039;) ..<br /> suffix<br /> end<br /> <br /> local function main(frame, wantLink)<br /> -- Arguments are passed using #invoke in an article to avoid double-expansion.<br /> local sandbox = frame:getTitle():find(&#039;sandbox&#039;, 1, true) and &#039;/sandbox&#039; or &#039;&#039;<br /> particleTable = mw.loadData(&#039;Module:Particles/data&#039; .. sandbox).particles<br /> supsub = require(&#039;Module:Su&#039;)._main<br /> local group = Group.new()<br /> for _, arg in ipairs(frame.args) do<br /> arg = stripToNil(arg)<br /> if arg then<br /> group:add(expand(arg, wantLink))<br /> end<br /> end<br /> return group:text()<br /> end<br /> <br /> local function link(frame)<br /> return main(frame, true)<br /> end<br /> <br /> local function nolink(frame)<br /> return main(frame, false)<br /> end<br /> <br /> return {<br /> link = link,<br /> nolink = nolink,<br /> }</div> Johnuniq