Editing Module:Recipe
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 6: | Line 6: | ||
local param = { | local param = { | ||
sCharArg = 'character', | sCharArg = 'character', | ||
sTypeArg = 'type', | sTypeArg = 'type', | ||
sSortArg = 'sort', | sSortArg = 'sort', | ||
| Line 31: | Line 30: | ||
sOut = sOut .. 's' | sOut = sOut .. 's' | ||
end | end | ||
return sOut | return sOut | ||
end | end | ||
local function | local function normalizeType(s) | ||
return mw.ustring.lower(mw.text.trim(tostring(s or ''))) | return mw.ustring.lower(mw.text.trim(tostring(s or ''))) | ||
end | end | ||
| Line 43: | Line 41: | ||
end | end | ||
local function | local function joinDisplay(list, separator) | ||
local out = {} | |||
for _, value in ipairs(list) do | |||
table.insert(out, '[[' .. value .. ']]') | |||
end | |||
end | |||
return table.concat(out, separator or ' / ') | |||
return | |||
end | end | ||
local function | local function joinFileNameParts(list) | ||
return table.concat(list, ' & ') | |||
end | end | ||
| Line 81: | Line 59: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function | local function addRecipe(category, sAmt, sName, quality) | ||
local cardArgs = { | local cardArgs = { | ||
name = sName, | name = sName, | ||
text = sAmt, | text = sAmt, | ||
show_caption = '1' | show_caption = '1', | ||
mobile = 'bulleted' | |||
} | } | ||
| Line 94: | Line 73: | ||
local cardNode = Card._main(cardArgs) | local cardNode = Card._main(cardArgs) | ||
category:wikitext( | |||
'[[Category:Uses ', | |||
sName, | sName, | ||
'|', | |||
padLeft(tostring(sAmt or ''):gsub('%D', ''), 10) | padLeft(tostring(sAmt or ''):gsub('%D', ''), 10), | ||
']]' | |||
) | ) | ||
| Line 109: | Line 89: | ||
text = sText or '', | text = sText or '', | ||
show_caption = '1', | show_caption = '1', | ||
mobile = 'bulleted', | |||
mini = '1' | mini = '1' | ||
} | } | ||
| Line 118: | Line 99: | ||
local cardNode = Card._main(cardArgs) | local cardNode = Card._main(cardArgs) | ||
if category and sName then | |||
category:wikitext('[[Category:Uses ', sName, ']]') | |||
end | |||
return cardNode | return cardNode | ||
end | end | ||
| Line 136: | Line 111: | ||
local function renderHeader(args, output, category) | local function renderHeader(args, output, category) | ||
local header = output:tag('div'):addClass(' | local header = output:tag('div'):addClass('recipe_header') | ||
local sType = args[param.sTypeArg] | local sType = args[param.sTypeArg] | ||
header:tag('span'):addClass(' | header:tag('span'):addClass('recipe_header_main') | ||
:tag('span'):addClass(' | :tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | ||
:tag('span'):addClass('mobileHide'):wikitext('<big>' .. sType .. '</big>'):done() | |||
:tag('span'):addClass('recipe_header_text'):wikitext('[[' .. sType .. ']]'):done() | |||
category:wikitext('[[Category:' .. sType .. ']]') | category:wikitext('[[Category:' .. sType .. ']]') | ||
| Line 224: | Line 202: | ||
end | end | ||
header:tag('span'):addClass(' | header:tag('span'):addClass('recipe_header_sub') | ||
:tag('span'):wikitext(' for '):done() | :tag('span'):addClass('mobileHide'):wikitext(' for '):done() | ||
:tag('span'):addClass(' | :tag('span'):addClass('hidden'):wikitext(' for '):done() | ||
:tag('span'):addClass('recipe_header_text'):wikitext(sTime):done() | |||
end | end | ||
| Line 236: | Line 215: | ||
local sCharName = args[param.sCharArg] | local sCharName = args[param.sCharArg] | ||
header:tag('span'):addClass(' | header:tag('span'):addClass('recipe_header_sub') | ||
:tag('span'):addClass('mobileHide'):wikitext(' with '):done() | |||
:tag('span'):addClass(' | :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(' | |||
end | end | ||
| Line 256: | Line 224: | ||
-- Standard recipe rendering | -- Standard recipe rendering | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function renderStandardYield(args, body) | local function renderStandardYield(args, body) | ||
| Line 272: | Line 230: | ||
end | end | ||
local sYield = args[param.sYieldArg] or | local sYield = args[param.sYieldArg] or '1' | ||
local pageTitle = | local pageTitle = args.page or mw.title.getCurrentTitle().text | ||
local yieldCard = | local yieldCard = Card._main({ | ||
name = pageTitle, | |||
text = sYield, | |||
show_caption = '1', | |||
}) | |||
body | body | ||
:tag('div'):addClass(' | :tag('div'):addClass('recipe_body_icon') | ||
:wikitext('➜'):done() | :wikitext('➜'):done() | ||
:tag('div'):addClass(' | :tag('div'):addClass('recipe_body_yield') | ||
:node(yieldCard) | :node(yieldCard) | ||
local itemText = require('Module:Item').main{ | |||
[1] = pageTitle, | |||
[2] = '15', | |||
x = sYield | |||
} | |||
end | end | ||
| Line 292: | Line 260: | ||
renderCharacter(args, header) | renderCharacter(args, header) | ||
local body = output:tag('div'):addClass(' | local body = output:tag('div'):addClass('recipe_body') | ||
local sSortDelim = param.sSortDelim | local sSortDelim = param.sSortDelim | ||
| Line 302: | Line 270: | ||
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 | ||
body:node( | body:node(addRecipe(category, args[sKey], sKey)) | ||
tArgsProcessed[sKey] = true | tArgsProcessed[sKey] = true | ||
end | end | ||
| Line 308: | Line 276: | ||
for sKey, sVal in pairs(args) do | for sKey, sVal in pairs(args) do | ||
if tArgsProcessed[sKey] ~= true and not | local restricted = false | ||
body:node( | |||
for _, keyParam in pairs(param) do | |||
if keyParam == sKey then | |||
restricted = true | |||
end | |||
end | |||
if tArgsProcessed[sKey] ~= true and not restricted then | |||
body:node(addRecipe(category, sVal, sKey)) | |||
end | end | ||
end | end | ||
| Line 319: | Line 295: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Cooking parsing | -- Cooking recipe parsing | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
local function getCookingIngredient(args, index) | local function getCookingIngredient(args, index) | ||
| Line 344: | Line 303: | ||
local ingredient = { | local ingredient = { | ||
index = index, | index = index, | ||
amount = args[prefix .. '_amount'] or | amount = args[prefix .. '_amount'] or '1', | ||
quality = args[prefix .. '_quality'], | quality = args[prefix .. '_quality'], | ||
item = args[prefix], | item = args[prefix], | ||
| Line 351: | Line 310: | ||
} | } | ||
-- |item_1_type = Fish | |||
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 | ||
-- |item_1_type_1 = Freshwater Fish | |||
-- |item_1_type_2 = Saltwater Fish | |||
local typeIndex = 1 | local typeIndex = 1 | ||
| Line 362: | Line 324: | ||
end | end | ||
-- |item_1_option_1 = Rice | |||
-- |item_1_option_2 = Wheat | |||
local optionIndex = 1 | local optionIndex = 1 | ||
| Line 370: | Line 334: | ||
local hasIngredient = | local hasIngredient = | ||
ingredient.item ~= nil | |||
or #ingredient.types > 0 | or #ingredient.types > 0 | ||
or #ingredient.options > 0 | or #ingredient.options > 0 | ||
| Line 381: | Line 345: | ||
end | end | ||
local function getKitchenware(args) | |||
local kitchenware = {} | |||
if argExists(args, 'kitchenware') then | |||
table.insert(kitchenware, args.kitchenware) | |||
end | end | ||
local index = 1 | |||
local | |||
while argExists(args, 'kitchenware_' .. index) do | |||
table.insert( | table.insert(kitchenware, args['kitchenware_' .. index]) | ||
index = index + 1 | |||
end | end | ||
return | return kitchenware | ||
end | end | ||
-------------------------------------------------------------------------------- | |||
-- Cooking recipe display | |||
-------------------------------------------------------------------------------- | |||
local | local function renderCookingTypeCard(category, body, ingredient) | ||
:addClass(' | local wrapper = body:tag('div') | ||
:addClass(' | :addClass('recipe_body_cooking_ingredient') | ||
:addClass('recipe_body_cooking_type_card') | |||
local | local fileBase = joinFileNameParts(ingredient.types) | ||
local fileName = 'Recipe ' .. fileBase .. ' Icon.png' | |||
local caption = joinDisplay(ingredient.types, ' / ') | |||
for _, typeName in ipairs(ingredient.types) do | |||
: | category:wikitext('[[Category:Uses ', typeName, ']]') | ||
end | |||
local | local amountText = tostring(ingredient.amount or '1') | ||
local card = wrapper:tag('div') | |||
:addClass(' | :addClass('card') | ||
:addClass('recipe-type- | :addClass('recipe-type-card') | ||
if ingredient.quality then | |||
:addClass(' | card:addClass('card-quality-' .. normalizeType(ingredient.quality)) | ||
end | |||
card:tag('div') | |||
:addClass('card-image') | |||
:wikitext('[[File:' .. fileName .. '|64x64px|link=]]') | |||
card:tag('div') | |||
:addClass('card-caption') | :addClass('card-caption') | ||
:wikitext( | :wikitext(caption) | ||
if amountText ~= '' then | |||
card:tag('div') | |||
:addClass('card-text') | |||
:wikitext(amountText) | |||
end | end | ||
end | end | ||
| Line 487: | Line 406: | ||
local function renderCookingOptionCards(category, body, ingredient) | local function renderCookingOptionCards(category, body, ingredient) | ||
local wrapper = body:tag('div') | local wrapper = body:tag('div') | ||
:addClass(' | :addClass('recipe_body_cooking_ingredient') | ||
:addClass(' | :addClass('recipe_body_cooking_options') | ||
for _, itemName in ipairs(ingredient.options) do | for _, itemName in ipairs(ingredient.options) do | ||
wrapper:node( | wrapper:node(addRecipe(category, ingredient.amount, itemName, ingredient.quality)) | ||
end | end | ||
end | end | ||
local function renderCookingIngredient(category, body, ingredient) | local function renderCookingIngredient(category, body, ingredient) | ||
-- Specific item: | |||
-- |item_1 = Rice | |||
if ingredient.item then | if ingredient.item then | ||
body:node(addRecipe(category, ingredient.amount, ingredient.item, ingredient.quality)) | |||
return | return | ||
end | end | ||
-- Multiple accepted specific items: | |||
-- |item_1_option_1 = Rice | |||
-- |item_1_option_2 = Wheat | |||
if #ingredient.options > 0 then | if #ingredient.options > 0 then | ||
renderCookingOptionCards(category, body, ingredient) | renderCookingOptionCards(category, body, ingredient) | ||
| Line 511: | Line 430: | ||
end | end | ||
-- Type-based ingredient: | |||
-- |item_1_type = Fish | |||
-- |item_1_type_1 = Freshwater Fish | |||
-- |item_1_type_2 = Saltwater Fish | |||
if #ingredient.types > 0 then | if #ingredient.types > 0 then | ||
renderCookingTypeCard(category, body, ingredient) | |||
return | return | ||
end | end | ||
end | |||
local function renderKitchenwareIcon(body, kitchenware) | |||
body:tag('div') | |||
:addClass('recipe_body_icon') | |||
:addClass('recipe_body_kitchenware_icon') | |||
:wikitext('[[File:Icon_' .. kitchenware .. '.png|35x35px|link=' .. kitchenware .. ']]') | |||
end | |||
local function renderKitchenwareMiniCard(category, body, kitchenware) | |||
body:tag('div') | |||
:addClass('recipe_body_icon') | |||
:addClass('recipe_body_kitchenware_card') | |||
:node(addMiniCard(category, kitchenware, '')) | |||
end | end | ||
| Line 522: | Line 459: | ||
end | end | ||
local sYield = args[param.sYieldArg] or | local sYield = args[param.sYieldArg] or '1' | ||
local pageTitle = | local pageTitle = args.page or mw.title.getCurrentTitle().text | ||
local kitchenware = getKitchenware(args) | |||
local yieldCard = Card._main({ | |||
name = pageTitle, | |||
text = sYield, | |||
show_caption = '1', | |||
}) | |||
if #kitchenware == 0 then | |||
body:tag('div') | |||
:addClass('recipe_body_icon') | |||
:wikitext('➜') | |||
elseif #kitchenware == 1 then | |||
-- Default: icon mode. | |||
-- Change this to renderKitchenwareMiniCard(category, body, kitchenware[1]) | |||
-- if you prefer mini-card kitchenware display. | |||
renderKitchenwareIcon(body, kitchenware[1]) | |||
category:wikitext('[[Category:Uses ', kitchenware[1], ']]') | |||
:tag('div'):addClass(' | else | ||
: | local wrapper = body:tag('div') | ||
:tag('div'):addClass(' | :addClass('recipe_body_icon') | ||
:addClass('recipe_body_kitchenware_multi') | |||
for _, itemName in ipairs(kitchenware) do | |||
wrapper:node(addMiniCard(category, itemName, '')) | |||
end | |||
end | |||
body:tag('div') | |||
:addClass('recipe_body_yield') | |||
:node(yieldCard) | |||
local itemText = require('Module:Item').main{ | |||
[1] = pageTitle, | |||
[2] = '15', | |||
x = sYield | |||
} | |||
end | end | ||
| Line 539: | Line 506: | ||
renderTime(args, header) | renderTime(args, header) | ||
renderCharacter(args, header) | renderCharacter(args, header) | ||
local body = output:tag('div') | local body = output:tag('div') | ||
:addClass(' | :addClass('recipe_body') | ||
:addClass(' | :addClass('recipe_body_cooking') | ||
local ingredientIndex = 1 | |||
local foundIngredient = false | local foundIngredient = false | ||
while true do | |||
local ingredient = getCookingIngredient(args, | local ingredient = getCookingIngredient(args, ingredientIndex) | ||
if ingredient then | if not ingredient then | ||
break | |||
end | end | ||
foundIngredient = true | |||
renderCookingIngredient(category, body, ingredient) | |||
ingredientIndex = ingredientIndex + 1 | |||
end | end | ||
| Line 583: | Line 553: | ||
function p._main(args, frame) | function p._main(args, frame) | ||
local output = mw.html.create('div') | local output = mw.html.create('div') | ||
:addClass(' | :addClass('recipe_container') | ||
local category = mw.html.create() | local category = mw.html.create() | ||
| Line 594: | Line 564: | ||
local sType = args[param.sTypeArg] | local sType = args[param.sTypeArg] | ||
if | if normalizeType(sType) == 'cooking' then | ||
renderCookingRecipe(args, frame, output, category) | renderCookingRecipe(args, frame, output, category) | ||
else | else | ||