Module:Recipe: Difference between revisions
No edit summary |
let's see how much this breaks. |
||
| Line 57: | Line 57: | ||
local function getCurrentPageName(args) | local function getCurrentPageName(args) | ||
return args[param.sPage] or args.page or mw.title.getCurrentTitle().text | return args[param.sPage] or args.page or mw.title.getCurrentTitle().text | ||
end | |||
local function getQualityClass(quality) | |||
if not quality or tostring(quality) == '' then | |||
return nil | |||
end | |||
return 'card-quality-' .. normalizeText(quality) | |||
end | end | ||
| Line 123: | Line 131: | ||
header:tag('span'):addClass('recipe_header_main') | header:tag('span'):addClass('recipe_header_main') | ||
:tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | :tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | ||
:tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | :tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | ||
| Line 227: | Line 234: | ||
:tag('span'):addClass('hidden'):wikitext('[[File:' .. sCharName .. ' Icon.png|24x24px|link=' .. sCharName .. ']]'):done() | :tag('span'):addClass('hidden'):wikitext('[[File:' .. sCharName .. ' Icon.png|24x24px|link=' .. sCharName .. ']]'):done() | ||
:tag('span'):addClass('recipe_header_text'):wikitext('[[' .. sCharName .. ']]'):done() | :tag('span'):addClass('recipe_header_text'):wikitext('[[' .. sCharName .. ']]'):done() | ||
end | |||
local function renderKitchenwareHeader(args, header) | |||
if type(args[param.sKitchArg]) ~= 'string' then | |||
return | |||
end | |||
local sKitchName = args[param.sKitchArg] | |||
header:tag('span'):addClass('recipe_header_sub') | |||
:tag('span'):addClass('mobileHide'):wikitext(' with '):done() | |||
:tag('span'):addClass('hidden'):wikitext('[[File:' .. sKitchName .. ' Icon.png|24x24px|link=' .. sKitchName .. ']]'):done() | |||
:tag('span'):addClass('recipe_header_text'):wikitext('[[' .. sKitchName .. ']]'):done() | |||
end | end | ||
| Line 276: | Line 296: | ||
end | end | ||
for sKey in string.gmatch(args[param.sSortArg] or '', '([^' .. sSortDelim .. ']+)') do | for sKey in string.gmatch(args[param.sSortArg] or '', '([^' .. sSortDelim .. ']+)') do | ||
if type(args[sKey]) ~= 'nil' then | if type(args[sKey]) ~= 'nil' then | ||
| Line 284: | Line 303: | ||
end | end | ||
for sKey, sVal in pairs(args) do | for sKey, sVal in pairs(args) do | ||
if tArgsProcessed[sKey] ~= true and not isRestrictedStandardParam(sKey) then | if tArgsProcessed[sKey] ~= true and not isRestrictedStandardParam(sKey) then | ||
| Line 329: | Line 347: | ||
} | } | ||
if argExists(args, prefix .. '_type') then | if argExists(args, prefix .. '_type') then | ||
table.insert(ingredient.types, args[prefix .. '_type']) | table.insert(ingredient.types, args[prefix .. '_type']) | ||
end | end | ||
local typeIndex = 1 | local typeIndex = 1 | ||
| Line 345: | Line 358: | ||
end | end | ||
local optionIndex = 1 | local optionIndex = 1 | ||
| Line 367: | Line 377: | ||
end | end | ||
local function | -------------------------------------------------------------------------------- | ||
local | -- Cooking type split-card helpers | ||
-------------------------------------------------------------------------------- | |||
local function makeTypeIcon(typeName) | |||
return '[[File:' .. typeName .. ' Icon.png|74x74px|link=' .. typeName .. ']]' | |||
end | |||
local function joinTypeCaption(types) | |||
local out = {} | |||
for _, typeName in ipairs(types) do | |||
table.insert(out, '[[' .. typeName .. ']]') | |||
end | |||
return table.concat(out, ' / ') | |||
end | |||
local function renderCookingSplitTypeCard(category, body, ingredient) | |||
local qualityClass = getQualityClass(ingredient.quality) | |||
local container = body:tag('span') | |||
:addClass('card-container') | |||
:addClass('recipe-type-split-card') | |||
if | if qualityClass then | ||
container:addClass(qualityClass) | |||
end | end | ||
local | local wrapper = container:tag('span') | ||
:addClass('card-wrapper') | |||
local cardBody = wrapper:tag('span') | |||
:addClass('card-body') | |||
local imageContainer = cardBody:tag('span') | |||
:addClass('card-image-container') | |||
:addClass('recipe-type-split-image') | |||
imageContainer:tag('span') | |||
:addClass('recipe-type-split-half') | |||
:addClass('recipe-type-split-half-a') | |||
:wikitext(makeTypeIcon(ingredient.types[1])) | |||
:done() | |||
imageContainer:tag('span') | |||
:addClass('recipe-type-split-half') | |||
:addClass('recipe-type-split-half-b') | |||
:wikitext(makeTypeIcon(ingredient.types[2])) | |||
:done() | |||
if tostring(ingredient.amount or '') ~= '' then | |||
cardBody:tag('span') | |||
:addClass('card-text') | |||
:wikitext(tostring(ingredient.amount or '1')) | |||
:done() | |||
end | end | ||
container:tag('span') | |||
:addClass('card-caption') | |||
:wikitext(joinTypeCaption(ingredient.types)) | |||
:done() | |||
for _, typeName in ipairs(ingredient.types) do | |||
addUseCategory(category, typeName) | |||
end | |||
end | end | ||
| Line 397: | Line 458: | ||
end | end | ||
local function | local function renderCookingTypeFallback(category, body, ingredient) | ||
local wrapper = body:tag('div') | local wrapper = body:tag('div') | ||
:addClass('recipe_body_cooking_ingredient') | :addClass('recipe_body_cooking_ingredient') | ||
| Line 409: | Line 470: | ||
ingredient.quality | ingredient.quality | ||
)) | )) | ||
end | |||
end | |||
local function renderCookingTypeCards(category, body, ingredient) | |||
if #ingredient.types == 2 then | |||
renderCookingSplitTypeCard(category, body, ingredient) | |||
else | |||
renderCookingTypeFallback(category, body, ingredient) | |||
end | end | ||
end | end | ||
| Line 428: | Line 497: | ||
local function renderCookingIngredient(category, body, ingredient) | local function renderCookingIngredient(category, body, ingredient) | ||
if ingredient.item then | if ingredient.item then | ||
renderCookingSpecificItem(category, body, ingredient) | renderCookingSpecificItem(category, body, ingredient) | ||
| Line 435: | Line 502: | ||
end | end | ||
if #ingredient.options > 0 then | if #ingredient.options > 0 then | ||
renderCookingOptionCards(category, body, ingredient) | renderCookingOptionCards(category, body, ingredient) | ||
| Line 443: | Line 507: | ||
end | end | ||
if #ingredient.types > 0 then | if #ingredient.types > 0 then | ||
renderCookingTypeCards(category, body, ingredient) | renderCookingTypeCards(category, body, ingredient) | ||
return | return | ||
end | end | ||
end | end | ||
| Line 513: | Line 535: | ||
renderTime(args, header) | renderTime(args, header) | ||
renderCharacter(args, header) | renderCharacter(args, header) | ||
renderKitchenwareHeader(args, header) | |||
local body = output:tag('div') | local body = output:tag('div') | ||
| Line 559: | Line 581: | ||
:addClass('recipe_container') | :addClass('recipe_container') | ||
local category = mw.html.create() | local category = mw.html.create() | ||