Module:Cs1 documentation support: Difference between revisions
From All Skies Encyclopaedia
imported>Trappist the monk m (Trappist the monk moved page Module:Cs1 lang lister to Module:Cs1 documentation support without leaving a redirect: better title because functionality in this module is diversifying;) |
imported>Trappist the monk No edit summary |
||
Line 1: | Line 1: | ||
--[[-------------------------< L I S T |
--[[-------------------------< A D D _ T O _ L I S T >--------------------------------------------------------- |
||
adds code/name pair to code_list and name/code pair to name_list; code/name pairs in override_list replace those |
adds code/name pair to code_list and name/code pair to name_list; code/name pairs in override_list replace those |
||
Line 18: | Line 18: | ||
code_list[code] = override_list[code] .. dagger; -- use the name from the override table; mark with dagger |
code_list[code] = override_list[code] .. dagger; -- use the name from the override table; mark with dagger |
||
name_list[override_list[code]] = code .. dagger; |
name_list[override_list[code]] = code .. dagger; |
||
-- code_list[code] = override_list[code] .. '<sup>†</sup>'; -- use the name from the override table; mark with dagger |
|||
-- name_list[override_list[code]] = code .. '<sup>†</sup>'; |
|||
else |
else |
||
code_list[code] = name; -- use the MediaWiki name and code |
code_list[code] = name; -- use the MediaWiki name and code |
||
Line 41: | Line 39: | ||
--[[-------------------------< L I S T E R > |
--[[-------------------------< L A N G _ L I S T E R >--------------------------------------------------------- |
||
Module entry point |
Module entry point |
||
Line 47: | Line 45: | ||
Crude documentation tool that returns one of several lists of language codes and names. |
Crude documentation tool that returns one of several lists of language codes and names. |
||
{{#invoke: |
{{#invoke:cs1 documentation support|lang_lister|list=<selector>}} |
||
where <selector> is one of the values: |
where <selector> is one of the values: |
||
Line 57: | Line 55: | ||
]] |
]] |
||
local function |
local function lang_lister (frame) |
||
local source_list = mw.language.fetchLanguageNames(mw.getContentLanguage():getCode(), 'all'); |
local source_list = mw.language.fetchLanguageNames(mw.getContentLanguage():getCode(), 'all'); |
||
local override = require ("Module:Citation/CS1/Configuration").lang_code_remap; |
local override = require ("Module:Citation/CS1/Configuration").lang_code_remap; |
||
Line 106: | Line 104: | ||
--[[--------------------------< S C R I P T _ L I S T E R > |
--[[--------------------------< S C R I P T _ L A N G _ L I S T E R >------------------------------------------ |
||
Module entry point |
Module entry point |
||
Line 112: | Line 110: | ||
Crude documentation tool that returns list of language codes and names supported by the various |script-<param>= parameters. |
Crude documentation tool that returns list of language codes and names supported by the various |script-<param>= parameters. |
||
{{#invoke: |
{{#invoke:cs1 documentation support|script_lang_lister}} |
||
]] |
]] |
||
local function |
local function script_lang_lister () |
||
local lang_code_src = mw.loadData ('Module:Citation/CS1/Configuration').script_lang_codes ; -- get list of allowed script language codes |
local lang_code_src = mw.loadData ('Module:Citation/CS1/Configuration').script_lang_codes ; -- get list of allowed script language codes |
||
local override = require ("Module:Citation/CS1/Configuration").lang_code_remap; |
local override = require ("Module:Citation/CS1/Configuration").lang_code_remap; |
||
Line 171: | Line 169: | ||
for k, v in pairs (list) do -- loop through the list to make a simple unordered list |
for k, v in pairs (list) do -- loop through the list to make a simple unordered list |
||
table.insert (out, table.concat ({'*', k, ': ', v})); |
table.insert (out, table.concat ({'*', k, ': ', v})); |
||
end |
|||
table.sort (out); -- sort it |
|||
return table.concat (out, '\010'); -- concatenate with \n |
|||
-- return (mw.dumpObject (list)) |
|||
end |
|||
--[[--------------------------< C A N O N I C A L _ P A R A M _ L I S T E R >---------------------------------- |
|||
experimental code that lists canonical parameter names. Perhaps basis for some sort of documentation? |
|||
{{#invoke:cs1 documentation support|canonical_param_lister}} |
|||
]] |
|||
local function canonical_param_lister () |
|||
local alias_src = mw.loadData ('Module:Citation/CS1/Configuration').aliases; -- get master list of aliases |
|||
local key; -- key for k/v in a new table |
|||
local list = {}; -- interim list of aliases |
|||
local out = {}; -- final output (for now an unordered list) |
|||
for _, aliases in pairs (alias_src) do -- loop through the master list of aliases |
|||
if 'table' == type (aliases) then -- table only when there are aliases |
|||
table.insert (list, aliases[1]); -- first member of an aliases table is declared canonical |
|||
else |
|||
table.insert (list, aliases); -- for those parameters that do not have any aliases, the parameter is declared canonical |
|||
end |
|||
end |
|||
for _, param in ipairs (list) do -- loop through the list to make a simple unordered list |
|||
table.insert (out, table.concat ({'*', param})); |
|||
end |
end |
||
Line 197: | Line 227: | ||
return { |
return { |
||
alias_lister = alias_lister, |
alias_lister = alias_lister, |
||
canonical_param_lister = canonical_param_lister, |
|||
id_limits_get = id_limits_get, |
id_limits_get = id_limits_get, |
||
lang_lister = lang_lister, |
|||
lister = lister, |
|||
script_lang_lister = script_lang_lister, |
|||
⚫ | |||
lister = lang_lister, -- this invoke deprecated |
|||
⚫ | |||
}; |
}; |
Revision as of 18:25, 4 April 2020
Documentation for this module may be created at Module:Cs1 documentation support/doc
--[[-------------------------< A D D _ T O _ L I S T >---------------------------------------------------------
adds code/name pair to code_list and name/code pair to name_list; code/name pairs in override_list replace those
taken from the MediaWiki list; these are marked with a superscripted dagger.
|script-<param>= lang codes always use override names so dagger is omitted
]]
local function add_to_list (code_list, name_list, override_list, code, name, dagger)
if false == dagger then
dagger = ''; -- no dagger for |script-<param>= codes and names
else
dagger = '<sup>†</sup>'; -- dagger for all other lists using override
end
if override_list[code] then -- look in the override table for this code
code_list[code] = override_list[code] .. dagger; -- use the name from the override table; mark with dagger
name_list[override_list[code]] = code .. dagger;
else
code_list[code] = name; -- use the MediaWiki name and code
name_list[name] = code;
end
end
--[[-------------------------< L I S T _ F O R M A T >---------------------------------------------------------
formats key/value pair into a string for rendering
['k'] = 'v' → k: v
]]
local function list_format (result, list)
for k, v in pairs (list) do
table.insert (result, k .. ': ' .. v);
end
end
--[[-------------------------< L A N G _ L I S T E R >---------------------------------------------------------
Module entry point
Crude documentation tool that returns one of several lists of language codes and names.
{{#invoke:cs1 documentation support|lang_lister|list=<selector>}}
where <selector> is one of the values:
2char – list of ISO 639-1 codes and names sorted by code
3char – list of ISO 639-2, -3 codes and names sorted by code
ietf – list of IETF language tags and names sorted by tag -- not supported by cs1|2 |language= parameter
name – list of language names and codes sorted by name -- IETF tags omitted because not supported by cs1|2 |language= parameter
]]
local function lang_lister (frame)
local source_list = mw.language.fetchLanguageNames(mw.getContentLanguage():getCode(), 'all');
local override = require ("Module:Citation/CS1/Configuration").lang_code_remap;
local code_1_list={};
local code_2_list={};
local ietf_list={};
local name_list={};
if not ({['2char']=true, ['3char']=true, ['ietf']=true, ['name']=true})[frame.args.list] then
return '<span style="font-size:100%" class="error">unknown list selector: ' .. frame.args.list .. '</span>';
end
-- if 'ietf' == frame.args.list then -- ietf codes not currently supported by cs1|2 |language= parameter
-- return '<span style="font-size:100%" class="error">ietf language tags not supported by cs1|2</span>'
-- end
for code, name in pairs (source_list) do
if 2 == code:len() then
add_to_list (code_1_list, name_list, override, code, name);
elseif 3 == code:len() then
add_to_list (code_2_list, name_list, override, code, name);
else -- ietf codes not currently supported by cs1|2 |language= parameter
add_to_list (ietf_list, name_list, override, code, name);
end
end
local result = {};
local out = {};
if '2char' == frame.args.list then
list_format (result, code_1_list);
elseif '3char' == frame.args.list then
list_format (result, code_2_list);
elseif 'ietf' == frame.args.list then
list_format (result, ietf_list);
else --must be 'name'
list_format (result, name_list);
end
table.sort (result);
table.insert (result, 1, '<div class="div-col columns column-width" style="column-width:20em">');
table.insert (out, table.concat (result, '\n*'));
table.insert (out, '</div>');
return table.concat (out, '\n');
end
--[[--------------------------< S C R I P T _ L A N G _ L I S T E R >------------------------------------------
Module entry point
Crude documentation tool that returns list of language codes and names supported by the various |script-<param>= parameters.
{{#invoke:cs1 documentation support|script_lang_lister}}
]]
local function script_lang_lister ()
local lang_code_src = mw.loadData ('Module:Citation/CS1/Configuration').script_lang_codes ; -- get list of allowed script language codes
local override = require ("Module:Citation/CS1/Configuration").lang_code_remap;
local this_wiki_lang = mw.language.getContentLanguage().code; -- get this wiki's language
local code_list = {}; -- interim list of aliases
local name_list={}; -- not used; defined here so that we can reuse add_to_list()
local out = {}; -- final output (for now an unordered list)
for _, code in ipairs (lang_code_src) do -- loop throu the list of code
local name = mw.language.fetchLanguageName (code, this_wiki_lang); -- get the language name associated with this code
add_to_list (code_list, name_list, override, code, name, false); -- name_list{} not used but provided so that we can reuse add_to_list(); don't add superscript dagger
end
local result = {};
local out = {};
list_format (result, code_list);
table.sort (result);
table.insert (result, 1, '<div class="div-col columns column-width" style="column-width:20em">');
table.insert (out, table.concat (result, '\n*'));
table.insert (out, '</div>');
return table.concat (out, '\n');
end
--[[--------------------------< A L I A S _ L I S T E R >------------------------------------------------------
experimental code that lists parameters and their aliases. Perhaps basis for some sort of documentation?
]]
local function alias_lister ()
local alias_src = mw.loadData ('Module:Citation/CS1/Configuration').aliases; -- get master list of aliases
local key; -- key for k/v in a new table
local list = {}; -- interim list of aliases
local out = {}; -- final output (for now an unordered list)
for _, aliases in pairs (alias_src) do -- loop throu the master list of aliases
if 'table' == type (aliases) then -- table only when there are aliases
for i, alias in ipairs (aliases) do -- loop through all of the aliases
if 1 == i then -- first 'alias' is the canonical parameter name
key = alias; -- so it becomes the key in list
else
list[key] = list[key] and (list[key] .. ', ' .. alias) or alias; -- make comma-separated list of aliases
list[alias] = 'see ' .. key; -- make a back reference from this alias to the canonical parameter
end
end
end
end
for k, v in pairs (list) do -- loop through the list to make a simple unordered list
table.insert (out, table.concat ({'*', k, ': ', v}));
end
table.sort (out); -- sort it
return table.concat (out, '\010'); -- concatenate with \n
-- return (mw.dumpObject (list))
end
--[[--------------------------< C A N O N I C A L _ P A R A M _ L I S T E R >----------------------------------
experimental code that lists canonical parameter names. Perhaps basis for some sort of documentation?
{{#invoke:cs1 documentation support|canonical_param_lister}}
]]
local function canonical_param_lister ()
local alias_src = mw.loadData ('Module:Citation/CS1/Configuration').aliases; -- get master list of aliases
local key; -- key for k/v in a new table
local list = {}; -- interim list of aliases
local out = {}; -- final output (for now an unordered list)
for _, aliases in pairs (alias_src) do -- loop through the master list of aliases
if 'table' == type (aliases) then -- table only when there are aliases
table.insert (list, aliases[1]); -- first member of an aliases table is declared canonical
else
table.insert (list, aliases); -- for those parameters that do not have any aliases, the parameter is declared canonical
end
end
for _, param in ipairs (list) do -- loop through the list to make a simple unordered list
table.insert (out, table.concat ({'*', param}));
end
table.sort (out); -- sort it
return table.concat (out, '\010'); -- concatenate with \n
-- return (mw.dumpObject (list))
end
--[[--------------------------< I D _ L I M I T S _ G E T >----------------------------------------------------
return the limit values for named identifier parameters that have id limits (pmc, pmid, ssrn); the return value
used in template documentation and error message help-text
]]
local function id_limits_get (frame)
local id_limits = mw.loadData ('Module:Citation/CS1/Configuration/sandbox').id_limits; -- get id_limits {} table from ~/Configuration
return id_limits[frame.args[1]];
end
--[[-------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
]]
return {
alias_lister = alias_lister,
canonical_param_lister = canonical_param_lister,
id_limits_get = id_limits_get,
lang_lister = lang_lister,
script_lang_lister = script_lang_lister,
lister = lang_lister, -- this invoke deprecated
script_lister = script_lang_lister,
};