Module:Args: Difference between revisions
Jump to navigation
Jump to search
Want an adless experience? Log in or Create an account.
(add fromPageContent function to parse args in template format on raw page text) |
(add an alternative method ("expand") that isn't so convoluted to work with but is slightly more limited. still looking for better ways of doing this) |
||
Line 50: | Line 50: | ||
return parsedArgs | return parsedArgs | ||
end | |||
function p.expandInto( args, key, value ) | |||
local first, rest = string.match( key, '^(.-)_(.*)$' ) | |||
local myKey = first or key | |||
myKey = tonumber( myKey ) or myKey | |||
if first then -- this is an internal node so insert children | |||
-- note this will overwrite values in the case of { arg = 'val', arg_sub = 'val' } | |||
args[myKey] = type( args[myKey] ) == 'table' and args[myKey] or {} | |||
p.expandInto( args[myKey], rest, value ) | |||
else -- this is a leaf so set value | |||
args[myKey] = args[myKey] or value -- don't overwrite a table | |||
end | |||
end | |||
function p.expand( args ) | |||
local expandedArgs = {} | |||
for k, v in pairs( args ) do | |||
p.expandInto( expandedArgs, k, v ) | |||
end | |||
return expandedArgs | |||
end | end | ||