Module:AFE

Èn årtike di Wiccionaire.
Potchî a: naiviaedje, cweri

La documentation pour ce module peut être créée à Module:AFE/doc

-- This module makes span AFE for each argument
-- Only use with Modele:AFE as :
-- {{AFE|arg1|arg2|...}} 
local p = {}

function render(text)
	
	-- style should be copied to the style sheet
	-- MediaWiki:Common.css
	local span_ = '<span class="afe" style="font-family:DejaVu Sans,Segoe UI,Segoe UI Symbol,Lucida Grande,Arial Unicode MS,Lucida Sans Unicode,Charis SIL,Doulos SIL,Gentium,GentiumAlt,Adobe Pi Std,Code2000,Chrysanthi Unicode,TITUS Cyberbit Basic,Bitstream Cyberbit,Hiragino Kaku Gothic Pro,Matrix Unicode,sans-serif;white-space:nowrap;">'
	local _span = '</span>'
					
	-- trim white spaces
	text = mw.text.trim(text)
	
	-- unicode char U+02C8 for primary stress, not « ' »
	text = string.gsub(text, "'", "ˈ")
	-- unicode char U+02D0 for long sound, not « : »
	text = string.gsub(text, ":", "ː")
	
	-- no treat .+ or … as AFE
	-- just return …
	if text == "" or string.find(text, '^%.+$') or text == "…" then
		return "…[[Categoreye:Årtikes avou des prononçaedjes a radjouter]]"
	end
	
	-- add / if needed
	if string.sub(text, 1, 1) ~= "/" then
		text = '/' .. text
	end
	if string.sub(text, -1) ~= "/" then
		text = text .. '/'
	end
				
	return span_ .. text .. _span
end

-- Entry point of the module
function p.init(frame)
	local html = ''
	local i = 0
	local dup = {}
	local is_dup = false
	
	-- for each argument of the parent modele
	local modele = mw.getCurrentFrame():getParent()
	for key,val in ipairs(modele.args) do
		-- check duplicated arg
		if dup[val] ~= nil then
			is_dup = true
		else
			dup[val] = true
		
			-- white space between each span
			if i > 0 then
				html = html .. ' ' 
			end
			
			html = html .. render(val)
			i = i + 1
		end
	end
	
	if is_dup then
		html = html .."[[Categoreye:Årtikes avou des doblons dins l' modele AFE]]"
	end
			
    return html
end

return p