Dota 2 Wiki
mNo edit summary
mNo edit summary
Line 1: Line 1:
 
local cargo = mw.ext.cargo
 
local cargo = mw.ext.cargo
local getArgs = require( 'Module:Arguments' ).main
+
local getArgs = require( 'Module:Arguments' ).getArgs
 
local p = {}
 
local p = {}
   
 
function p.main( frame )
 
function p.main( frame )
local args = getArgs()
+
local args = getArgs(frame, {
  +
wrappers = {
return p._main( args )
 
  +
'Template:Team icon'
  +
}
  +
})
 
return p._main( args )
 
end
 
end
   
 
function p._main( args )
 
function p._main( args )
if args[1] then
+
if args[1] then
local name = args[1]
+
local name = args[1]
local size = args[2] or '40px'
+
local size = args[2] or '40px'
local icon = 'File:Team icon Default.png'
+
local icon = 'File:Team icon Default.png'
  +
 
local cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1]
+
local cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1]
if cargo_output and cargo_output['icon'] ~= '' then
+
if cargo_output and cargo_output['icon'] ~= '' then
name = cargo_output['name']
+
name = cargo_output['name']
icon = 'File:' .. cargo_output['icon']
+
icon = 'File:' .. cargo_output['icon']
else
+
else
local success, result = pcall( function( file ) return mw.title.new( file ).fileExists end, 'File:Team icon ' .. args[1] .. '.png' )
+
local success, result = pcall( function( file ) return mw.title.new( file ).fileExists end, 'File:Team icon ' .. args[1] .. '.png' )
if success == true and result == true then
+
if success == true and result == true then
icon = 'File:Team icon ' .. args[1] .. '.png'
+
icon = 'File:Team icon ' .. args[1] .. '.png'
end
+
end
end
+
end
  +
 
return '[[' .. icon .. '|' .. size .. '|link=' .. args[1] .. '|' .. name .. ']]'
+
return '[[' .. icon .. '|' .. size .. '|link=' .. args[1] .. '|' .. name .. ']]'
else
+
else
return error( 'Check your input', 0 )
+
return error( 'Check your input', 0 )
end
+
end
 
end
 
end
   

Revision as of 13:17, 20 April 2018

Documentation for Module:Team icon Jump to code ↴ [ edit | purge ]

Reality Rift icon
▶️ Planeshift.
The documentation for this module can be found at Template:Team icon.
You may be forwarded to another wiki language, in case a translation is not available.


Dependencies

local cargo = mw.ext.cargo
local getArgs = require( 'Module:Arguments' ).getArgs
local p = {}

function p.main( frame )
  local args = getArgs(frame, {
    wrappers = {
      'Template:Team icon'
    }
  })
  return p._main( args )
end

function p._main( args )
  if args[1] then
    local name = args[1]
    local size = args[2] or '40px'
    local icon = 'File:Team icon Default.png'
    
    local cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1]
    if cargo_output and cargo_output['icon'] ~= '' then
      name = cargo_output['name']
      icon = 'File:' .. cargo_output['icon']
    else
      local success, result = pcall( function( file ) return mw.title.new( file ).fileExists end, 'File:Team icon ' .. args[1] .. '.png' )
      if success == true and result == true then
        icon = 'File:Team icon ' .. args[1] .. '.png'
      end
    end
  
    return '[[' .. icon .. '|' .. size .. '|link=' .. args[1] .. '|' .. name .. ']]'
  else
    return error( 'Check your input', 0 )
  end
end

return p