Module:Args: Difference between revisions

Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
(don't try to parse values to numbers because a module might be expecting a string and the input just happens to be a number)
(add fromPageContent function to parse args in template format on raw page text)
Line 47: Line 47:
   for k, v in pairs( args ) do
   for k, v in pairs( args ) do
     insertInto( parsedArgs, k, v )
     insertInto( parsedArgs, k, v )
  end
  return parsedArgs
end
function p.fromPageContent( content, templateName )
  templateName = templateName or 'Properties'
  local parsedArgs = Arg.new()
  local templateContents = string.match( content, '{{%s*' .. templateName .. '%s*|%s*(.-)%s*}}' )
  if templateContents then
    for prop in mw.text.gsplit( templateContents, '|' ) do
      local k, v = unpack( mw.text.split( prop, '=' ) )
      insertInto( parsedArgs, k, v )
    end
   end
   end