“模块:Ship Specs”的版本间的差异

来自星际公民宇宙百科
跳转至: 导航搜索
第4行: 第4行:
 
local specs = mw.text.jsonDecode(json)
 
local specs = mw.text.jsonDecode(json)
 
mw.log(#specs)
 
mw.log(#specs)
local h_root = mw.html.create('')
+
local h_table = mw.html.create('table'):addClass('ship-specs-table')
local h_table = h_root:tag('table'):addClass('ship-specs-table');
 
 
if specs["Name"] then
 
if specs["Name"] then
local h_td = h_table.tag('tr'):addClass('ship-specs-name'):tag('td')
+
h_table:tag('tr'):addClass('ship-specs-name'):tag('td'):attr({ width="100%", colspan="2" }):tag('b'):wikitext(specs["Name"])
h_td:attr({ width="100%", colspan="2" })
 
h_td:tag('b'):wikitext(specs["Name"])
 
 
end
 
end
 
if specs["Image"] then
 
if specs["Image"] then
local h_td = h_table.tag('tr'):addClass('ship-specs-image'):tag('td')
+
h_table:tag('tr'):addClass('ship-specs-image'):tag('td'):attr({ width="100%", colspan="2" }):wikitext(specs["Image"])
h_td:attr({ width="100%", colspan="2" })
 
h_td:wikitext(specs["Image"])
 
 
end
 
end
return tostring(root)
+
return tostring(h_table)
 
end
 
end
  

2015年10月4日 (日) 20:36的版本

此模块的文档可以在模块:Ship Specs/doc创建

local p = {}

function p.text( json )
	local specs = mw.text.jsonDecode(json)
	mw.log(#specs)
	local h_table = mw.html.create('table'):addClass('ship-specs-table')
	if specs["Name"] then
		h_table:tag('tr'):addClass('ship-specs-name'):tag('td'):attr({ width="100%", colspan="2" }):tag('b'):wikitext(specs["Name"])
	end
	if specs["Image"] then
		h_table:tag('tr'):addClass('ship-specs-image'):tag('td'):attr({ width="100%", colspan="2" }):wikitext(specs["Image"])
	end
	return tostring(h_table)
end

function p.main( frame )
	return p.text(frame.args[1])
end

return p