More actions
No edit summary |
No edit summary Tag: Reverted |
||
Line 22: | Line 22: | ||
local footer = args.footer or '' | local footer = args.footer or '' | ||
local link = args.link or '' | local link = args.link or '' | ||
if not validTypes[cardType] then | if not validTypes[cardType] then | ||
cardType = 'default' | cardType = 'default' | ||
end | end | ||
if cardType == 'spacer' then | if cardType == 'spacer' then | ||
local div = mw.html.create('div') | local div = mw.html.create('div') | ||
:addClass('vh-card--spacer') | :addClass('vh-card--spacer') | ||
return tostring(div) | return tostring(div) | ||
end | end | ||
local html = mw.html.create('div') | local html = mw.html.create('div') | ||
:addClass('vh-card') | :addClass('vh-card') | ||
:addClass('vh-card--' .. cardType) | :addClass('vh-card--' .. cardType) | ||
-- | -- Header | ||
if title ~= '' or icon ~= '' then | if title ~= '' or icon ~= '' then | ||
local header = html:tag('div') | local header = html:tag('div') | ||
:addClass('vh-card-header') | :addClass('vh-card-header') | ||
if icon ~= '' then | if icon ~= '' then | ||
header:tag('span') | header:tag('span') | ||
Line 50: | Line 47: | ||
:wikitext(icon) | :wikitext(icon) | ||
end | end | ||
if title ~= '' then | if title ~= '' then | ||
local titleElement = header:tag('h3') | local titleElement = header:tag('h3') | ||
:addClass('vh-card-title') | :addClass('vh-card-title') | ||
if link ~= '' then | if link ~= '' then | ||
titleElement:wikitext('[[' .. link .. '|' .. title .. ']]') | titleElement:wikitext('[[' .. link .. '|' .. title .. ']]') | ||
Line 62: | Line 59: | ||
end | end | ||
end | end | ||
-- | -- Content | ||
if content ~= '' then | if content ~= '' then | ||
html:tag('div') | html:tag('div') | ||
Line 69: | Line 66: | ||
:wikitext(content) | :wikitext(content) | ||
end | end | ||
-- | -- Footer | ||
if footer ~= '' then | if footer ~= '' then | ||
html:tag('div') | html:tag('div') | ||
Line 76: | Line 73: | ||
:wikitext(footer) | :wikitext(footer) | ||
end | end | ||
return tostring(html) | return tostring(html) | ||
end | end | ||
function p.group(frame) | function p.group(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local content = args.content or args[1] or '' | local content = args.content or args[1] or '' | ||
local processedContent = frame:preprocess(content) | local processedContent = frame:preprocess(content) | ||
-- Remove automatic paragraphing from MediaWiki by trimming | |||
-- | return '<div class="vh-card-group">\n' .. processedContent .. '\n</div>' | ||
return '<div class="vh-card-group">' .. processedContent .. '</div>' | |||
end | end | ||
function p.quickLink(frame) | function p.quickLink(frame) | ||
Line 105: | Line 91: | ||
local link = args.link or '' | local link = args.link or '' | ||
local description = args.description or '' | local description = args.description or '' | ||
local html = mw.html.create('div') | local html = mw.html.create('div') | ||
:addClass('vh-quick-link-card') | :addClass('vh-quick-link-card') | ||
if icon ~= '' then | if icon ~= '' then | ||
html:tag('div') | html:tag('div') | ||
Line 114: | Line 100: | ||
:wikitext(icon) | :wikitext(icon) | ||
end | end | ||
if title ~= '' then | if title ~= '' then | ||
local titleDiv = html:tag('div') | local titleDiv = html:tag('div') | ||
:addClass('vh-quick-link-title') | :addClass('vh-quick-link-title') | ||
if link ~= '' then | if link ~= '' then | ||
titleDiv:wikitext('[[' .. link .. '|' .. title .. ']]') | titleDiv:wikitext('[[' .. link .. '|' .. title .. ']]') | ||
Line 125: | Line 111: | ||
end | end | ||
end | end | ||
if description ~= '' then | if description ~= '' then | ||
html:tag('div') | html:tag('div') | ||
Line 131: | Line 117: | ||
:wikitext(description) | :wikitext(description) | ||
end | end | ||
return tostring(html) | return tostring(html) | ||
end | end | ||
return p | return p |
Revision as of 09:43, 6 July 2025
Documentation for this module may be created at Module:Card/doc
local p = {}
local validTypes = {
default = true,
primary = true,
success = true,
warning = true,
destructive = true,
spacer = true,
}
function p.main(frame)
local args = frame:getParent().args
return p._main(args)
end
function p._main(args)
local cardType = args.type or 'default'
local icon = args.icon or ''
local title = args.title or ''
local content = args.content or ''
local footer = args.footer or ''
local link = args.link or ''
if not validTypes[cardType] then
cardType = 'default'
end
if cardType == 'spacer' then
local div = mw.html.create('div')
:addClass('vh-card--spacer')
return tostring(div)
end
local html = mw.html.create('div')
:addClass('vh-card')
:addClass('vh-card--' .. cardType)
-- Header
if title ~= '' or icon ~= '' then
local header = html:tag('div')
:addClass('vh-card-header')
if icon ~= '' then
header:tag('span')
:addClass('vh-card-icon')
:wikitext(icon)
end
if title ~= '' then
local titleElement = header:tag('h3')
:addClass('vh-card-title')
if link ~= '' then
titleElement:wikitext('[[' .. link .. '|' .. title .. ']]')
else
titleElement:wikitext(title)
end
end
end
-- Content
if content ~= '' then
html:tag('div')
:addClass('vh-card-content')
:wikitext(content)
end
-- Footer
if footer ~= '' then
html:tag('div')
:addClass('vh-card-footer')
:wikitext(footer)
end
return tostring(html)
end
function p.group(frame)
local args = frame:getParent().args
local content = args.content or args[1] or ''
local processedContent = frame:preprocess(content)
-- Remove automatic paragraphing from MediaWiki by trimming
return '<div class="vh-card-group">\n' .. processedContent .. '\n</div>'
end
function p.quickLink(frame)
local args = frame:getParent().args
local icon = args.icon or ''
local title = args.title or ''
local link = args.link or ''
local description = args.description or ''
local html = mw.html.create('div')
:addClass('vh-quick-link-card')
if icon ~= '' then
html:tag('div')
:addClass('vh-quick-link-icon')
:wikitext(icon)
end
if title ~= '' then
local titleDiv = html:tag('div')
:addClass('vh-quick-link-title')
if link ~= '' then
titleDiv:wikitext('[[' .. link .. '|' .. title .. ']]')
else
titleDiv:wikitext(title)
end
end
if description ~= '' then
html:tag('div')
:addClass('vh-quick-link-desc')
:wikitext(description)
end
return tostring(html)
end
return p