Module:Draft

La bibliothèque libre.
Aller à la navigation Aller à la recherche
Documentation du module [voir] [modifier] [purger]
La documentation de ce module Scribunto écrit en Lua est incluse depuis sa sous-page de documentation.

Some live examples[modifier]

Examples of modules and their uses in live demo in debug phase:

Draft tests[modifier]

{{Draft|tests|QITEM=Q535}} Erreur Lua dans package.lua à la ligne 80 : module 'Module:Central-s-fr' not found.

local p = {}
local activity = p -- The main central module install central libraries and bind the main and sub modules
--	The template Modèle:Draft can test the module Module:Draft

local Central = require("Module:Central-s-fr") -- Module:ControlArgs control arguments, mixes translations and manage modules versions.

p.version = { -- Modules dependencies. Dependencias del módulo. Dépendances du module.
	versionName = "Draft", versionNumber = "1.0.0(180407:20:40)", versionDate = "2018-04-07T20:40", -- UTC
	-- UTC version structure : main.fonction.task(yymmdd:hh:mm)
	mainDescription = "Begin to use", functionDescription = "fonctional suport", taskDescription = "finalise doc mode",
	sought = "Central;Central-s-fr", -- Sought module and submodules versions
	known = "Central-s-fr;Central;Central-14 * Mathroman;Mathroman34", -- Known module and submodules versions
}

local ftd = ";"
ftd = ftd .. "activity.phabricator_tasks_report;activity.count_used_central_wikis;activity.rough_date_days;activity.init_central_versions;"
ftd = ftd .. "activity.central_subtasks_report;activity.describe_central_libraries;activity.init_selected_wiki;activity.begin_central_modules_suport;"
ftd = ftd .. "activity.central_libraries_report;"

ftd = ftd .. "central_object.binded_in;central_object.new;"

ftd = ftd .. "events.all_kinds_test;events.categories_lister;events.gener_categories;events.all_kinds_test_test;events.categ_Test;"
ftd = ftd .. "events.add_new;events.add_cat;events.add_cat_group;events.add_record;events.add_err;events.add_wng;events.add_err;"
ftd = ftd .. "events.is_category;events.is_error;events.is_warning;events.add_new;"
ftd = ftd .. "events.errors_lister;events.is_error;events.add_new;events.add_new;"

ftd = ftd .. "langs.main_i18n_languages_list;langs.selectLang;langs.selectLang_test;langs.i18n_lister;langs.abnormal_char_in_text;"
ftd = ftd .. "langs.formTestCase;langs.changing_translations;langs.missing_translations;"
ftd = ftd .. "langs.init_content_page_user_lang;langs.list_Mediawiki_languages;langs.dummy_languages;langs.translationsCounts;"
ftd = ftd .. "lua_table.sort_onkey;lua_table.sort_types;lua_table.to_sort_tests;lua_table.to_sort;"
ftd = ftd .. "lua_table.objfromsubnames;lua_table.tabfromsubnames;"
ftd = ftd .. "lua_table.counts;lua_table.count_values;lua_table.named_sub_counts;lua_table.formSubCounts;lua_table.count_types;"
ftd = ftd .. "lua_table.level_count;lua_table.count_all;lua_table.named_sub_counts;lua_table.formSubCounts;lua_table.count_tests;lua_table.level_list;"
ftd = ftd .. "lua_table.rough_view;lua_table.structure;lua_table.toList_tests;"
ftd = ftd .. "lua_table.toList;lua_table.toList_test;lua_table.toTable;lua_table.toTable_test;lua_table.to_sort;"

ftd = ftd .. "mathroman.int2roman;mathroman.int2roman_test;mathroman.roman2int;mathroman.roman2int_tests;mathroman.xxxxxx;"

ftd = ftd .. "modes.args_unknown_report;modes.options_from_mode;modes.options_from_mode_tests;modes.list_all_args_main;"
ftd = ftd .. "modes.bind_args_known_one_lib_report;modes.multiple_selection;modes.multiple_selection_tests;"
ftd = ftd .. "modes.all_errors_list;modes.all_categories_list;modes.args_known_structure;"
ftd = ftd .. "modes.similar_args_list;modes.namespaces_page_list;"
ftd = ftd .. "modes.used_options_list;modes.args_known_report;"
ftd = ftd .. "modes.multiple_values;modes.multiple_values_tests;"
ftd = ftd .. "modes.recursiveNormal;modes.recursiveNormal_tests;"

ftd = ftd .. "tableview.form_one_case;tableview.new;"

ftd = ftd .. "versions.setup_central_libraries;versions.bind_all_sub_modules_test;versions.deprecatedFunction;"
ftd = ftd .. "versions.tab_elem_report;versions.form_suport_desk_report;versions.running_times;"
ftd = ftd .. "versions.versions_management_test;versions.versions_management_report;versions.tasks_changes_report;"
ftd = ftd .. "versions.sort_central_modules_report;versions.all_G_and_loaded_list;"
ftd = ftd .. "versions.anti_crash;versions.anti_crash_tests;"

ftd = ftd .. "viewer.form9content;viewer.form9en;viewer.form9user;viewer.form9content;viewer.form9en;viewer.form9page;viewer.trans9vars;"
ftd = ftd .. "viewer.form99content;viewer.form99user;viewer.trans99vars;viewer.form99page;viewer.form99user;viewer.discreet_main_version;"
ftd = ftd .. "viewer.deleteColor;viewer.discreetColor;viewer.normalColor;viewer.warningColor;"
ftd = ftd .. "viewer.invokeColor;viewer.usualColor;viewer.errorColor;viewer.wikidataColor;viewer.addColor;"
ftd = ftd .. "viewer.smallCapsStyle;viewer.classDayTimeStyle;viewer.errorColor;viewer.wikidataColor;"
ftd = ftd .. "viewer.form9user_test;viewer.form_functionalCSS;viewer.form_image;viewer.form_main_version;viewer.form_result;viewer.formatDate;"
ftd = ftd .. "viewer.sort_central_modules_report;viewer.all_G_and_loaded_list;"
ftd = ftd .. "viewer.docSection;viewer.docPage;viewer.docGroup;viewer.docInternal;viewer.docModule;viewer.docPage;"
ftd = ftd .. "viewer.day_to_stamp;viewer.date_to_part;viewer.day_to_UTC;viewer.parts_of_date_tests;iewer.tableView_test;viewer.boxview_test;"
ftd = ftd .. "viewer.is_in;viewer.is_in_sp;viewer.ta;viewer.tam;viewer.rough_view;viewer.isDef;format_time_tests;"
ftd = ftd .. "viewer.simpleList;viewer.simpleList_test;viewer.ta;viewer.tam;viewer.rough_view;viewer.rough_view_test;format_time_tests;"
ftd = ftd .. "viewer.anti_crash;viewer.anti_crash_tests;"

activity.functions_to_doc = ftd

---------------------- on 20180317 transfer activity.central_libraries_autodoc() from ModuleCentral-s-fr.lua to ModuleDraft.lua
---------------------- on 2018-04-07T20:40 Update ModuleDraft.lua
function activity.to_sort(tab, sortfield, sortorder) -- To sort any table and convert in sequence if needed.
--	"20180307", "NOW", "Rical", "S180810lts", "new function
	local tab = tab or {}
	if (type(tab) == "string") then
		tab = mw.text.split(tab) -- table to sort
	end
	if (type(tab) ~= "table") then tab = {} end
	if not ( (type(sortfield) == "number") or (type(sortfield) == "string") ) then sortfield = 1 end
	if (type(sortorder) ~= "string") then sortorder = "<" end
	local sorted, i = {}, 0
	for key, elem in pairs(tab) do
		i = i + 1
		table.insert(sorted, elem)
	end
	table.sort(sorted, function (a, b) return ( ( a[sortfield] ) < ( b[sortfield] ) ) end ) -- Sort libraries
	return sorted
end -- local sorted = activity.to_sort(tab, sortfield, sortorder) -- To sort any table and convert in sequence if needed.

function activity.to_sort(tab, sortfield, sortorder) -- To sort any table and convert in sequence if needed.
--	"20180307", "NOW", "Rical", "S180810lts", "new function
	local t = viewer.ta("\n* Begin tab", tab ) .. viewer.ta("sortfield", sortfield) .. viewer.ta("sortorder", sortorder)
	local tab = tab or {}
	if (type(tab) == "string") then
		tab = mw.text.split(tostring(tab), ';') -- table to sort
	end
	t = t .. viewer.ta("\n* Count of central libraries", lua_table.level_count(libname_libraries) )
	if (type(tab) ~= "table") then tab = {} end
	if not ( (type(sortfield) == "number") or (type(sortfield) == "string") ) then sortfield = 1 end
	if (type(sortorder) ~= "string") then sortorder = "<" end
	local sorted, i = {}, 0
	for key, elem in pairs(tab) do
		i = i + 1
		table.insert(sorted, elem)
	end
	if (type(sortfield) == "string") then
		table.sort(sorted, function (a, b) return ( ( a[sortfield or "a"] ) < ( b[sortfield or "b"] ) ) end ) -- Sort libraries
	end
	if (type(sortfield) == "number") then
--		table.sort(sorted, function (a, b) return ( ( a[sortfield or 1] ) < ( b[sortfield or 1] ) ) end ) -- Sort libraries
	end
	t = t .. viewer.ta("\n* End tab", tab ) .. viewer.ta("sortfield", sortfield) .. viewer.ta("sortorder", sortorder)
	return sorted, (t or "activity.to_sort()")
end -- local sorted = activity.to_sort(tab, sortfield, sortorder) -- To sort any table and convert in sequence if needed.

function activity.sort_central_libraries_functions(sorted_central_libraries) -- Select and sort central libraries and functions
	local sorted_central_libraries = sorted_central_libraries or {} -- To sort any table and convert in sequence if needed.
	local sorted_functions = {}
	for libname, lib in pairs(package.loaded) do -- search directly in package.loaded
		if(type(lib) == "table") and (type(lib.i18n) == "table") and (type(libname) == "string") -- Select central i18n objects
		and (not string.find(libname, ":") ) then -- Avoid central modules
			lib.libname = libname
			table.insert(sorted_central_libraries, lib)
			for funcname, func in pairs(lib) do -- search directly in package.loaded Rical 20180321
				if (type(func) == "function") then -- select central libraries
					libname_funcname = libname .. "." .. funcname
					table.insert(sorted_functions, { ["libname"] = libname, ["funcname"] = funcname, ["libname_funcname"] = libname_funcname } )
				end
			end
		end
	end
	table.sort(sorted_central_libraries, function (a, b) return ( a.libname < b.libname ) end ) -- Sort libraries
	table.sort(sorted_functions, function (a, b) return ( (a.libname_funcname < b.libname_funcname ) ) end ) -- Sort libraries
	activity.sorted_central_libraries = sorted_central_libraries
	activity.sorted_functions = sorted_functions
	return sorted_central_libraries, sorted_functions
end -- local sorted_central_libraries, sorted_functions = activity.sort_central_libraries_functions() -- Select and sort central libraries and functions

-- Last
function activity.central_libraries_report(t) -- List actual functions for documentations. subtask S171128laf "now",
	local t = t or "\n* <b>activity.central_libraries_report(t)</b> List all actual functions."
	t = t .. '\n* Selected functions come from: <b>activity.functions_to_doc</b> = "<b>;activity.central_libraries_report;datas.get_datas;events.add_cat;</b>"'
	t = t .. "\n* The fonctions to document are in bold like <b>activity.central_libraries_report</b>"
	local sorted_central_libraries, sorted_functions = activity.sort_central_libraries_functions() -- Select and sort central libraries and functions
	local libname, funcname, libname_funcname, asterisk = "", "", "", ""
	t = t .. viewer.ta("\n* Count of central libraries", lua_table.level_count(sorted_central_libraries) )
	local nlibfunc, nallfunc, nlibdoc, nalldoc = 0, 0, 0, 0
	local sorted_to_autodoc = {}
	for i, lib in pairs(sorted_central_libraries) do
		nlibfunc = 0
		nlibdoc = 0
		lib.libname = (lib.libname or lib.name or "libname")
		t = t .. "\n* <b>Library " .. libname .. "</b>: "
		for i, func_record in pairs(sorted_functions) do -- search all functions
			if func_record.libname == lib.libname then
				nallfunc = nallfunc + 1
				nlibfunc = nlibfunc + 1
				libname_funcname = tostring(func_record.libname_funcname)
				asterisk = ""
				if string.find(activity.functions_to_doc, libname_funcname, 1, true) then --OK
					nlibdoc = nlibdoc + 1
					nalldoc = nalldoc + 1
					t = t .. " <b>" .. libname_funcname .. "</b>, "
					table.insert(sorted_to_autodoc, { ["name"] = name, ["funcname"] = funcname, ["libname_funcname"] = libname_funcname } )
				else
					t = t .. libname_funcname .. ", "
				end
			end
		end
		table.insert(sorted_functions, { ["name"] = name, ["funcname"] = funcname, ["libname_funcname"] = libname_funcname } )
		t = t .. viewer.ta("* <i>Count of functions in this library</i>", nlibfunc) .. viewer.ta("<i>to document</i>", nlibdoc)
	end
	table.sort(sorted_functions, function (a, b) return ( (a.libname_funcname < b.libname_funcname ) ) end ) -- Sort libraries
	t = t .. viewer.ta("\n* <i>Count of functions in all libraries</i>", nallfunc)
	t = t .. viewer.ta("<i>functions to doc</i>", lua_table.level_count(sorted_funcs) )
	t = t .. viewer.ta("<i>functions with doc</i>", nalldoc)
	t = t .. viewer.ta("\n* <b>Count of sorted functions: </b>", lua_table.level_count(sorted_functions) )
	activity.sorted_functions = sorted_functions
	activity.sorted_to_autodoc = sorted_to_autodoc
	return t
end -- function activity.central_libraries_report(t)
-- Last

function activity.central_libraries_autodoc(t, sorted_functions) -- Form a basic documentation for sorted functions.
	local t = t or "\n* <b>activity.central_libraries_autodoc(t)</b> Form a basic documentation for sorted functions."
	t = t .. "\n*"
--	if 1 then return t end
	local sorted_functions = sorted_functions or activity.sorted_functions
--	local xxx = activity.central_libraries_report(t, sorted_functions)
--	<br>[[:#= = = --- = = =|= = = %1 = = =]]
	local one_autodoc = "<br>[[= = = %1 = = =]]<br> "
	for i, lib_func in pairs(activity.sorted_to_autodoc) do -- form one_autodoc
		t = t .. viewer.form9user(one_autodoc, lib_func.libname_funcname)
	end
	t = string.gsub(tostring(t), "= = =", "===")
	t = string.gsub(tostring(t), "= =", "==")
	return t
end -- function activity.central_libraries_autodoc(t, sorted_functions)

function activity.tests(frame)
	local res = ""
	res = res .. Central.init(frame, Central.Central_version, "tests", Central.args_known, Central.options_for_modes)
--	res = res .. t
--	modes.args_import, t = modes.import_arguments()
	res = res .. "\n* getEntityIdForCurrentPage = " .. tostring( mw.wikibase.getEntityIdForCurrentPage() ) -- Returns the Item id as string, like "Q42"
	res = res .. "\n* Tests of Module:Draft"
	res = res .. activity.central_libraries_report()
	res = res .. activity.central_libraries_autodoc(t, sorted_functions) -- Form a basic documentation for sorted functions.
	return res
end -- function Central.tests(frame)
-- Modèle for tests of Module:Draft
-- Module:Draft/Documentation

return activity -- The main central module install central libraries and bind the main and sub modules