Module:Card: Difference between revisions
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| Line 185: | Line 185: | ||
value = tostring(value or '') | value = tostring(value or '') | ||
-- Converts "Luca: Myriad Meadows" to "Myriad Meadows" | -- Converts "Luca: Myriad Meadows" to "Myriad Meadows". | ||
return mw.text.trim(value:gsub('^.-:%s*', '', 1)) | return mw.text.trim(value:gsub('^.-:%s*', '', 1)) | ||
end | end | ||
| Line 197: | Line 197: | ||
end | end | ||
-- Generates | -- Generates the second icon for a split card. | ||
local function makeSplitIcon(name, mini) | local function makeSplitIcon(name, mini) | ||
name = tostring(name or '') | name = tostring(name or '') | ||
| Line 208: | Line 207: | ||
' Icon.png|' .. | ' Icon.png|' .. | ||
size .. 'x' .. size .. | size .. 'x' .. size .. | ||
'px|link=' .. name .. | 'px|link=' .. | ||
name .. | |||
']]' | ']]' | ||
end | end | ||
| Line 229: | Line 229: | ||
) | ) | ||
-- Base name for assets | -- Base name for assets. | ||
-- Removes a trailing disambiguation such as "(Currency)". | |||
out.image_name = out.name:gsub('%s*%([^()]*%)$', '') | out.image_name = out.name:gsub('%s*%([^()]*%)$', '') | ||
| Line 319: | Line 320: | ||
end | end | ||
-- Caption | -- Caption defaults | ||
if out.show_caption and lib.isEmpty(out.caption) then | if out.show_caption and lib.isEmpty(out.caption) then | ||
if out.data then | if out.data then | ||
| Line 379: | Line 380: | ||
function p._main(args) | function p._main(args) | ||
local a = p._processArgs(args) | local a = p._processArgs(args) | ||
local isSplit = ne(a.split) | local isSplit = ne(a.split) | ||
-- Outer container | |||
local node_container = mw.html.create('div') | local node_container = mw.html.create('div') | ||
:addClass('card-container') | :addClass('card-container') | ||
if isSplit then | if isSplit then | ||
node_container:addClass('recipe-type-split-card') | |||
end | end | ||
| Line 419: | Line 407: | ||
end | end | ||
-- Main image | -- Main image container | ||
local imageContainer = node_card:tag('span') | local imageContainer = node_card:tag('span') | ||
:addClass('card-image-container') | :addClass('card-image-container') | ||
:addClass('card-quality-' .. a.quality) | :addClass('card-quality-' .. a.quality) | ||
-- Split or regular image | |||
if isSplit then | if isSplit then | ||
imageContainer:addClass('recipe-type-split-image') | imageContainer:addClass('recipe-type-split-image') | ||
-- First item: top-left half | |||
imageContainer:tag('span') | imageContainer:tag('span') | ||
:addClass('recipe-type-split-half') | :addClass('recipe-type-split-half') | ||
| Line 432: | Line 422: | ||
:wikitext(a.image_wikitext) | :wikitext(a.image_wikitext) | ||
-- Second item: bottom-right half | |||
imageContainer:tag('span') | imageContainer:tag('span') | ||
:addClass('recipe-type-split-half') | :addClass('recipe-type-split-half') | ||
:addClass('recipe-type-split-half-b') | :addClass('recipe-type-split-half-b') | ||
:wikitext(makeSplitIcon(a.split)) | :wikitext(makeSplitIcon(a.split, a.mini)) | ||
else | else | ||
imageContainer:wikitext(a.image_wikitext) | imageContainer:wikitext(a.image_wikitext) | ||
| Line 490: | Line 481: | ||
-- Caption | -- Caption | ||
-- Split captions are opt-in and use spans instead of list items. | |||
if a.show_caption and isSplit then | if a.show_caption and isSplit then | ||
local node_caption = node_container:tag('span') | local node_caption = node_container:tag('span') | ||
:addClass('card-caption') | :addClass('card-caption') | ||
:addClass('card-split-caption') | :addClass('card-split-caption') | ||
local list = node_caption:tag('span') | local list = node_caption:tag('span') | ||
:addClass('card-split-caption-list') | :addClass('card-split-caption-list') | ||
list:tag('span') | list:tag('span') | ||
:addClass('card-split-caption-item') | :addClass('card-split-caption-item') | ||
:wikitext('[[' .. a.name .. ']]') | :wikitext('[[' .. a.name .. ']]') | ||
list:tag('span') | list:tag('span') | ||
:addClass('card-split-caption-item') | :addClass('card-split-caption-item') | ||
:wikitext('[[' .. a.split .. ']]') | :wikitext('[[' .. a.split .. ']]') | ||
setCaptionWidth(node_caption, a.caption_width) | setCaptionWidth(node_caption, a.caption_width) | ||
elseif a.show_caption and ne(a.caption) then | elseif a.show_caption and ne(a.caption) then | ||
local node_caption = node_container:tag('span') | local node_caption = node_container:tag('span') | ||
:addClass('card-caption') | :addClass('card-caption') | ||
if a.no_link or lib.isEmpty(a.final_link) then | if a.no_link or lib.isEmpty(a.final_link) then | ||
node_caption:wikitext(a.caption) | node_caption:wikitext(a.caption) | ||
| Line 519: | Line 511: | ||
) | ) | ||
end | end | ||
setCaptionWidth(node_caption, a.caption_width) | setCaptionWidth(node_caption, a.caption_width) | ||
end | end | ||
| Line 528: | Line 520: | ||
function p.templateData(frame) | function p.templateData(frame) | ||
return TemplateData.templateData(CARD_ARGS, { | return TemplateData.templateData(CARD_ARGS, { | ||
description = 'Creates an item-style card with image, quality, label | description = 'Creates an item-style card with image, quality, label, split images, modifiers, and optional data-driven icons.', | ||
format = 'inline' | format = 'inline' | ||
}, frame) | }, frame) | ||