Module:Infobox: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Replaced content with "-- Module:Infobox - streamlined version without SMW dependencies -- <nowiki> local Infobox = {} Infobox.__index = Infobox Infobox.__tostring = Infobox.tostring -- Edit button for unknown params local editbutton = require('Module:Edit button') local edit = editbutton("'''?''' (edit)") -- Standardised "has content" function function hasContent(arg, default) return string.match(arg or '','%S') and arg or default end -- Create a standardised release function, since...")
Tags: Replaced Reverted
No edit summary
Tag: Reverted
Line 1: Line 1:
-- Module:Infobox - streamlined version without SMW dependencies
-- Module:Infobox


-- <nowiki>
local Infobox = {}
local Infobox = {}
Infobox.__index = Infobox
Infobox.__index = Infobox
Line 12: Line 11:
-- Standardised "has content" function
-- Standardised "has content" function
function hasContent(arg, default)
function hasContent(arg, default)
return string.match(arg or '','%S') and arg or default
    return string.match(arg or '','%S') and arg or default
end
end


-- Create a standardised release function, since so many pages use it
-- Standardised "release" function
-- Standardised "release" function for dates
function releaseUpdate(release, update)
function releaseUpdate(release, update)
if not release or string.lower(release) == 'no' then
    -- Assuming release dates are entered in a valid format, return as is
return 'N/A'
    -- Add any additional formatting or checks if needed
end
    return release
if not update or string.lower(update) == 'no' then
return release
end
return string.format('%s ([[Update:%s|Update]])', release, update)
end
end


-- Standardised image function
-- Standardised "image" function for .png images
function image(img)
function image(img)
return img and img:find('%S') and img or nil
    -- Check if the image name ends with '.png', if not, add it
    if img and not img:match('%.png$') then
        img = img .. '.png'
    end
    return img
end
end


-- Standardised numbers
-- Standardised "numbers" function for numeric values
function numbers(num)
function numbers(num)
num = string.gsub(num or '',',','')
    -- Convert to number if possible, else return nil or default value
return tonumber(num)
    return tonumber(num)
end
end
-- Wrap content with line breaks if it contains list-like wiki syntax
function wrapContent(content)
if type(content) == "string" then
local firstListItem = math.min(content:find('^[*#]') or math.huge, content:find('\n[*#]') or math.huge)
if firstListItem ~= math.huge then
local suffix = content:find('\n[*#][^\n]+$') and '\n' or ''
content = content:sub(1, firstListItem - 1) .. '\n' .. content:sub(firstListItem) .. suffix
end
end
return content
end
-- map of names to pre-defined functions, used by Infobox:defineParams
local func_map = {
name = hasContent, -- updated
release = { name = releaseUpdate, params = { 'release', 'update' }, flag = 'p' },
image = image,
numbers = numbers,
}
-- In case the nil_param is needed outside of this module
function Infobox.nilParam()
return nil
end
-- ... [remainder of the code with SMW specific parts removed]


return Infobox
return Infobox
-- </nowiki>

Navigation menu