Module:QuoteBuilder

From Conflict of Nations Wiki
Jump to navigation Jump to search

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

--------------------------------------------------------------------------------
-- Builds Cquote2 templates from a lua table of quotes
-- interface is meant to be called with {{PAGENAME}} and expects an argument
-- of the form Country Name (Scenario Name)
--------------------------------------------------------------------------------
local returnValue = {}

function returnValue.countryInterface(frame)
	local dataPreprocessor = require("Module:DataPreprocessor")
	local processedDataTable = dataPreprocessor.process(frame)
	local source = processedDataTable[1]
	local entry = processedDataTable[2]
	return frame:preprocess(returnValue.buildWikitext("Module:Data/Quotes/"..source, entry))
end

function returnValue.scenarioInterface(frame)
	local entry = frame.args[1]
	return frame:preprocess(returnValue.buildWikitext("Module:Data/Scenarios/Quotes", entry))
end

function returnValue.buildWikitext(source, entry)
	local dataSource = mw.loadData(source)
	if dataSource == nil then
		error("Data source not found")
		return
		end
	local wikitextData = dataSource[entry]
	if wikitextData == nil then
		return ""
		end
	local wikitext = "{{Cquote2|quotetext = "..wikitextData.."}}"
	return wikitext
	end

return returnValue