Modulo:Portalo: Malsamoj inter versioj

[kontrolita revizio][kontrolita revizio]
Enhavo forigita Enhavo aldonita
e traduko de la mesaĝo kaj kategorio en la funkcio "_portal"
aktuala versio el la testejo: Modulo:Portalo/testoj
Linio 1:
--[==[ Version from 2014-06-28
-- This modulo is a Lua implementation of the old {{Portal}} template.
-- Please take care when updating it! It outputs two functions: p.portal, which generates a table of portals, and p.image, which
-- produces the image name for an individual portal.
Linio 38 ⟶ 39:
-- Previously all the images were on one data page at [[Modulo:Portalo/bildoj]], but this had the disadvantage that all
-- 5,000,000 pages using this modulo needed to be refreshed every time an image was added or removed.
 
-- The colors for the background are in the following submodule:
-- [[Modulo:Portalo/koloroj]]
]==]
 
Linio 90 ⟶ 94:
else
return 'Portal-puzzle.svg'
end
end
end
 
-- for colors
local function matchColorPage(s)
-- Finds the appropriate image subpage given a lower-case
-- portal name plus the first letter of that portal name.
if type(s) ~= 'string' or #s < 1 then return end
local firstLetter = mw.ustring.sub(s, 1, 1)
local colorPage
-- if mw.ustring.find(firstLetter, '^[a-z]') then
-- colorPage = 'Modulo:Portalo/koloroj/' .. firstLetter
-- else
-- colorPage= 'Modulo:Portalo/koloroj/alia'
-- end
colorPage = 'Modulo:Portalo/koloroj'
local colors = mw.loadData(colorPage)
local color = colors[s]
if color then
return color
end
end
 
local function getColorName(s)
-- Gets the image name for a given string.
if type(s) ~= 'string' or #s < 1 then
return '#B9B9B9'
end
s = mw.ustring.lower(s)
local color = matchColorPage(s)
if color then
return color
else
local alias = getAlias(s)
color = matchColorPage(alias) -- If no alias was found this returns nil.
if color then
return color
else
return '#B9B9B9'
end
end
Linio 102 ⟶ 146:
.addClass('portal')
.css('border', 'solid #aaa 1px')
.css('text-align', 'center')
.css('margin', args.margin or (args.left == 'yes' and '0.5em 1em 0.5em 0') or '0.5em 0 0.5em 1em')
.newline()
Linio 108 ⟶ 153:
local tableroot = root.tag('table')
.css('background', '#f9f9f9')
.css('font-size', '8590%')
.css('line-height', '110%')
.css('max-width', '175px210px')
.css('width', type(args.boxsize) == 'string' and (args.boxsize .. 'px'))
.css('padding', '1ex')
-- If no portals have been specified, display an error and add the page to a tracking category.
Linio 117 ⟶ 163:
tableroot.wikitext('<strong class="error">Neniuj portaloj difinitaj: bonvolu difini almenaŭ unu portalon</strong>[[Kategorio:Portalaj ŝablonoj sen parametro]]')
end
-- some variables for variant
local variant = args.varianto
-- local text
if variant == "longa" then
text = "'''Rilataj artikoloj troviĝas en''' <br />"
else
text = ""
end
 
-- Display the portals specified in the positional arguments.
for i, portal in ipairs(portals) do
local image = getImageName(portal)
local color = getColorName(portal)
-- Generate the html for the image and the portal name.
tableroot
Linio 132 ⟶ 187:
.done()
.tag('td')
-- .css('padding', '0 0.2em')
.css('padding', '0 1ex')
.css('vertical-align', 'middle')
.css('font-style', 'italic')
.css('font-weight', 'bold')
.wikitext(mw.ustring.format(text .. '[[Portalo:%s|<span style="color:white; padding:0.5px .7ex; display: block; background: ' .. color .. '">Portalo pri %s%s</span>]]', portal, portal, args['break'] and '<br />' or ' '))
end
return tostring(root)