Module:Recipe list

From Box of Rocks WIKI
Jump to navigation Jump to search

Documentation for this module may be created at Module:Recipe list/doc

local p = {}
function p.type( f )
	local args = f.args
	local text = require( [[Module:Text]] )
	local crafting = require( [[Module:Crafting]] ).table
	local type = text.trim( args[1] )

	local argList = {
		'type', 'upcoming', 'name', 'ingredients', 'arggroups',
		1, 2, 3, 4, 5, 6, 7, 8, 9,
		'A1', 'B1', 'C1', 'A2', 'B2', 'C2', 'A3', 'B3', 'C3',
		'Output', 'description', 'fixed', 'notfixed',
		'A1title', 'A1link', 'B1title', 'B1link', 'C1title', 'C1link',
		'A2title', 'A2link', 'B2title', 'B2link', 'C2title', 'C2link',
		'A3title', 'A3link', 'B3title', 'B3link', 'C3title', 'C3link',
		'Otitle', 'Olink',
	}
	
	local data = f:callParserFunction( '#dpl:', {
		category = type .. ' recipe',
		include = '{Crafting}:' .. table.concat( argList, ':' ),
		mode = 'userformat',
		secseparators = '====',
		multisecseparators = '===='
	} )
	
	local out = {}
	local showDesciption
	local templates = {}
	for template in text.gsplit( data, '====' ) do
		-- If type matches
		if template:find( '^%s*' .. type .. '%s*|' ) then
			local tArgs = {}
			local i = 0
			-- Extract the arguments from the DPL query
			for tArg in text.gsplit( template, '\n|' ) do
				i = i + 1
				if tArg ~= '' then
					local key = argList[i]
					tArgs[key] = tArg
				end
			end
			
			if tArgs.description then
				showDescription = true
			end
			
			tArgs.nocat = '1'
			
			table.insert( templates, tArgs )
		end
	end
	if #templates == 0 then
		return
	end
	
	templates[1].head = '1'
	templates[1].showname = '1'
	if showDescription and args.showdesciption ~= '0' or args.showdesciption == '1' then
		templates[1].showdescription = '1'
	end
	if not args.continue then
		templates[#templates].foot = '1'
	end
	
	local out = {}
	for i, v in ipairs( templates ) do
		table.insert( out, crafting( v ) )
	end
	
	return table.concat( out, '\n' )
end
return p