Module:Optional CSS attribute
![文档图示](http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。 本模块的子页面。 |
--[=[
Simple module to construct a CSS attribute with an undefined number (including zero) of CSS properties
]=]
require('strict')
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_attribute_string(attribute, properties)
if not attribute or not properties or mw.text.trim(attribute) == '' or properties == {} then
return ''
end
attribute = mw.text.trim(attribute)
local out = ''
for p, v in pairs(properties) do
local property = mw.text.trim(p)
local value = mw.text.trim(v)
if property ~= attribute and property ~= '' and value ~= '' then
out = out .. property .. ':' .. value .. ';'
end
end
if properties[attribute] then
out = out .. mw.text.trim(properties[attribute])
end
if out == '' then
return ''
end
return attribute .. '="' .. out .. '"'
end
--[=[
The main entry function from templates
Arguments are taken from both frame and parent argument lists
]=]
function p.optional_CSS_attribute(frame)
local args = getArgs(frame)
local attribute = args[1] or args.attribute
args[1] = nil
args.attribute = nil
return p.make_attribute_string(attribute, args)
end
return p