Module:RCChronology: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
local checkParams = require("Module:Check for unknown parameters") | |||
local p = {} | local p = {} | ||
Line 81: | Line 82: | ||
end | end | ||
function p.makeRcRow(frame) | function p.makeRcRow(frame) | ||
local args = frame.args | local args = frame.args | ||
Line 92: | Line 92: | ||
local use_cor = args["use_cor#"] | local use_cor = args["use_cor#"] | ||
local title_fallback = args["title"] | local title_fallback = args["title"] | ||
-- Only show the row if either prev or next is given | -- Only show the row if either prev or next is given | ||
Line 103: | Line 98: | ||
end | end | ||
-- Check required numbering parameters - rc# or cor# | |||
if not rcnum and not cornum then | |||
-- Known parameters in your template/module | |||
local knownParams = { | |||
"prev_rc_title", "this_rc_title", "next_rc_title", | |||
"rc#", "cor#", "use_cor#", "title" | |||
} | |||
-- Run check for missing numbering param, show preview warning only | |||
-- using preview= so it only shows in preview and edit mode | |||
local checkResult = checkParams._check( | |||
knownParams, -- valid parameters | |||
args, -- actual args passed | |||
{ unknown = "", preview = "Please provide either rc# or cor# in the infobox." } | |||
) | |||
-- Return check warning message + table output | |||
return checkResult .. p._renderTable(prev, this, next_, rcnum, cornum, use_cor, title_fallback) | |||
end | |||
-- Otherwise, just render normally | |||
return p._renderTable(prev, this, next_, rcnum, cornum, use_cor, title_fallback) | |||
end | |||
-- Extracted rendering function so it can be called twice above | |||
function p._renderTable(prev, this, next_, rcnum, cornum, use_cor, title_fallback) | |||
local row = '<table style="background: transparent; color: inherit; width: 100%; min-width: 100%; border-collapse: collapse; display: inline-table;">\n' | local row = '<table style="background: transparent; color: inherit; width: 100%; min-width: 100%; border-collapse: collapse; display: inline-table;">\n' | ||
row = row .. '<tr style="line-height: 1.4em;">\n' | row = row .. '<tr style="line-height: 1.4em;">\n' | ||
Line 109: | Line 130: | ||
row = row .. makeNextCell(next_, rcnum, cornum, use_cor) | row = row .. makeNextCell(next_, rcnum, cornum, use_cor) | ||
row = row .. '</tr></table>' | row = row .. '</tr></table>' | ||
return row | return row | ||
end | end | ||
return p | return p |
Revision as of 10:34, 3 July 2025
Documentation for this module may be created at Module:RCChronology/doc
local checkParams = require("Module:Check for unknown parameters")
local p = {}
-- Helper function: builds the "previous" cell
local function makePrevCell(prev, rcnum, cornum, use_cor)
if not prev or prev == "" then
return '<td style="width: 33%; padding: .2em .1em .2em .1em;"></td>'
end
local info = '"' .. prev .. '"'
local detail = ""
if use_cor and use_cor:lower() == "yes" then
if cornum then
detail = string.format("<br />(COR# %d)", cornum - 1)
end
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum - 1)
elseif cornum then
detail = string.format("<br />(COR# %d)", cornum - 1)
end
return string.format(
'<td style="width: 33%%; text-align: center; vertical-align: top; padding: .2em .1em .2em .1em;">%s%s</td>',
info, detail
)
end
-- Helper function: builds the "current" cell
local function makeThisCell(this, rcnum, cornum, use_cor, title_fallback)
local display_title
if this and this ~= "" then
display_title = this
elseif title_fallback and title_fallback ~= "" then
display_title = title_fallback
else
display_title = mw.title.getCurrentTitle().rootText or "Unknown"
end
local info = '"' .. "'''" .. display_title .. "'''" .. '"'
local detail = ""
if use_cor and use_cor:lower() == "yes" then
if cornum then
detail = string.format("<br />(COR# %d)", cornum)
end
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum)
elseif cornum then
detail = string.format("<br />(COR# %d)", cornum)
end
return string.format(
'<td style="width: 33%%; text-align: center; vertical-align: top; padding: .2em .1em .2em .1em;">%s%s</td>',
info, detail
)
end
-- Helper function: builds the "next" cell
local function makeNextCell(next_, rcnum, cornum, use_cor)
if not next_ or next_ == "" then
return '<td style="width: 33%; padding: .2em .1em .2em .1em;"></td>'
end
local info = '"' .. next_ .. '"'
local detail = ""
if use_cor and use_cor:lower() == "yes" then
if cornum then
detail = string.format("<br />(COR# %d)", cornum + 1)
end
elseif rcnum then
detail = string.format("<br />(RC# %d)", rcnum + 1)
elseif cornum then
detail = string.format("<br />(COR# %d)", cornum + 1)
end
return string.format(
'<td style="width: 33%%; text-align: center; vertical-align: top; padding: .2em .1em .2em .1em;">%s%s</td>',
info, detail
)
end
function p.makeRcRow(frame)
local args = frame.args
local prev = args["prev_rc_title"]
local this = args["this_rc_title"]
local next_ = args["next_rc_title"]
local rcnum = tonumber(args["rc#"])
local cornum = tonumber(args["cor#"])
local use_cor = args["use_cor#"]
local title_fallback = args["title"]
-- Only show the row if either prev or next is given
if not (prev and prev ~= "") and not (next_ and next_ ~= "") then
return ""
end
-- Check required numbering parameters - rc# or cor#
if not rcnum and not cornum then
-- Known parameters in your template/module
local knownParams = {
"prev_rc_title", "this_rc_title", "next_rc_title",
"rc#", "cor#", "use_cor#", "title"
}
-- Run check for missing numbering param, show preview warning only
-- using preview= so it only shows in preview and edit mode
local checkResult = checkParams._check(
knownParams, -- valid parameters
args, -- actual args passed
{ unknown = "", preview = "Please provide either rc# or cor# in the infobox." }
)
-- Return check warning message + table output
return checkResult .. p._renderTable(prev, this, next_, rcnum, cornum, use_cor, title_fallback)
end
-- Otherwise, just render normally
return p._renderTable(prev, this, next_, rcnum, cornum, use_cor, title_fallback)
end
-- Extracted rendering function so it can be called twice above
function p._renderTable(prev, this, next_, rcnum, cornum, use_cor, title_fallback)
local row = '<table style="background: transparent; color: inherit; width: 100%; min-width: 100%; border-collapse: collapse; display: inline-table;">\n'
row = row .. '<tr style="line-height: 1.4em;">\n'
row = row .. makePrevCell(prev, rcnum, cornum, use_cor)
row = row .. makeThisCell(this, rcnum, cornum, use_cor, title_fallback)
row = row .. makeNextCell(next_, rcnum, cornum, use_cor)
row = row .. '</tr></table>'
return row
end
return p