Module:DPL

-- Import modules local iter = require("Module:Functional").iter

-- Note that the namespace is included in title. local function getImage( title ) local namespace = title:gsub(":.+", "") local name = title:gsub(".+:", "")

local result = mw.getCurrentFrame:preprocess("")

return result end

-- Looks up pages that use a specified template, gets the values of the specified parameters, and converts them into a DPL table. -- 'category' filters the pages by their category, otherwise the script would take too long. -- 'name' should be the raw template name, without the namespace. -- 'parameters' should be a Lua table containing the parameters that you want to be included in the table. local function lookupTemplate( category, name, parameters ) local dpl_result = mw.getCurrentFrame:callParserFunction{ name = '#dpl', args = {			category = category, uses = "Template:" .. name, include = "{" .. name .. "}:" .. table.concat(parameters, ":"), table = ",," .. table.concat(parameters, ","), tablerow = string.rep(",", #parameters):sub(1, -2), [1] = ''		}	}	local t = {} local substrings = mw.text.split(dpl_result, "\n|-", true) for i = 1, #substrings - 1 do		if i == 1 then local temp = mw.text.split(substrings[i], "\n!", true) table.remove(temp, 1) table.insert(t, temp) else table.insert(t, mw.text.split(substrings[i], "\n|", true)) end end return t end

-- Converts a Lua table to HTML table -- 't' should be the input Lua table, with the header row in index 1. -- 'class' should be a table containing the classes that you want to be applied to the HTML table. It is optional and defaults to { "wikitable" }. local function toHTMLTable( t, classes ) classes = classes or { "wikitable" } local function addClass(acc, e)		return acc:addClass(e):done end local metatable = iter(classes):reduce(addClass, mw.html.create("table")) metadata:css("width", "100%"):css("text-align", "center") for i = 1, #t do		local addRow = nil if i == 1 then addRow = function (acc, e)				return acc:tag("th"):attr("scope", "col"):wikitext(e):done end else addRow = function (acc, e)				return acc:tag("td"):wikitext(e):done end end iter(t[i]):reduce(addRow, metadata:tag("tr")) end return tostring(metadata) end

return { getImage = getImage, lookupTemplate = lookupTemplate, toHTMLTable = toHTMLTable }