Documentação do módulo[ver] [editar] [histórico] [purgar]

Implements {{ULS}}.

--[=[
Implements [[Template:ULS]]
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local make_attribute_string = require('Module:Optional CSS attribute').make_attribute_string

function p._ULS(args)
	-- lang attribute
	local lang_attr = make_attribute_string('lang', {['lang'] = args.lang})
	
	-- font
	local fonts = {}
	for k, v in pairs(args) do
		if string.sub(k, 1, 4) == 'font' and tonumber(string.sub(k, 5)) and v then
			fonts[tonumber(string.sub(k, 5))] = v
		end
	end
	fonts[#fonts + 1] = 'serif'
	local font_family = table.concat(fonts, ", ")
	
	-- font size
	local font_size
	if args['font-size'] then
		font_size = args['font-size'] .. "%"
	end
	
	-- style attribute
	local style_args = {
		['font-family'] = font_family,
		['font-size'] = font_size,
		['style'] = args.extra
	}
	local style_attr = make_attribute_string('style', style_args)
	
	-- class attribute
	local class_attr = make_attribute_string('class', {['class'] = args.class})
	
	-- other attributes
	local attr = args.attr
	
	-- all attributes
	local all_attr = table.concat({lang_attr, style_attr, class_attr, attr}, " ")
	
	-- content
	local content = args[1] or ''
	
	-- put it all together
	return "<span " .. all_attr .. ">" .. content .. "</span>"
end

function p.ULS(frame)
	return p._ULS(getArgs(frame))
end

return p