17,230
edits
(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) |
(change fromPageContent to use expandInto instead of parseInto, and trim whitespace from key and value) |
||
Line 77: | Line 77: | ||
function p.fromPageContent( content, templateName ) | function p.fromPageContent( content, templateName ) | ||
templateName = templateName or 'Properties' | templateName = templateName or 'Properties' | ||
local parsedArgs = | local parsedArgs = {} | ||
local templateContents = string.match( content, '{{%s*' .. templateName .. '%s*|%s*(.-)%s*}}' ) | local templateContents = string.match( content, '{{%s*' .. templateName .. '%s*|%s*(.-)%s*}}' ) | ||
if templateContents then | if templateContents then | ||
for prop in mw.text.gsplit( templateContents, '|' ) do | for prop in mw.text.gsplit( templateContents, '%s*|%s*' ) do | ||
local k, v = unpack( mw.text.split( prop, '=' ) ) | local k, v = unpack( mw.text.split( prop, '%s*=%s*' ) ) | ||
p.expandInto( parsedArgs, k, v ) | |||
end | end | ||
end | end |