Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Other/Su.lua
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions Other/Table empty cell.lua
Original file line number Diff line number Diff line change
@@ -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 "<small><span style=\"color: #2C2C2C\" title=\"" .. titleText .. "\">" .. altText .. "</span></small>"
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
13 changes: 13 additions & 0 deletions Other/Tone superscript.lua
Original file line number Diff line number Diff line change
@@ -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*]+)", "<sup>%1</sup>")
root:tag('span'):wikitext(x)
local tracking = ''
if string.match(arg, "</?sup>") then tracking = '[[Thể loại:Trang sử dụng Tone superscript với sup tag]]' end
return tostring(root)..tracking
end

return p
86 changes: 86 additions & 0 deletions Testcases/Separated entries.lua
Original file line number Diff line number Diff line change
@@ -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<span style="display:none" data-plural="0"></span>'},
{'dataPlural=1|separator=,|A|B', 'A,B<span style="display:none" data-plural="1"></span>'},
{'dataPlural=1|separator=,|A||B', 'A,B<span style="display:none" data-plural="1"></span>'}, -- empty parameter
{'dataPlural=1|conjunction=;', ''},
{'dataPlural=1|conjunction=;|A', 'A<span style="display:none" data-plural="0"></span>'},
{'dataPlural=1|conjunction=;|A|B', 'A;B<span style="display:none" data-plural="1"></span>'},
{'dataPlural=1|separator=,|conjunction=;', ''},
{'dataPlural=1|separator=,|conjunction=;|A', 'A<span style="display:none" data-plural="0"></span>'},
{'dataPlural=1|separator=,|conjunction=;|A|B', 'A;B<span style="display:none" data-plural="1"></span>'},
{'dataPlural=1|separator=,|conjunction=;|A|B|C', 'A,B;C<span style="display:none" data-plural="1"></span>'},
{'dataPlural=1|separator=,|conjunction=;|A|B|C|D', 'A,B,C;D<span style="display:none" data-plural="1"></span>'},
{'dataPlural=1|start=2|separator=,|conjunction=;|A|B|C|D', 'B,C;D<span style="display:none" data-plural="1"></span>'},
},{nowiki=1})
end

return p
Loading