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

来自星际公民宇宙百科
跳转至: 导航搜索
第9行: 第9行:
 
return tostring(mw.dumpObject( json ))
 
return tostring(mw.dumpObject( json ))
 
end
 
end
 +
 +
function p.dumpencode( frame )
 +
return tostring(mw.dumpObject(mw.text.encode(frame.args[1])))
 +
end
 +
 +
  
 
function p.text( json )
 
function p.text( json )

2015年10月5日 (一) 08:22的版本

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

local p = {}

function p.unstripNoWiki( frame )
	return tostring(mw.text.unstripNoWiki(frame.args[1]))
end

function p.dumpObject( frame )
	local json = (string.gsub(frame.args[1], "<[/]?pre>", ""))
	return tostring(mw.dumpObject( json ))
end

function p.dumpencode( frame )
	return tostring(mw.dumpObject(mw.text.encode(frame.args[1])))
end



function p.text( json )
	json = mw.text.decode(json)
	json = (string.gsub(json, "<[/]?pre>", ""))
	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