|
|
@ -3,21 +3,25 @@ def parse_template(title, template)
|
|
|
|
|
|
|
|
|
|
|
|
fields = {}
|
|
|
|
fields = {}
|
|
|
|
|
|
|
|
|
|
|
|
fields_string = @wiki.article(title).text.scan(template_re)[0][0]
|
|
|
|
if (scanned = @wiki.article(title).text.scan(template_re)) != []
|
|
|
|
|
|
|
|
fields_string = scanned[0][0]
|
|
|
|
|
|
|
|
|
|
|
|
inlink = 0
|
|
|
|
inlink = 0
|
|
|
|
field = ""
|
|
|
|
field = ""
|
|
|
|
fields_string += "|" unless fields_string.match(/\|$/)
|
|
|
|
fields_string += "|" unless fields_string.match(/\|$/)
|
|
|
|
fields_string.split(//).each do |c|
|
|
|
|
fields_string.split(//).each do |c|
|
|
|
|
if c == "|" && inlink == 0
|
|
|
|
if c == "|" && inlink == 0
|
|
|
|
(key, value) = field.split(/=/)
|
|
|
|
(key, value) = field.split(/=/)
|
|
|
|
fields[key] = value
|
|
|
|
fields[key] = value
|
|
|
|
field = ""
|
|
|
|
field = ""
|
|
|
|
else
|
|
|
|
else
|
|
|
|
inlink += 1 if c == "["
|
|
|
|
inlink += 1 if c == "["
|
|
|
|
inlink -= 1 if c == "]"
|
|
|
|
inlink -= 1 if c == "]"
|
|
|
|
field += c
|
|
|
|
field += c
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
$stderr.print "Template #{template} not found in #{title}!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
fields
|
|
|
|
fields
|
|
|
|