Module:ProcessArgs: Difference between revisions

From Structorica Wiki
Jump to navigation Jump to search
Created page with "--- --- This module provides utilities for processing template arguments. --- --- 1. Function norm(): --- Cleans template arguments by removing empty values and trimming whitespace. --- Example: {{Template|a| |b| }} becomes {a="a", b="b"} --- --- 2. Function merge(): --- Combines current template parameters with parent template parameters. --- Example: Current template {{Child|y=2}} + parent {{Parent|x=1}} = {y="2", x="1"} --- --- Source: https://minecraft.wi..."
 
No edit summary
Line 8: Line 8:
--- 2. Function merge():
--- 2. Function merge():
---    Combines current template parameters with parent template parameters.
---    Combines current template parameters with parent template parameters.
---    Example: Current template {{Child|y=2}} + parent {{Parent|x=1}} = {y="2", x="1"}
---    Example: Current template <code>{{Child|y=2}} + parent {{Parent|x=1}} = {y="2", x="1"}</code>
---
---
--- Source: https://minecraft.wiki/w/Module:ProcessArgs
--- Source: https://minecraft.wiki/w/Module:ProcessArgs

Revision as of 15:29, 15 January 2026

Documentation

This module provides utilities for processing template arguments.

1. Function norm():

Cleans template arguments by removing empty values and trimming whitespace.

2. Function merge():

Combines current template parameters with parent template parameters.

Source

https://minecraft.wiki/w/Module:ProcessArgs


---
--- This module provides utilities for processing template arguments.
---
--- 1. Function norm():
---    Cleans template arguments by removing empty values and trimming whitespace.
---    Example: {{Template|a| |b| }} becomes {a="a", b="b"}
---
--- 2. Function merge():
---    Combines current template parameters with parent template parameters.
---    Example: Current template <code>{{Child|y=2}} + parent {{Parent|x=1}} = {y="2", x="1"}</code>
---
--- Source: https://minecraft.wiki/w/Module:ProcessArgs
---

local p = {}


-- 1. Function norm() ---
function p.norm( origArgs )
	if type( origArgs ) ~= 'table' then
		origArgs = mw.getCurrentFrame():getParent().args
	end
	local args = {}
	
	for k, v in pairs( origArgs ) do
		v = mw.text.trim( tostring( v ) )
		if v ~= '' then
			args[k] = v
		end
	end
	
	return args
end


-- 2. Function merge() ---
function p.merge( origArgs, parentArgs, norm )
	if type( origArgs ) ~= 'table' then
		norm = origArgs
		local f = mw.getCurrentFrame()
		origArgs = f.args
		parentArgs = f:getParent().args
	end
	local args = {}
	
	for k, v in pairs( origArgs ) do
		v = mw.text.trim( tostring( v ) )
		if not norm or v ~= '' then
			args[k] = v
		end
	end
	
	for k, v in pairs( parentArgs ) do
		v = mw.text.trim( v )
		if not norm or v ~= '' then
			args[k] = v
		end
	end
	
	return args
end



return p