Module:Lang/documentor tool: Difference between revisions

From Zoophilia Wiki
Jump to navigationJump to search
meta>Trappist the monk
+sandbox;
meta>Trappist the monk
No edit summary
Line 25: Line 25:
local params;
local params;
local style;


if content:match ('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+|[^}]+}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}') then -- if this template uses [[Module:Lang]]
if content:match ('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+|[^}]+}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}') then -- if this template uses [[Module:Lang]]
params = content:match ('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+(|[^}]+)}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}') -- extract the #invoke:'s parameters
style, params = content:match ('{{%s*#invoke:%s*[Ll]ang%s*|([^|]+)(|[^}]+)}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}') -- extract the #invoke:'s parameters
if not params then  
if not params then  
return ''; -- there should be at least one or the template/module won't work TODO: error message?
return ''; -- there should be at least one or the template/module won't work TODO: error message?
Line 36: Line 37:
end
end


return table.concat ({table.concat (out,'\n|-\n! scope="row" | '), '\n|-\n|}'}); -- add inter-row markup and close the wikitable and done
style = style:match ('lang_xx_(.*)');
return table.concat ({table.concat (out,'\n|-\n! scope="row" | '), '\n|-\n|style: ', style, '\n|-|}'}); -- add inter-row markup and close the wikitable and done
else
else
return ''; -- does not use [[Module:Lang]] so abandon quietly
return ''; -- does not use [[Module:Lang]] so abandon quietly

Revision as of 10:23, 24 December 2017

Documentation for this module may be created at Module:Lang/documentor tool/doc

require('Module:No globals');
local p = {};

--[=[------------------------< L A N G - X X _ S E T T I N G S >-----------------------------------------------

{{#invoke:Lang/documentor tool|lang_xx_settings|template={{ROOTPAGENAME}}}}

reads the content of the template and extracts the parameters from {{#invoke:Lang|...}} for display on the template's
documentation page

]=]

function p.lang_xx_settings (frame)
	local page = mw.title.makeTitle ('Template', frame.args['template'] or frame.args[1]);	-- get a page object for this page in 'Template:' namespace
	if not page then
		return '';																-- TODO: error message?
	end
	
	local content = page:getContent();											-- get unparsed content
	if not page then
		return '';																-- TODO: error message?
	end

	local out = {};
	
	local params;
	local style;

	if content:match ('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+|[^}]+}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}') then			-- if this template uses [[Module:Lang]]
		style, params = content:match ('{{%s*#invoke:%s*[Ll]ang%s*|([^|]+)(|[^}]+)}}') or content:match ('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}')	-- extract the #invoke:'s parameters
		if not params then 
			return '';															-- there should be at least one or the template/module won't work TODO: error message?
		end
		table.insert (out, '{| class="wikitable" style="text-align:right; float:right"\n|+settings')	-- start a wikitable
		for k, v in params:gmatch ('%s*|%s*([^%s=]+)%s*=%s*([^%s|]+)') do		-- get the parameter names (k) and values (v)
			table.insert (out, table.concat ({k, '\n|', v}));					-- make rudimentary wikitable entries
		end

		style = style:match ('lang_xx_(.*)');
		return table.concat ({table.concat (out,'\n|-\n! scope="row" | '), '\n|-\n|style: ', style, '\n|-|}'});	-- add inter-row markup and close the wikitable and done
	else
		return '';																-- does not use [[Module:Lang]] so abandon quietly
	end
end

return p;