Module:Item: Difference between revisions

From escforumwiki
Jump to navigation Jump to search
en>Petr Matas
No edit summary
en>Petr Matas
No edit summary
Line 5: Line 5:
end
end


function p.main(frame)
function unescape(str)
return str:gsub("\\(.)", "%1")
end
 
function p.pack(frame)
local parent = frame:getParent()
local parent = frame:getParent()
Line 13: Line 17:
end
end
return result;
return result .. "|";
end
 
function unpack(str)
end
 
function p.each(frame)
local parent = frame:getParent()
local items = parent.args
local separator = frame.args.separator or ""
local template = frame.args.template
local result = ""
for i, item in ipairs(items) do
result = result .. frame:expandTemplate{ title = template, args = unpack(item) }
if items[i + 1] then
result = result .. separator
end
end
return result
end
end


return p
return p

Revision as of 04:16, 13 December 2015

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

local p = {}

function escape(str)
	return str:gsub("([|\\])", "\\%1")
end

function unescape(str)
	return str:gsub("\\(.)", "%1")
end

function p.pack(frame)
	local parent = frame:getParent()
	
	local result = ''
	for key, value in pairs(parent.args) do
		result = result .. "|" .. escape(tostring(key)) .. "|" .. escape(value)
	end
	
	return result .. "|";
end

function unpack(str)
	
end

function p.each(frame)
	local parent = frame:getParent()
	local items = parent.args
	local separator = frame.args.separator or ""
	local template = frame.args.template
	
	local result = ""
	for i, item in ipairs(items) do
		result = result .. frame:expandTemplate{ title = template, args = unpack(item) }
		if items[i + 1] then
			result = result .. separator
		end
	end
	
	return result
end

return p