Module:Module sandbox/sandbox: Difference between revisions
Appearance
Content deleted Content added
No edit summary Tag: Reverted |
Undid revision 1186997155 by 5.64.158.190 (talk) |
||
Line 22: | Line 22: | ||
local lang_link_wikilink = make_language_wikilink(lang_code) |
local lang_link_wikilink = make_language_wikilink(lang_code) |
||
return "! style=\"padding-left:0.5em\" | "..lang_link_wikilink.. |
return "! style=\"padding-left:0.5em\" | "..lang_link_wikilink.. |
||
"\n |
"\n|".. frame:expandTemplate{ title = 'lang', args = {lang_code, lang_text} } |
||
end |
end |
||
Revision as of 20:36, 26 November 2023
![]() | This is the module sandbox page for Module:Module sandbox (diff). |
Usage
{{#invoke:Module sandbox|function_name}}
Example
{{#invoke:Module sandbox|main}}
yields:
Hello world!
Documentation
Package items
sandbox.hello_world(name)
(function)- Prints hello world
- Parameter:
name
Person to address (string) - Returns: hello world string
- TODO: make it say "Hello, [name]".
sandbox.main(frame)
(function)- Main entrypoint.
- Parameter:
frame
calling frame (table) - Returns: output wikitext
local lang = require('Module:Lang')
local language_names = mw.loadData('Module:Lang/data').lang_name_table.lang
local p = {}
local SEPARATOR = '|- style="border-bottom:1px solid #aaa"\n'
local STYLE = "border-bottom:1px solid #aaa"
local function make_table_start(width, font_size, name)
return '{| class="mw-collapsible mw-collapsed" style="width:'..width..';'..
'font-size:' .. font_size .. '; text-align:left; border-collapse:collapse;'..'\n'..
'! colspan=2 style="text-align:center; border-top: 0px;" | '..name..'\n'
end
-- todo: link to articles properly
local function make_language_wikilink(lang_code)
local article_name = 'Main Page'
local display = language_names[lang_code]
return '[['..article_name..'|'..display..']]'
end
local function make_language_row(frame, lang_code, lang_text)
local lang_link_wikilink = make_language_wikilink(lang_code)
return "! style=\"padding-left:0.5em\" | "..lang_link_wikilink..
"\n|".. frame:expandTemplate{ title = 'lang', args = {lang_code, lang_text} }
end
function p.main(frame)
local output = ''
output = output .. make_table_start(
frame.args.width,
frame.args.font_size,
frame.args.name) .. SEPARATOR
for k,v in pairs(frame.args) do
if language_names[k] then
output = output .. make_language_row(frame, k, v) .. '\n' .. SEPARATOR
end
end
return output
end
return p