Модуль:Карточка: различия между версиями

мНет описания правки
мНет описания правки
Метки: с мобильного устройства из мобильной версии через расширенный мобильный режим
 
(не показано 9 промежуточных версий этого же участника)
Строка 1: Строка 1:
-- DRUID Infobox.
-- DRUID Infobox.
-- source: https://support.wiki.gg/wiki/Module:Infobox
-- source: https://support.wiki.gg/wiki/Module:Infobox
-- license: CC BY-SA 4.0
-- license: CC BY-SA 4.0


-- version 0.1.7
-- version 0.1.7
Строка 17: Строка 17:
-- set to `nil` (not in quotes) to remove such rows altogether in the tabs where they're missing
-- set to `nil` (not in quotes) to remove such rows altogether in the tabs where they're missing
local TABBED_NONEXIST = nil -- `''` or `nil` or `'N/A'` etc. Don't put nil in quotes.
local TABBED_NONEXIST = nil -- `''` or `nil` or `'N/A'` etc. Don't put nil in quotes.
local SKIP_SECTIONS_DEFAULT = 2


---------------------------------------------------------------------------
---------------------------------------------------------------------------
Строка 37: Строка 38:


function p.preprocess(frame)
function p.preprocess(frame)
    return frame:preprocess(frame.args[1] or frame:getParent().args[1])
  local rawText = frame.args[1] or frame:getParent().args[1]
  return frame:preprocess(rawText)
end
end


Строка 46: Строка 48:
local sep = args.sep or ','
local sep = args.sep or ','
h.castArgs(args, sep)
h.castArgs(args, sep)
local skip = tonumber(args.skipSections) or SKIP_SECTIONS_DEFAULT
h.skipSections = skip
h.printCount = 0
if h.castBool(args.setmainimage or 'yes') then
if h.castBool(args.setmainimage or 'yes') then
    h.setMainImage(args.images[1])
--h.setMainImage(args.images[1])
end
end
    -- suggest to use HIDDENCAT here; will be used for maintenance & gadget imports
-- suggest to use HIDDENCAT here; will be used for maintenance & gadget imports
return h.makeInfobox(args, sep), '[[Category:Pages with DRUID infoboxes]]'
local output = h.makeInfobox(args, sep)
local finalOutput = tostring(output)
return frame:preprocess(finalOutput)
end
end


Строка 131: Строка 138:
function h.setMainImage(file)
function h.setMainImage(file)
if h.counter > 1 then return end
if h.counter > 1 then return end
    if not file then return end
if not file then return end
    local fileText = file:gsub('.-:', '')
local fileText = file:gsub('.-:', '')
fileText = fileText:gsub('^([^|%]]+).*', '%1')
fileText = fileText:gsub('^([^|%]]+).*', '%1')
-- setmainimage is guaranteed to exist on wiki.gg but may not exist on other wikis
-- setmainimage is guaranteed to exist on wiki.gg but may not exist on other wikis
Строка 149: Строка 156:
:addClass(args.class) -- warning: class can be nil, don't concat anything
:addClass(args.class) -- warning: class can be nil, don't concat anything
:attr('id', args.id or ('druid-container-' .. h.counter))
:attr('id', args.id or ('druid-container-' .. h.counter))
if args.style then
out:cssText(args.style)
end
h.runHook('onMakeOutputStart', out, args)
h.runHook('onMakeOutputStart', out, args)
if args.kind then out:addClass('druid-container-' .. h.escape(args.kind)) end
if args.kind then out:addClass('druid-container-' .. h.escape(args.kind)) end
Строка 154: Строка 166:
h.printImages(out, args.images, args)
h.printImages(out, args.images, args)
for _, section in ipairs(args.sections) do
for _, section in ipairs(args.sections) do
-- cannot begin tagging here because we don't know if any applicable args are present
local cols = args[section .. '_columns']
local cols = args[section .. '_columns']
local makeSection = cols and h.makeGridSection or h.makeSection
local makeSection = cols and h.makeGridSection or h.makeSection
out:node(makeSection(section, args[section], args, tonumber(cols)))
local secNode = makeSection(section, args[section], args, tonumber(cols))
if secNode then
out:node(secNode)
end
end
end
h.runHook('onMakeOutputEnd', out, args)
h.runHook('onMakeOutputEnd', out, args)
-- category for gadget loading
return out
return out, '[[Category:Pages with DRUID infoboxes]]'
end
end


Строка 376: Строка 389:
local shouldPrintItem = h.printData(node, item, section, args)
local shouldPrintItem = h.printData(node, item, section, args)
if shouldPrintItem then
if shouldPrintItem then
h.printCount = h.printCount + 1
shouldPrint = true
shouldPrint = true
local tr = container:tag(h.getTag('row'))
local tr = container:tag(h.getTag('row'))
Строка 419: Строка 433:
local a, b = sizeOfLastRow, numCols
local a, b = sizeOfLastRow, numCols
while b ~= 0 do
while b ~= 0 do
    a, b = b, a % b
a, b = b, a % b
end
end
local lcm = sizeOfLastRow * numCols / a
local lcm = sizeOfLastRow * numCols / a
Строка 479: Строка 493:


function h.printSectionHeader(node, section, args)
function h.printSectionHeader(node, section, args)
local fields = args[section] or {}
local hasContent = args[section .. '_columns']
and (h.countItems(fields, section, args) > 0)
  or (function()
for _, item in ipairs(fields) do
if h.printData(mw.html.create(), item, section, args) then
return true
end
end
return false
end)()
if not hasContent then return end
if h.castBool(args[section .. '_nolabel']) then return end
if h.castBool(args[section .. '_nolabel']) then return end
h.printCount = h.printCount + 1
if h.printCount <= h.skipSections then
return
end
local tr = node:tag(h.getTag('row'))
local tr = node:tag(h.getTag('row'))
:attr('data-druid-section', h.escape(section))
:attr('data-druid-section', h.escape(section))
Строка 493: Строка 527:
end
end
end
end
local emptySections = {}
local emptySections = {}
for _, label in ipairs(args.tabs) do
for _, label in ipairs(args.tabs) do
Строка 674: Строка 709:
end
end


return mw.getCurrentFrame():preprocess(p)
return p