Documentation for this module may be created at Module:Card/doc
local getArgs = require( 'Module:Arguments' ).getArgs
local p = {}
function getStyle(args,cardcount)
local style = ""
if args["colorbg"..tostring(cardcount)] then
style = "background: "..args["colorbg"..tostring(cardcount)]
end
if args["colortext"..tostring(cardcount)] then
style = "color: "..args["colortext"..tostring(cardcount)]
end
return style
end
function getByline(args,n,mode)
local n = tostring(n)
if args["byline"..mode..n] then
local div = mw.html.create("div")
div:addClass("byline-"..mode)
div:wikitext(args["byline"..mode..n])
if args["colorbyline"..n] then
div:css("color", args["colorbyline"..n])
end
return tostring(div)
end
return ""
end
function setTitle(args,n)
local n = tostring(n)
if args["title"..n] then
local div = mw.html.create("div")
div:addClass("card-title")
div:wikitext(args["title"..n])
if args["colortitle"..n] then
div:css("color",args["colortitle"..n])
end
return tostring(div)
end
return ""
end
function createTopCard(args,count)
local div = mw.html.create("div")
div:addClass("card-top")
local text = ""
if args["text"..tostring(count)] then
text = args["text"..tostring(count)]
end
div:wikitext(getByline(args,count,"top"),setTitle(args,count),getByline(args,count,"bottom"),text)
return tostring(div)
end
function createBottomCard(args,n)
local n = tostring(n)
if args["bottom"..n] then
local div = mw.html.create("div")
div:addClass("card-bottom")
div:wikitext(args["bottom"..n])
if args["colorbgbottom"..n] then
div:css("background",args["colorbgbottom"..n])
end
if args["colorbottom"..n] then
div:css("color",args["colorbottom"..n])
end
return tostring(div)
end
return ""
end
function createButton(frame,args,n)
local n = tostring(n)
if args["page"..n] or args["pagelink"..n] then
local div = mw.html.create("div")
div:addClass("card-button")
local shownText = "|"..args["pagetext"..n] or ""
local text
if args["pagelink"..n] then
text = "["..args["pagelink"..n]..shownText.."]"
else
text = "[["..args["page"..n]..shownText.."]]"
end
div:wikitext(text)
if args["colorbgbutton"..n] then
div:css("background",args["colorbgbutton"..n])
end
return tostring(div)
end
return ""
end
function generate(frame,args,n,o)
local divRow = mw.html.create("div")
divRow:addClass("card-row")
for cardcount = n,o do
local div = mw.html.create("div")
div:addClass("card")
if column then
div:addClass("card-col"..tostring(column))
end
div:css(getStyle(args,cardcount))
div:wikitext(createTopCard(args,cardcount),createBottomCard(args,cardcount),createButton(frame,args,cardcount))
divRow:wikitext(tostring(div))
end
return tostring(divRow)
end
function p.main(frame)
local args = getArgs(frame)
local container = mw.html.create("div")
container:addClass("card-container")
if args.wide then
container:addClass("floatnone")
end
for i=1,args.row or 1 do
container:wikitext(generate(frame,args,(i*args.column)-args.column+1,i*args.column))
end
return tostring(container)
end
return p