Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Sandbox/Chao: Difference between revisions

From BlazBlue Wiki
m (save function for dumping tables to console)
m (test lua and template expansion)
Line 1: Line 1:
--[[
--[[
{{#invoke:Sandbox/Chao|GallerySection|character=Noel Vermillion|section=Portraits}}
simulate passing a frame to the function in the console with:
simulate passing a frame to the function in the console with:
myFrame = { args = { '1', '2', namedparam = "value" } }
myFrame = { args = { character='Noel Vermillion', section='Portraits' } }
=p.BBRadio ( myFrame )
=p.GallerySection ( myFrame )
--]]
--]]


Line 8: Line 9:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo


function p.BBRadio( frame )
function p.testExpandTemplate(frame)
intro = frame.args['intro'] or ''
frame:expandTemplate{ title = 'h', args = { '|' } }
intro = html_escape(intro)
end
 
limit = frame.args['limit'] or 100
function p.GallerySection(frame)
_character = frame.args.character or ''
link_parts = {
_source = frame.args.source or ''
'tables=Files,BBRadio_Cuts',
_section = frame.args.section or ''
'fields=Files._pageName, Files.Caption',
_limit = frame.args.limit or 4
'where=Files.Characters HOLDS "' .. html_escape(frame.args[1]) .. '" AND BBRadio_Cuts.Season="' .. frame.args[2] .. '"',
_title = frame.args.title or ''
'join_on=Files._pageName=BBRadio_Cuts._pageName',
_header = frame.args.header or ''
'order_by=_pageName',
_see_all = frame.args.see_all or ''
'format=gallery',
_see_cameo = frame.args.see_cameo or ''
'offset=0',
_count_all = frame.args.count_all or ''
'limit=' .. limit,
'default=',
'intro=' .. intro,
'show bytes=0',
'show dimensions=0',
'show filename=0',
'caption field=Caption',
'image width=250'
}
link = html_escape(concatvalues(link_parts,"&"))
parts = {
frame:expandTemplate{ title = 'Gallery Section (Cargo)', args = {
'https://blazblue.wiki/index.php\?title=Special:ViewData&',
  character = _character
link,
    ,source = _source
'">'
  ,section = _section
}
    ,limit = _limit
final_link = concatvalues(parts,"")
    ,title = _title
mw.log(final_link)
    ,header = _header
return final_link
} }
end
end



Revision as of 01:05, 11 September 2019

Script error: The function "main" does not exist.


--[[
{{#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 )
--]]

local p = {}
local cargo = mw.ext.cargo

function p.testExpandTemplate(frame)
	frame:expandTemplate{ title = 'h', args = { '|' } }
end

function p.GallerySection(frame)
	_character = frame.args.character or ''
	_source = frame.args.source or ''
	_section = frame.args.section or ''
	_limit = frame.args.limit or 4
	_title = frame.args.title or ''
	_header = frame.args.header or ''
	_see_all = frame.args.see_all or ''
	_see_cameo = frame.args.see_cameo or ''
	_count_all = frame.args.count_all or ''
	
	frame:expandTemplate{ title = 'Gallery Section (Cargo)', args = { 
		  character = _character
		    ,source = _source
		   ,section = _section
		     ,limit = _limit
		     ,title = _title
		    ,header = _header
	} }
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