Module:RecipeUsedIn

local util_args = require('Module:ArgsUtil') local util_cargo = require("Module:CargoUtil")

local lang = mw.getLanguage('en')

local COLUMNS = { 'Ingredients', 'Outcome', 'CraftTime', 'Experience' } local COL_NAMES = { CraftTime = 'Craft time', Experience = 'Experience gained' }

local h = {} local p = {} function p.main(frame) local args = util_args.merge local data = util_cargo.queryAndCast(h.getQuery(args)) h.processData(data) return h.makeOutput(result) end

function h.getQuery(args) local query = { tables = { 'Recipes', 'Items', 'Recipes=Recipes2', 'Items=Items2', },		join = { 'Recipes._pageName=Items._pageName', 'Recipes.id=Recipes2.id', 'Recipes2._pageName=Items2._pageName', },		fields = { 'Items', -- TODO },		oneToMany = { groupBy = { 'RecipeId' }, fields = { Ingredients = { 'Recipes2.', 'Items2.', 'Items2.', -- TODO },			}		},	}	return query end

function h.makeOutput(result) local output = mw.html.create('table') :addClass('wikitable') :addClass('sortable') :css('min-width', '50%') :css('white-space', 'nowrap') h.printCaption(output) h.printHeader(output) h.printData(output, result) end

function h.processData(data) -- TODO end

function h.printCaption(output) output:tag('caption') :addClass('infoboxname') :attr('colspan', 4) :wikitext('Used in the following Recipes') end

function h.printHeader(output) local tr = output:tag('tr') for _, col in ipairs(COLUMNS) do		tr:tag('th') :wikitext(COL_NAMES[col] or col) end end

function h.printData(output, result) for _, dataRow in ipairs(result) do		local tr = output:tag('tr') h.printOneDataRow(tr, dataRow) end end

function h.printOneDataRow(tr, dataRow) for _, col in ipairs(COLUMNS) do		tr:tag('td') td:wikitext(dataRow[col]) end end

return p