Module:LinkGridBanner: Difference between revisions
From Jules RNG Wiki
More actions
Created page with "local p = {} function p.render(frame) local args = frame:getParent().args local cards = {} local i = 1 -- Loop to gather data while args['title' .. i] do table.insert(cards, { link = args['link' .. i] or args['title' .. i], title = args['title' .. i], image = args['image' .. i] or 'Default.png', body = args['body' .. i] or '' }) i = i + 1 end -- 1. CONTAINER STYLE..." |
No edit summary |
||
| Line 6: | Line 6: | ||
local i = 1 | local i = 1 | ||
-- Loop to gather data | -- Loop to gather data (same logic as before) | ||
while args['title' .. i] do | while args['title' .. i] do | ||
table.insert(cards, { | table.insert(cards, { | ||
link = args['link' .. i] or args['title' .. i], | link = args['link' .. i] or args['title' .. i], | ||
title = args['title' .. i], | title = args['title' .. i], | ||
image = args['image' .. i] or 'Default.png', | image = args['image' .. i] or 'Default.png', -- Ensure you have a fallback image! | ||
body = args['body' .. i] or '' | body = args['body' .. i] or '' | ||
}) | }) | ||
| Line 17: | Line 17: | ||
end | end | ||
-- 1. CONTAINER | -- 1. CONTAINER | ||
local containerStyle = { | local containerStyle = { | ||
['display'] = 'flex', | ['display'] = 'flex', | ||
['flex-wrap'] = 'wrap', | ['flex-wrap'] = 'wrap', | ||
['gap'] = '1rem', | ['gap'] = '1rem', | ||
['justify-content'] = 'center' | ['justify-content'] = 'center', | ||
['margin-top'] = '1rem' | |||
} | } | ||
-- 2. CARD | -- 2. CARD | ||
local cardStyle = { | local cardStyle = { | ||
['flex'] = '1 1 300px', | ['flex'] = '1 1 300px', -- Grow/Shrink, Base width 300px | ||
['max-width'] = '32%', | ['max-width'] = '32%', -- Desktop: 3 per row | ||
['border'] = '1px solid var(--border-color-base)', | ['border'] = '1px solid var(--border-color-base)', | ||
['border-radius'] = 'var(--border-radius-base, 12px)', | ['border-radius'] = 'var(--border-radius-base, 12px)', | ||
| Line 34: | Line 35: | ||
['overflow'] = 'hidden', | ['overflow'] = 'hidden', | ||
['background'] = 'var(--color-surface-1)', | ['background'] = 'var(--color-surface-1)', | ||
['display'] = 'flex', | |||
['flex-direction'] = 'column', -- Stack image on top of text | |||
['transition'] = 'transform 0.2s ease', | ['transition'] = 'transform 0.2s ease', | ||
} | } | ||
-- 3. IMAGE | -- 3. BANNER IMAGE AREA | ||
local | local imageWrapperStyle = { | ||
['width'] = '100%', | ['width'] = '100%', | ||
['aspect-ratio'] = '16 / 9', | ['aspect-ratio'] = '16 / 9', -- Forces the rectangle shape | ||
['overflow'] = 'hidden | ['overflow'] = 'hidden', | ||
['position'] = 'relative', | ['position'] = 'relative', | ||
['background'] = 'var(--color-surface-2)' -- | ['background'] = 'var(--color-surface-2)', | ||
['border-bottom'] = '1px solid var(--border-color-base)' | |||
} | } | ||
-- 4. TEXT | -- 4. TEXT CONTENT | ||
local | local contentStyle = { | ||
['padding'] = '15px', | ['padding'] = '15px', | ||
['flex-grow'] = '1', | ['flex-grow'] = '1', -- Pushes content to fill height | ||
['display'] = 'flex', | ['display'] = 'flex', | ||
['flex-direction'] = 'column', | ['flex-direction'] = 'column', | ||
| Line 61: | Line 61: | ||
local titleStyle = { | local titleStyle = { | ||
['font-weight'] = 'bold', | ['font-weight'] = 'bold', | ||
['font-size'] = '1. | ['font-size'] = '1.3em', | ||
['color'] = 'var(--color-base)' | ['color'] = 'var(--color-base)', | ||
['line-height'] = '1.2' | |||
} | } | ||
local | local bodyStyle = { | ||
['color'] = 'var(--color-subtle)', | ['color'] = 'var(--color-subtle)', | ||
['font-size'] = '0.95em', | ['font-size'] = '0.95em', | ||
['line-height'] = '1. | ['line-height'] = '1.5' | ||
} | } | ||
| Line 78: | Line 78: | ||
local cardDiv = root:tag('div'):css(cardStyle) | local cardDiv = root:tag('div'):css(cardStyle) | ||
-- Image | -- A. Banner Image | ||
-- We | -- We wrap the image in a div that clips it | ||
local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle) | |||
cardDiv:tag('div') | |||
-- | -- We insert the file. Note: "class=banner-img" is used by the CSS below | ||
local | imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=banner-img]]', card.image, card.link)) | ||
-- B. Text Content | |||
local textDiv = cardDiv:tag('div'):css(contentStyle) | |||
-- Title | -- Title | ||
textDiv:tag('div') | |||
:css(titleStyle) | :css(titleStyle) | ||
:wikitext(string.format('[[%s|%s]]', card.link, card.title)) | :wikitext(string.format('[[%s|%s]]', card.link, card.title)) | ||
-- Description | -- Body (Description/Stats) | ||
textDiv:tag('div') | |||
:css( | :css(bodyStyle) | ||
:wikitext(card.body) | :wikitext(card.body) | ||
end | end | ||
-- 6. CSS FIX | -- 6. CSS FIX (Crucial for 16:9 cropping) | ||
-- This | -- This CSS forces the image to cover the area (object-fit: cover) | ||
local styles = mw.html.create('style') | |||
local | styles:wikitext([[ | ||
/* Force image to fill the 16:9 box */ | |||
. | .banner-img img { | ||
width: 100% !important; | width: 100% !important; | ||
height: 100% !important; | height: 100% !important; | ||
object-fit: cover !important; | object-fit: cover !important; | ||
display: block !important; | object-position: center; | ||
display: block; | |||
} | |||
/* Mobile: Cards become full width */ | |||
@media (max-width: 768px) { | |||
.citizen-card-grid > div { max-width: 100% !important; } | |||
} | } | ||
]]) | ]]) | ||
return tostring( | return tostring(styles) .. tostring(root) | ||
end | end | ||
return p | return p | ||
Revision as of 04:59, 27 January 2026
Documentation for this module may be created at Module:LinkGridBanner/doc
local p = {}
function p.render(frame)
local args = frame:getParent().args
local cards = {}
local i = 1
-- Loop to gather data (same logic as before)
while args['title' .. i] do
table.insert(cards, {
link = args['link' .. i] or args['title' .. i],
title = args['title' .. i],
image = args['image' .. i] or 'Default.png', -- Ensure you have a fallback image!
body = args['body' .. i] or ''
})
i = i + 1
end
-- 1. CONTAINER
local containerStyle = {
['display'] = 'flex',
['flex-wrap'] = 'wrap',
['gap'] = '1rem',
['justify-content'] = 'center',
['margin-top'] = '1rem'
}
-- 2. CARD
local cardStyle = {
['flex'] = '1 1 300px', -- Grow/Shrink, Base width 300px
['max-width'] = '32%', -- Desktop: 3 per row
['border'] = '1px solid var(--border-color-base)',
['border-radius'] = 'var(--border-radius-base, 12px)',
['box-shadow'] = 'var(--box-shadow-level-1)',
['overflow'] = 'hidden',
['background'] = 'var(--color-surface-1)',
['display'] = 'flex',
['flex-direction'] = 'column', -- Stack image on top of text
['transition'] = 'transform 0.2s ease',
}
-- 3. BANNER IMAGE AREA
local imageWrapperStyle = {
['width'] = '100%',
['aspect-ratio'] = '16 / 9', -- Forces the rectangle shape
['overflow'] = 'hidden',
['position'] = 'relative',
['background'] = 'var(--color-surface-2)',
['border-bottom'] = '1px solid var(--border-color-base)'
}
-- 4. TEXT CONTENT
local contentStyle = {
['padding'] = '15px',
['flex-grow'] = '1', -- Pushes content to fill height
['display'] = 'flex',
['flex-direction'] = 'column',
['gap'] = '8px'
}
local titleStyle = {
['font-weight'] = 'bold',
['font-size'] = '1.3em',
['color'] = 'var(--color-base)',
['line-height'] = '1.2'
}
local bodyStyle = {
['color'] = 'var(--color-subtle)',
['font-size'] = '0.95em',
['line-height'] = '1.5'
}
-- 5. BUILD HTML
local root = mw.html.create('div'):css(containerStyle)
for _, card in ipairs(cards) do
local cardDiv = root:tag('div'):css(cardStyle)
-- A. Banner Image
-- We wrap the image in a div that clips it
local imgDiv = cardDiv:tag('div'):css(imageWrapperStyle)
-- We insert the file. Note: "class=banner-img" is used by the CSS below
imgDiv:wikitext(string.format('[[File:%s|400px|center|link=%s|class=banner-img]]', card.image, card.link))
-- B. Text Content
local textDiv = cardDiv:tag('div'):css(contentStyle)
-- Title
textDiv:tag('div')
:css(titleStyle)
:wikitext(string.format('[[%s|%s]]', card.link, card.title))
-- Body (Description/Stats)
textDiv:tag('div')
:css(bodyStyle)
:wikitext(card.body)
end
-- 6. CSS FIX (Crucial for 16:9 cropping)
-- This CSS forces the image to cover the area (object-fit: cover)
local styles = mw.html.create('style')
styles:wikitext([[
/* Force image to fill the 16:9 box */
.banner-img img {
width: 100% !important;
height: 100% !important;
object-fit: cover !important;
object-position: center;
display: block;
}
/* Mobile: Cards become full width */
@media (max-width: 768px) {
.citizen-card-grid > div { max-width: 100% !important; }
}
]])
return tostring(styles) .. tostring(root)
end
return p