<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.garp.au/index.php?action=history&amp;feed=atom&amp;title=Module%3AInfoboxes</id>
	<title>Module:Infoboxes - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.garp.au/index.php?action=history&amp;feed=atom&amp;title=Module%3AInfoboxes"/>
	<link rel="alternate" type="text/html" href="https://wiki.garp.au/index.php?title=Module:Infoboxes&amp;action=history"/>
	<updated>2026-05-04T12:32:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.garp.au/index.php?title=Module:Infoboxes&amp;diff=58&amp;oldid=prev</id>
		<title>DrunkMunki: Created page with &quot;local p = {}     --Vars-- local _fieldTags = {&quot;&lt;title&quot;, &quot;&lt;media&quot;, &quot;&lt;image&quot;, &quot;&lt;audio&quot;, &quot;&lt;video&quot;, &quot;&lt;data&quot;, &quot;&lt;caption&quot;}   --SUPORTING FUNCTIONS--  	--Infobox Functions--  		--generateInfoboxExample--  --Makes a good guess at whether a page is an infobox template local function isInfobox(pageContent) 	return string.match(pageContent, &quot;&lt;infobox&quot;) end  --Makes a good guess at whether a string of text contains field data for an infobox local function isFieldData...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.garp.au/index.php?title=Module:Infoboxes&amp;diff=58&amp;oldid=prev"/>
		<updated>2024-04-07T11:05:25Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local p = {}     --&lt;a href=&quot;/index.php?title=Vars&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Vars (page does not exist)&quot;&gt;Vars&lt;/a&gt;-- local _fieldTags = {&amp;quot;&amp;lt;title&amp;quot;, &amp;quot;&amp;lt;media&amp;quot;, &amp;quot;&amp;lt;image&amp;quot;, &amp;quot;&amp;lt;audio&amp;quot;, &amp;quot;&amp;lt;video&amp;quot;, &amp;quot;&amp;lt;data&amp;quot;, &amp;quot;&amp;lt;caption&amp;quot;}   --&lt;a href=&quot;/index.php?title=SUPORTING_FUNCTIONS&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;SUPORTING FUNCTIONS (page does not exist)&quot;&gt;SUPORTING FUNCTIONS&lt;/a&gt;--  	--&lt;a href=&quot;/index.php?title=Infobox_Functions&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Infobox Functions (page does not exist)&quot;&gt;Infobox Functions&lt;/a&gt;--  		--&lt;a href=&quot;/index.php?title=GenerateInfoboxExample&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;GenerateInfoboxExample (page does not exist)&quot;&gt;generateInfoboxExample&lt;/a&gt;--  --Makes a good guess at whether a page is an infobox template local function isInfobox(pageContent) 	return string.match(pageContent, &amp;quot;&amp;lt;infobox&amp;quot;) end  --Makes a good guess at whether a string of text contains field data for an infobox local function isFieldData...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[Vars]]--&lt;br /&gt;
local _fieldTags = {&amp;quot;&amp;lt;title&amp;quot;, &amp;quot;&amp;lt;media&amp;quot;, &amp;quot;&amp;lt;image&amp;quot;, &amp;quot;&amp;lt;audio&amp;quot;, &amp;quot;&amp;lt;video&amp;quot;, &amp;quot;&amp;lt;data&amp;quot;, &amp;quot;&amp;lt;caption&amp;quot;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[SUPORTING FUNCTIONS]]--&lt;br /&gt;
&lt;br /&gt;
	--[[Infobox Functions]]--&lt;br /&gt;
&lt;br /&gt;
		--[[generateInfoboxExample]]--&lt;br /&gt;
&lt;br /&gt;
--Makes a good guess at whether a page is an infobox template&lt;br /&gt;
local function isInfobox(pageContent)&lt;br /&gt;
	return string.match(pageContent, &amp;quot;&amp;lt;infobox&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--Makes a good guess at whether a string of text contains field data for an infobox&lt;br /&gt;
local function isFieldData(line)&lt;br /&gt;
	for i, tag in ipairs(_fieldTags) do&lt;br /&gt;
		if string.match(string.lower(line), tag) then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--WIP (not functional)&lt;br /&gt;
local function parseLine(line)&lt;br /&gt;
	matches = {}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--Makes a good guess at whether a field is an image&lt;br /&gt;
local function isImage(line)&lt;br /&gt;
	return string.match(string.lower(line), &amp;quot;&amp;lt;image&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--Makes a good guess at whether a field is the title&lt;br /&gt;
local function isTitle(line)&lt;br /&gt;
	return string.match(string.lower(line), &amp;quot;&amp;lt;title&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--Makes a good guess at whether a line opens a &amp;lt;group&amp;gt; tag&lt;br /&gt;
local function isGroup(line)&lt;br /&gt;
	return string.match(string.lower(line), &amp;quot;&amp;lt;group&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--Makes a good guess at whether a field is a status field&lt;br /&gt;
local function isStatus(line)&lt;br /&gt;
	return string.match(string.lower(line), &amp;quot;status&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--Checks if infobox preview should be generated&lt;br /&gt;
local function useInfobox(frame)&lt;br /&gt;
	return frame.args[2] ~= &amp;quot;noib&amp;quot;&lt;br /&gt;
		and frame.args[3] ~= &amp;quot;noib&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--Checks if example usage should be generated&lt;br /&gt;
local function useExample(frame)&lt;br /&gt;
	return frame.args[2] ~= &amp;quot;noex&amp;quot;&lt;br /&gt;
		and frame.args[3] ~= &amp;quot;noex&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[For use in Infobox template /doc pages:&lt;br /&gt;
	Automatically generates a usage example in an Infobox /doc page based on the&lt;br /&gt;
	tags in the corresponding Infobox template.&lt;br /&gt;
]]--&lt;br /&gt;
function p.generateInfoboxExample(frame)&lt;br /&gt;
	&lt;br /&gt;
	--[[Check that both no-use options aren&amp;#039;t specified, because if they both are,&lt;br /&gt;
		it makes running all this code pointless because it&amp;#039;s not outputting anything.&lt;br /&gt;
	]]--&lt;br /&gt;
	if useInfobox(frame) or useExample(frame) then&lt;br /&gt;
		--Get page name passed in as first arg and strip &amp;quot;/doc&amp;quot; from it if it&amp;#039;s there&lt;br /&gt;
		local pageName = string.gsub(frame.args[1], &amp;quot;/doc&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
		&lt;br /&gt;
		--[[Create a title object with that page name and store the raw contents&lt;br /&gt;
			of that page in pageContent if the page exists&lt;br /&gt;
		]]--&lt;br /&gt;
		local pageContent = require(&amp;quot;Module:Common&amp;quot;).getContent(pageName, &amp;quot;Template&amp;quot;)&lt;br /&gt;
		&lt;br /&gt;
		--Return if there&amp;#039;s no page content because why bother?&lt;br /&gt;
		if not pageContent then&lt;br /&gt;
			--Error: Page doesn&amp;#039;t exist&lt;br /&gt;
			return &amp;quot;ERROR: PAGE TITLE &amp;quot; .. pageName .. &amp;quot; DOESN&amp;#039;T EXIST OR PAGE IS EMPTY&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--[[Initialize variables to store each stage of content parsing.&lt;br /&gt;
		&lt;br /&gt;
			exampleConcatTable &amp;amp; infoBoxConcatTable: Used as stacks to store&lt;br /&gt;
				pieces of the docOutput before they	get concatenated into&lt;br /&gt;
				docOutput because adding directly to docOutput each loop is much&lt;br /&gt;
				slower due to Lua garbage collecting immutable variables&lt;br /&gt;
				&lt;br /&gt;
			previousGroup: Flag that gets set to true when the most recent&lt;br /&gt;
				parsed tag is a &amp;quot;group&amp;quot; tag, then set to false again when&lt;br /&gt;
				parsing a non-group tag. This is a workaround to not output&lt;br /&gt;
				multiple linebreaks when there are 2 or more &amp;quot;group&amp;quot; tags parsed&lt;br /&gt;
				consecutively.&lt;br /&gt;
			&lt;br /&gt;
			infoBox: Will store the text specific to building the sample infobox&lt;br /&gt;
				at the last step of the process for code readability.&lt;br /&gt;
				&lt;br /&gt;
			usageExample: Will store the text specific to displaying the example&lt;br /&gt;
				infobox in &amp;lt;pre&amp;gt; tags for code readability.&lt;br /&gt;
				&lt;br /&gt;
			docOutput: For storing the final output for the doc page to be&lt;br /&gt;
				serve as a return value for code readability.&lt;br /&gt;
		]]--&lt;br /&gt;
		&lt;br /&gt;
		local exampleConcatTable = {}&lt;br /&gt;
		local infoBoxConcatTable = {}&lt;br /&gt;
		local previousGroup = false&lt;br /&gt;
		&lt;br /&gt;
		local infoBox = &amp;quot;&amp;quot;&lt;br /&gt;
		local usageExample = useExample(frame) and &amp;quot;Example Usage:&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;{{&amp;quot; .. pageName .. &amp;quot;\n&amp;quot; or &amp;quot;&amp;quot;&lt;br /&gt;
		local docOutput = &amp;quot;&amp;quot;&lt;br /&gt;
		&lt;br /&gt;
		--Make sure (trust that) the page contains an infobox based on an opening tag&lt;br /&gt;
		if isInfobox(pageContent) then&lt;br /&gt;
			&lt;br /&gt;
			--[[Split the raw pageContent by \r and \n and push strings to the stack&lt;br /&gt;
				based on the tag on that line.&lt;br /&gt;
					(This isn&amp;#039;t the most robust solution because tags not being&lt;br /&gt;
					properly separated by a new line can easily break this, but this&lt;br /&gt;
					can be made more robust in the future)&lt;br /&gt;
			]]--&lt;br /&gt;
			for s in string.gmatch(pageContent, &amp;quot;[^\r\n]+&amp;quot;) do&lt;br /&gt;
				if isFieldData(s) then&lt;br /&gt;
					local firstQuote = string.find( s, &amp;#039;&amp;quot;&amp;#039; )&lt;br /&gt;
					if firstQuote then&lt;br /&gt;
					&lt;br /&gt;
						firstQuote = firstQuote + 1&lt;br /&gt;
						&lt;br /&gt;
						local source = string.sub(s, firstQuote, string.find(s, &amp;#039;&amp;quot;&amp;#039;, firstQuote+1)-1)&lt;br /&gt;
						local example = &amp;quot;&amp;quot;&lt;br /&gt;
						&lt;br /&gt;
						if isImage(s) then&lt;br /&gt;
							example = &amp;quot;Placeholder.jpg&amp;quot;&lt;br /&gt;
							&lt;br /&gt;
						elseif isTitle(s) then&lt;br /&gt;
							example = pageName&lt;br /&gt;
						elseif isStatus(s) then&lt;br /&gt;
							example = &amp;quot;Active&amp;quot;&lt;br /&gt;
						else&lt;br /&gt;
							example = &amp;quot;Example&amp;quot;&lt;br /&gt;
						end&lt;br /&gt;
						&lt;br /&gt;
						if useExample(frame) then&lt;br /&gt;
							table.insert(exampleConcatTable, &amp;quot;|&amp;quot; .. source .. &amp;quot;=&amp;quot; .. example .. &amp;quot;\n&amp;quot;)&lt;br /&gt;
						end&lt;br /&gt;
						&lt;br /&gt;
						if useInfobox(frame) and not string.match(string.lower(s), &amp;quot;role&amp;quot;) then&lt;br /&gt;
							infoBoxConcatTable[source] = isImage(s) and &amp;quot;[[File:&amp;quot; .. example .. &amp;quot;]]&amp;quot; or example&lt;br /&gt;
						end&lt;br /&gt;
						&lt;br /&gt;
						previousGroup = false&lt;br /&gt;
					end&lt;br /&gt;
					&lt;br /&gt;
				elseif useExample(frame) and isGroup(s) then&lt;br /&gt;
					if not previousGroup then&lt;br /&gt;
						table.insert(exampleConcatTable, &amp;quot;\n&amp;quot;)&lt;br /&gt;
						previousGroup = true&lt;br /&gt;
					end&lt;br /&gt;
				&lt;br /&gt;
				elseif string.match(s, &amp;quot;&amp;lt;/infobox&amp;gt;&amp;quot;) then&lt;br /&gt;
					break&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			--Finally concatenate all the strings in the stack(s) into docOutput&lt;br /&gt;
			&lt;br /&gt;
			if useExample(frame) then&lt;br /&gt;
				usageExample = usageExample .. table.concat(exampleConcatTable) .. &amp;quot;}}&amp;lt;/pre&amp;gt;&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			if useInfobox(frame) then&lt;br /&gt;
				infoBox = frame:expandTemplate{ title=pageName, args=infoBoxConcatTable} .. &amp;quot;\n&amp;quot;&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			docOutput = infoBox .. usageExample&lt;br /&gt;
		else&lt;br /&gt;
			--Error: There wasn&amp;#039;t an infobox based on the search criteria&lt;br /&gt;
			return &amp;quot;ERROR: NO INFOBOX FOUND&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
		--Print that pretty doc to the page :)&lt;br /&gt;
		return docOutput&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>DrunkMunki</name></author>
	</entry>
</feed>