迪士尼Wiki
探索
首页
讨论板
所有页面
社区页
交互式地图
最新博文
角色
传统角色
米奇老鼠
米妮老鼠
高飞
布鲁托
唐老鸭
男英雄
辛巴
匹诺曹
野兽
阿修
女英雄
樂佩公主
艾莎
安娜
梅莉達
歐若拉
恶棍
邪惡皇后
电影
經典動畫長片
101忠狗
猫儿历险记
狮子王2
失落的帝国
仙履奇缘3
公主与青蛙
冰雪奇缘
加勒比海盗:黑珍珠号的诅咒
真人动作电影
101斑点狗2
加勒比海盗:世界的尽头
后裔
明日世界
星球大战:新的希望
欢乐满人间
沉睡魔咒
灰姑娘2
电视剧
音樂情人夢
超能高校生
救難小福星
下課後
女孩看世界
飞哥与小佛
导演
比尔·坎登
华特·迪士尼
约翰·拉萨特
克里斯·巴克
张云明
演员
丹·史蒂文斯
埃玛·华森
路克·伊凡斯
乔什·盖德
伊旺·麦奎格
海伦娜·伯翰·卡特
更多
游戏
樂高超人特攻隊
冰雪奇缘:自由落体
书籍
冰雪奇缘绘本
歌曲
我看见光芒
我的人生何时奇航
我有了一个梦想
放開手
游乐场
探險世界
小小世界
幻想世界
明日世界
社区
管理员
Laundry Machine
HansJie
分类方针
FANDOM
游戏
电影
电视
wiki
探索wiki
社区中心
创建wiki
尚未注册?
注册
登录
登录
注册
你好,迪士尼的粉丝们!
431
个页面
探索
首页
讨论板
所有页面
社区页
交互式地图
最新博文
角色
传统角色
米奇老鼠
米妮老鼠
高飞
布鲁托
唐老鸭
男英雄
辛巴
匹诺曹
野兽
阿修
女英雄
樂佩公主
艾莎
安娜
梅莉達
歐若拉
恶棍
邪惡皇后
电影
經典動畫長片
101忠狗
猫儿历险记
狮子王2
失落的帝国
仙履奇缘3
公主与青蛙
冰雪奇缘
加勒比海盗:黑珍珠号的诅咒
真人动作电影
101斑点狗2
加勒比海盗:世界的尽头
后裔
明日世界
星球大战:新的希望
欢乐满人间
沉睡魔咒
灰姑娘2
电视剧
音樂情人夢
超能高校生
救難小福星
下課後
女孩看世界
飞哥与小佛
导演
比尔·坎登
华特·迪士尼
约翰·拉萨特
克里斯·巴克
张云明
演员
丹·史蒂文斯
埃玛·华森
路克·伊凡斯
乔什·盖德
伊旺·麦奎格
海伦娜·伯翰·卡特
更多
游戏
樂高超人特攻隊
冰雪奇缘:自由落体
书籍
冰雪奇缘绘本
歌曲
我看见光芒
我的人生何时奇航
我有了一个梦想
放開手
游乐场
探險世界
小小世界
幻想世界
明日世界
社区
管理员
Laundry Machine
HansJie
分类方针
查看“Module:HtmlBuilder”的源代码
返回页面
| ←
Module:HtmlBuilder
查看源代码
查看历史
讨论 (0)
因为以下原因,您没有权限编辑本页:
此页面已被保护以防止编辑或其他操作。
您可以查看和复制此页面的源代码。
-- Module for building complex HTML (e.g. infoboxes, navboxes) using a fluent interface. local HtmlBuilder = {} local metatable = {} metatable.__index = function(t, key) local ret = rawget(t, key) if ret then return ret end ret = metatable[key] if type(ret) == 'function' then return function(...) return ret(t, ...) end else return ret end end metatable.__tostring = function(t) local ret = {} t._build(ret) return table.concat(ret) end metatable._build = function(t, ret) if t.tagName then table.insert(ret, '<' .. t.tagName) for i, attr in ipairs(t.attributes) do table.insert(ret, ' ' .. attr.name .. '="' .. attr.val .. '"') end if #t.styles > 0 then table.insert(ret, ' style="') for i, prop in ipairs(t.styles) do if type(prop) == 'string' then -- added with cssText() table.insert(ret, prop .. ';') else -- added with css() table.insert(ret, prop.name .. ':' .. prop.val .. ';') end end table.insert(ret, '"') end if t.selfClosing then table.insert(ret, ' /') end table.insert(ret, '>') end for i, node in ipairs(t.nodes) do if node then if type(node) == 'table' then node._build(ret) else table.insert(ret, tostring(node)) end end end if t.tagName and not t.unclosed and not t.selfClosing then table.insert(ret, '</' .. t.tagName .. '>') end end metatable.node = function(t, builder) if builder then table.insert(t.nodes, builder) end return t end metatable.wikitext = function(t, ...) local vals = {...} for i = 1, #vals do if vals[i] then table.insert(t.nodes, vals[i]) end end return t end metatable.newline = function(t) table.insert(t.nodes, '\n') return t end metatable.tag = function(t, tagName, args) args = args or {} args.parent = t local builder = HtmlBuilder.create(tagName, args) table.insert(t.nodes, builder) return builder end local function getAttr(t, name) for i, attr in ipairs(t.attributes) do if attr.name == name then return attr end end end metatable.attr = function(t, name, val) if type(val) == 'string' or type(val) == 'number' then -- if caller sets the style attribute explicitly, then replace all styles previously added with css() and cssText() if name == 'style' then t.styles = {val} return t end local attr = getAttr(t, name) if attr then attr.val = val else table.insert(t.attributes, {name = name, val = val}) end end return t end metatable.addClass = function(t, class) if class then local attr = getAttr(t, 'class') if attr then attr.val = attr.val .. ' ' .. class else t.attr('class', class) end end return t end metatable.css = function(t, name, val) if type(val) == 'string' or type(val) == 'number' then for i, prop in ipairs(t.styles) do if prop.name == name then prop.val = val return t end end table.insert(t.styles, {name = name, val = val}) end return t end metatable.cssText = function(t, css) if css then table.insert(t.styles, css) end return t end metatable.done = function(t) return t.parent or t end metatable.allDone = function(t) while t.parent do t = t.parent end return t end function HtmlBuilder.create(tagName, args) args = args or {} local builder = {} setmetatable(builder, metatable) builder.nodes = {} builder.attributes = {} builder.styles = {} builder.tagName = tagName builder.parent = args.parent builder.unclosed = args.unclosed or false builder.selfClosing = args.selfClosing or false return builder end return HtmlBuilder --[[Category:模块]]
返回
Module:HtmlBuilder
。
Follow on IG
TikTok
Join Fan Lab