diff --git a/Other/Su.lua b/Other/Su.lua new file mode 100644 index 0000000..dbb8de8 --- /dev/null +++ b/Other/Su.lua @@ -0,0 +1,74 @@ +-- Mô đun này thực hiện {{su}}. + +local p = {} + +function p.main(frame) + -- Use arguments from the parent frame only, and remove any blank arguments. + -- We don't need to trim whitespace from any arguments, as this module only + -- uses named arguments, and whitespace is trimmed from them automatically. + local origArgs = frame:getParent().args + local args = {} + for k, v in pairs(origArgs) do + if v ~= '' then + args[k] = v + end + end + + -- Define the variables to pass to luaMain. + local sup = args.p + local sub = args.b + local options = { + align = args.a, + fontSize = args.w, + lineHeight = args.lh, + verticalAlign = args.va + } + return p._main(sup, sub, options) +end + +function p._main(sup, sub, options) + options = options or {} + local span = mw.html.create('span') + + -- Set the styles. + span:css{ + ['display'] = 'inline-block', + ['margin-bottom'] = '-0.3em', + ['vertical-align'] = options.verticalAlign or sub and '-0.4em' or '0.8em', + ['line-height'] = options.lineHeight or '1.2em' + } + if options.fontSize == 'f' or options.fontSize == 'fixed' then + span:css{ + ['font-family'] = 'monospace', + ['font-size'] = '80%' + } + else + span:css('font-size', options.fontSize or '80%') + end + if options.align == 'r' or options.align == 'right' then + span:css('text-align', 'right') + elseif options.align == 'c' or options.align == 'center' then + span:css('text-align', 'center') + else + span:css('text-align', 'left') + end + + -- Add the wikitext. + span + :tag('sup') + :css('font-size', 'inherit') + :css('line-height', 'inherit') + :css('vertical-align', 'baseline') + :wikitext(sup) + :done() + :tag('br', {selfClosing = true}):done() + :tag('sub') + :css('font-size', 'inherit') + :css('line-height', 'inherit') + :css('vertical-align', 'baseline') + :wikitext(sub) + + return tostring(span) +end + +return p diff --git a/Other/Table empty cell.lua b/Other/Table empty cell.lua new file mode 100644 index 0000000..27aaf97 --- /dev/null +++ b/Other/Table empty cell.lua @@ -0,0 +1,59 @@ +local p = {} + +-- List of default title texts. +local defaultTitleTextlist = { + ["TBA"] = "Chưa thông báo", + ["TBD"] = "Chưa xác định", + ["N/A"] = "Không có" +} + +-- Local function which is used to retrieve the title text. +local function getTitleText(args, altText) + local titleText = args[2] or args["title_text"] + + -- If the title text was manually added, return it. + if (titleText) then + return titleText + end + + -- The title text was not set, get the correct default text which corresponds to the alt text. + for k, v in pairs(defaultTitleTextlist) do + if (altText == k) then + return v + end + end +end + +-- Local function which is used to retrieve the alt text. +local function getAltText(args) + local altText = args[1] or args["alt_text"] + + if (altText == nil) then + altText = "TBA" + end + + return altText +end + +-- Local function which does the actual main process. +function p._main(args) + local altText = getAltText(args) + local titleText = getTitleText(args, altText) + + return "" .. altText .. "" +end + +--[[ +Public function which is used to create information for an empty text cell. + +Parameters: + -- |1= or |alt_text= — optional; The text which will be written in the cell. + -- |2= or |title_text= — optional; The text which will be shown when hovering over the cell. +--]] +function p.main(frame) + local getArgs = require('Module:Arguments').getArgs; + local args = getArgs(frame); + return p._main(args) +end + +return p diff --git a/Other/Tone superscript.lua b/Other/Tone superscript.lua new file mode 100644 index 0000000..4fbb205 --- /dev/null +++ b/Other/Tone superscript.lua @@ -0,0 +1,13 @@ +local p = {} + +function p.main(frame) + local root = mw.html.create() + local arg = frame:getParent().args[1] or "" + local x = arg:gsub("%f[%d%s]([%d*]+)", "%1") + root:tag('span'):wikitext(x) + local tracking = '' + if string.match(arg, "") then tracking = '[[Thể loại:Trang sử dụng Tone superscript với sup tag]]' end + return tostring(root)..tracking +end + +return p diff --git a/Testcases/Separated entries.lua b/Testcases/Separated entries.lua new file mode 100644 index 0000000..858eeb3 --- /dev/null +++ b/Testcases/Separated entries.lua @@ -0,0 +1,86 @@ +-- Unit tests for [[Module:Separated entries]]. Click talk page to run tests. +local p = require('Module:UnitTests') + +function p:test_main() + self:preprocess_equals_many('{{#invoke:Separated entries|main|', '}}', { + {'', ''}, + {'A', 'A'}, + {'A|B', 'AB'}, + {'A||B', 'AB'}, -- empty parameter + {'A|B|C', 'ABC'}, + {'separator=,', ''}, + {'separator=,|A', 'A'}, + {'separator=,|A|B', 'A,B'}, + {'separator=,|A||B', 'A,B'}, -- empty parameter + {'conjunction=;', ''}, + {'conjunction=;|A', 'A'}, + {'conjunction=;|A|B', 'A;B'}, + {'separator=,|conjunction=;', ''}, + {'separator=,|conjunction=;|A', 'A'}, + {'separator=,|conjunction=;|A|B', 'A;B'}, + {'separator=,|conjunction=;|A|B|C', 'A,B;C'}, + {'separator=,|conjunction=;|A|B|C|D', 'A,B,C;D'}, + {'start=2|separator=,|conjunction=;|A|B|C|D', 'B,C;D'}, + {'dataPlural=1', ''}, + {'dataPlural=1|A', 'A'}, + {'dataPlural=1|A|B', 'AB'}, + {'dataPlural=1|A||B', 'AB'}, -- empty parameter + {'dataPlural=1|A|B|C', 'ABC'}, + {'dataPlural=1|separator=,', ''}, + {'dataPlural=1|separator=,|A', 'A'}, + {'dataPlural=1|separator=,|A|B', 'A,B'}, + {'dataPlural=1|separator=,|A||B', 'A,B'}, -- empty parameter + {'dataPlural=1|conjunction=;', ''}, + {'dataPlural=1|conjunction=;|A', 'A'}, + {'dataPlural=1|conjunction=;|A|B', 'A;B'}, + {'dataPlural=1|separator=,|conjunction=;', ''}, + {'dataPlural=1|separator=,|conjunction=;|A', 'A'}, + {'dataPlural=1|separator=,|conjunction=;|A|B', 'A;B'}, + {'dataPlural=1|separator=,|conjunction=;|A|B|C', 'A,B;C'}, + {'dataPlural=1|separator=,|conjunction=;|A|B|C|D', 'A,B,C;D'}, + {'dataPlural=1|start=2|separator=,|conjunction=;|A|B|C|D', 'B,C;D'}, + },{nowiki=1}) +end + +function p:test_sandbox() + self:preprocess_equals_many('{{#invoke:Separated entries/sandbox|main|', '}}', { + {'', ''}, + {'A', 'A'}, + {'A|B', 'AB'}, + {'A||B', 'AB'}, -- empty parameter + {'A|B|C', 'ABC'}, + {'separator=,', ''}, + {'separator=,|A', 'A'}, + {'separator=,|A|B', 'A,B'}, + {'separator=,|A||B', 'A,B'}, -- empty parameter + {'conjunction=;', ''}, + {'conjunction=;|A', 'A'}, + {'conjunction=;|A|B', 'A;B'}, + {'separator=,|conjunction=;', ''}, + {'separator=,|conjunction=;|A', 'A'}, + {'separator=,|conjunction=;|A|B', 'A;B'}, + {'separator=,|conjunction=;|A|B|C', 'A,B;C'}, + {'separator=,|conjunction=;|A|B|C|D', 'A,B,C;D'}, + {'start=2|separator=,|conjunction=;|A|B|C|D', 'B,C;D'}, + {'dataPlural=1', ''}, + {'dataPlural=1|A', 'A'}, + {'dataPlural=1|A|B', 'AB'}, + {'dataPlural=1|A||B', 'AB'}, -- empty parameter + {'dataPlural=1|A|B|C', 'ABC'}, + {'dataPlural=1|separator=,', ''}, + {'dataPlural=1|separator=,|A', 'A'}, + {'dataPlural=1|separator=,|A|B', 'A,B'}, + {'dataPlural=1|separator=,|A||B', 'A,B'}, -- empty parameter + {'dataPlural=1|conjunction=;', ''}, + {'dataPlural=1|conjunction=;|A', 'A'}, + {'dataPlural=1|conjunction=;|A|B', 'A;B'}, + {'dataPlural=1|separator=,|conjunction=;', ''}, + {'dataPlural=1|separator=,|conjunction=;|A', 'A'}, + {'dataPlural=1|separator=,|conjunction=;|A|B', 'A;B'}, + {'dataPlural=1|separator=,|conjunction=;|A|B|C', 'A,B;C'}, + {'dataPlural=1|separator=,|conjunction=;|A|B|C|D', 'A,B,C;D'}, + {'dataPlural=1|start=2|separator=,|conjunction=;|A|B|C|D', 'B,C;D'}, + },{nowiki=1}) +end + +return p