Jump to content

Module:Lang/documentor tool

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 13:32, 15 November 2017 (create;). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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

--[=[------------------------< L A N G - X X _ D E F A U L T 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 'error message';
	end
	
--	local page = mw.title.makeTitle ('Template', 'Lang-de');					-- get a page object for this page in 'Template:' namespace
	local content = page:getContent();											-- get unparsed content
	if not page then
		return 'error message';
	end

	local out = {};
	
	local params;

	if content:match ('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+|[^}]+}}') then			-- if this template uses [[Module:Lang]]
		params = content:match ('{{%s*#invoke:%s*[Ll]ang%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

		return table.concat ({table.concat (out,'\n|-\n! scope="row" | '), '\n|-\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;