More actions
m (test lua and template expansion) |
m (test lua and template expansion) |
||
Line 4: | Line 4: | ||
myFrame = { args = { character='Noel Vermillion', section='Portraits' } } | myFrame = { args = { character='Noel Vermillion', section='Portraits' } } | ||
=p.GallerySection ( myFrame ) | =p.GallerySection ( myFrame ) | ||
=p.testExpandTemplate( myFrame ) | |||
--]] | --]] | ||
Line 10: | Line 11: | ||
function p.testExpandTemplate(frame) | function p.testExpandTemplate(frame) | ||
text = p.GallerySection(frame, 'BlazBlue: Central Fiction', '', 8, 'title', 'h3', 'y', 'y', '7') | |||
return text | |||
end | end | ||
function p.GallerySection(frame) | function p.GallerySection(frame, source, section, limit, title, header, see_all, see_cameo, count_all) | ||
_character = frame.args.character or '' | _character = frame.args.character or '' | ||
_source = frame.args.source or '' | _source = frame.args.source or source or '' | ||
_section = | _section = section or '' | ||
_limit = | _limit = tonumber(limit) or 4 | ||
_title = | _title = title or '' | ||
_header = | _header = header or '' | ||
_see_all = | _see_all = see_all or '' | ||
_see_cameo = | _see_cameo = see_cameo or '' | ||
_count_all = | _count_all = count_all or '' | ||
gallery = frame:expandTemplate{ title = 'Gallery Section (Cargo)', args = { | gallery = frame:expandTemplate{ title = 'Gallery Section (Cargo)', args = { | ||
Line 31: | Line 35: | ||
,title = _title | ,title = _title | ||
,header = _header | ,header = _header | ||
,see_all = _see_all | |||
,see_cameo = _see_cameo | |||
,count_all = _count_all | |||
} } | } } | ||
Revision as of 01:28, 11 September 2019
--[[
{{#invoke:Sandbox/Chao|GallerySection|character=Noel Vermillion|section=Portraits}}
simulate passing a frame to the function in the console with:
myFrame = { args = { character='Noel Vermillion', section='Portraits' } }
=p.GallerySection ( myFrame )
=p.testExpandTemplate( myFrame )
--]]
local p = {}
local cargo = mw.ext.cargo
function p.testExpandTemplate(frame)
text = p.GallerySection(frame, 'BlazBlue: Central Fiction', '', 8, 'title', 'h3', 'y', 'y', '7')
return text
end
function p.GallerySection(frame, source, section, limit, title, header, see_all, see_cameo, count_all)
_character = frame.args.character or ''
_source = frame.args.source or source or ''
_section = section or ''
_limit = tonumber(limit) or 4
_title = title or ''
_header = header or ''
_see_all = see_all or ''
_see_cameo = see_cameo or ''
_count_all = count_all or ''
gallery = frame:expandTemplate{ title = 'Gallery Section (Cargo)', args = {
character = _character
,source = _source
,section = _section
,limit = _limit
,title = _title
,header = _header
,see_all = _see_all
,see_cameo = _see_cameo
,count_all = _count_all
} }
return gallery
end
-- concat all the strings in table s together with the given delimiter
function concatvalues(s,delimiter)
local t = { }
for k,v in ipairs(s) do
t[#t+1] = tostring(v)
end
return table.concat(t,delimiter)
end
function html_escape(s)
return (string.gsub(s, "[<>\"'/ ,]", {
["<"] = "%3C",
[">"] = "%3E",
['"'] = "%22",
["'"] = "%27",
["/"] = "%2F",
[" "] = "+",
[","] = "%2C"
}))
end
-- helpful for printing tables
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
return p