Module:IPAc-en/sandbox: Difference between revisions

Content deleted Content added
No edit summary
apparently the rest of the module relies on the padding being added, so how about padding with the empty string?
 
(30 intermediate revisions by 6 users not shown)
Line 1:
-- This module implements [[Template:IPAc-en]].
 
-- local data = mw.loadData('Module:IPAc-en/data')
local data = mw.loadData('Module:IPAc-en/data/sandbox')
local currentFrame = mw.getCurrentFrame()
local p = {}
 
Line 13 ⟶ 11:
local function trim(s)
return s:match('^%s*(.-)%s*$')
end
 
-- This implements [[Template:Nowrap]].
local function makeNowrapSpan(s)
local span = mw.html.create('span')
:addClass('rt-commentedText') -- Works with [[MediaWiki:Gadget-ReferenceTooltips.js]]
:addClass('nowrap')
:wikitext(labels)
return tostring(span)
end
 
Line 24 ⟶ 31:
-- This adds a tooltip icon to a label. It implements [[Template:H:title]].
local function makeTooltip(label, tooltip)
local span =-- mw.html.create( doesn't properly escape 'span|')
return string.format(
:attr('title', tooltip)
'<span title="%s">%s</span>',
:wikitext(label)
mw.text.encode(tooltip, '|'),
return tostring(span)
label
})
end
 
Line 43 ⟶ 52:
local function renderCategories()
local ret = ''
ret = categoryHandler{
[1] = 'yes', -- Add categories in these namespaces
main = 1,
wikipedia = 1,
file = 1,
template = 1,
help = 1,
category = 1,
portal = 1,
book = 1,
draft = 1,
module = 1,
}
if retcategoryHandler{ ==true 'yes'} then
ret = {}
for cat in pairs(categories) do
Line 82 ⟶ 78:
if pronItem then
pron[#pron + 1] = pronItem
pron[#pronif + 1]pronItem ~= '' 'then
pron[#pron + 1] = ' '
else
pron[#pron + 1] = ''
}end
else
break
Line 88:
end
if #pron > 0 then
ret[#ret + 1] = mw.getCurrentFrame():extensionTag({
name = 'templatestyles',
args = { src = 'Module:IPA/styles.css' }
})
ret[#ret + 1] = string.format(
'<span class="IPA-label IPA-label-small">%s</smallspan>',
table.concat(pron)
)
Line 121 ⟶ 125:
categories["Ill-formatted IPAc-en transclusions"] = true
words[#words + 1] = formatPhonemeGroup(phonemes)
-- Call [[Template:Error]]
local errorText = currentFrame:expandTemplate{
title = 'Template:Error',
args = {
string.format("[invalid input: '%s']", id)
}
}
words[#words + 1] = makeTooltip(
errorText,string.format(
"<strong class=\"error\">[invalid input: '%s']</strong>",
args = { id
}),
'Unrecognized symbol'
)
Line 158:
local span = mw.html.create('span')
-- Suppress Navigation popups and Page Previews (aka Hovercards)
:addClass('nowrap IPA nopopups noexcerpt')
:attr('titlelang', tooltip'en-fonipa')
:wikitext(string.format(
'[[Help:IPA/English|%s]]',
Line 171 ⟶ 172:
local file = args.audio and trim(args.audio)
if file and file ~= '' then
categories["ArticlesPages including recorded pronunciations (English)"] = true
if args[1] and string.lower(trim(args[1])) == 'uk' then
ret[#ret + 1] = currentFramemw.getCurrentFrame():expandTemplate{
categories["Articles including recorded pronunciations (UK English)"] = true
elseif args[1] and string.lower(trim(args[1])) == 'us' then
categories["Articles including recorded pronunciations (US English)"] = true
else
categories["Articles including recorded pronunciations (English)"] = true
end
ret[#ret + 1] = currentFrame:expandTemplate{
title = 'Template:IPA audio link', args = { file } }
end
end
-- Nowrap and categories
ret = makeNowrapSpan(table.concat(ret)) .. renderCategories()
 
-- Reset the categories table in case we are run again.
categories = {}