Jump to content

Module:RoleInfobox: Difference between revisions

From Elite Dangerous Wiki
Content deleted Content added
mNo edit summary
m Updated MainImage width
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
local Infobox = {}
local Infobox = {}
local HF = require('Module:HF')
local HF = require('Module:HF')

function Infobox.trimTable ( trimTable )
output = {}
for i, value in ipairs(trimTable) do
output[i] = HF.trim(value)
end
return output
end


function Infobox.MainImage( field, vars )
function Infobox.MainImage( field, vars )
local output = field.Value
local output = field.Value
if not HF.isempty(output) then
if not HF.isempty(output) then
output = '[[File:' .. output .. '|250px]]'
output = '[[File:' .. output .. '|306px]]'
return output
return output
end
end
Line 14: Line 22:
if not HF.isempty(field.Value) then
if not HF.isempty(field.Value) then
local ships = HF.explode(';', field.Value)
local ships = HF.explode(';', field.Value)

ships = Infobox.trimTable(ships)
table.sort(ships)
table.sort(ships)

for i, ship in ipairs(ships) do
for i, ship in ipairs(ships) do
output = output .. HF.trim(ship) .. '<br />'
output = output .. HF.trim(ship) .. '<br />'
Line 20: Line 31:
if string.sub(output, -6) == '<br />' then
if string.sub(output, -6) == '<br />' then
output = string.sub( output, 1, -6 )
output = string.sub( output, 1, -7 )
end
end
Line 31: Line 42:
if not HF.isempty(field.Value) then
if not HF.isempty(field.Value) then
local upgrades = HF.explode(';', field.Value)
local upgrades = HF.explode(';', field.Value)

upgrades = Infobox.trimTable(upgrades)
table.sort(upgrades)
table.sort(upgrades)

for i, upgrade in ipairs(upgrades) do
for i, upgrade in ipairs(upgrades) do
output = output .. HF.trim(upgrade) .. '<br />'
output = output .. HF.trim(upgrade) .. '<br />'
Line 37: Line 51:
if string.sub(output, -6) == '<br />' then
if string.sub(output, -6) == '<br />' then
output = string.sub( output, 1, -6 )
output = string.sub( output, 1, -7 )
end
end

Latest revision as of 21:59, 7 June 2015

Documentation for this module may be created at Module:RoleInfobox/doc

local Infobox = {}
local HF = require('Module:HF')

function Infobox.trimTable ( trimTable )
    output = {}
    for i, value in ipairs(trimTable) do
        output[i] = HF.trim(value)
    end
    return output
end

function Infobox.MainImage( field, vars )
    local output = field.Value
    if not HF.isempty(output) then
        output = '[[File:' .. output .. '|306px]]'
        return output
    end
end

function Infobox.Ships( field, vars )
    local output = ''
    if not HF.isempty(field.Value) then
        local ships = HF.explode(';', field.Value)

        ships = Infobox.trimTable(ships)
        table.sort(ships)

        for i, ship in ipairs(ships) do
            output = output .. HF.trim(ship) .. '<br />'
        end
        
        if string.sub(output, -6) == '<br />' then
            output = string.sub( output, 1, -7 )
        end
        
        return output
    end
end

function Infobox.Upgrades( field, vars )
    local output = ''
    if not HF.isempty(field.Value) then
        local upgrades = HF.explode(';', field.Value)

        upgrades = Infobox.trimTable(upgrades)
        table.sort(upgrades)

        for i, upgrade in ipairs(upgrades) do
            output = output ..  HF.trim(upgrade) .. '<br />'
        end
        
        if string.sub(output, -6) == '<br />' then
            output = string.sub( output, 1, -7 )
        end
        
        return output
    end
end

return Infobox