Module:Optional style
模块文档[创建]
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。 本模块的子页面。 |
--[=[
Simple module to construct a style attribute with an undefined number (including
zero) of CSS properties
]=]
local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
--[=[
Construct the string from the given table of property:values
]=]
function p.make_style_string(properties)
local out = ''
local num_processed = 0
for k, v in pairs(properties) do
if k ~= 'style' and v~= '' then
out = out .. k .. ':' .. v .. ';'
end
end
if properties.style ~= nil and properties.style ~= '' then
out = out .. properties.style
end
if out == '' then
return ''
end
return 'style="' .. out .. '"'
end
--[=[
The main entry function from templates
Arguments are taken from both frame and parent argument lists
]=]
function p.optional_style(frame)
local args = getArgs(frame)
return p.make_style_string(args)
end
return p