Jump to content

Module:MaterialInfobox: Difference between revisions

From Elite Dangerous Wiki
Content deleted Content added
m One last try to see if I'm being sane
All of this should work, but maybe we only want some of it.
Line 35: Line 35:
end
end


--[[ Everything after this is stuff you may or may not want to keep --]]
function SplitRunFunction(func_name, default, field, vars)
function SplitRunFunction(func_name, field, vars, value)
if type( func_name ) == "string" then
if type( func_name ) == "string" then
if not HF.isempty( func_name ) then
if not HF.isempty( func_name ) then
if type( Infobox[func_name] ) == "function" then
if type( Infobox[func_name] ) == "function" then
return Infobox[func_name]( field, vars )
return Infobox[func_name]( field, vars, value ) --[[ I tried a hack where I modified field.Value to little success, so I resorted to calling it with different arguments --]]
end
end
end
end
end
end
return default
return value
end
end


function Infobox.SplitLabelMethod( field, vars )
function Infobox.SplitTest( field, vars, value )
return "abc" + value + "cba"
end

function Infobox.ExampleSplitLabelMethod( field, vars )
return {
return {
SplitRunFunction( field.LabelLeftMethod, field.LabelLeft, field, vars ),
SplitRunFunction( field.LabelLeftMethod, field, vars, field.LabelLeft ),
SplitRunFunction( field.LabelRightMethod, field.LabelRight, field, vars )
SplitRunFunction( field.LabelRightMethod, field, vars, field.LabelRight )
}
}
end
end
function Infobox.SplitValueMethod( field, vars )
function Infobox.ExampleSplitValueMethod( field, vars )
field.Value = ValueLeft --[[ A bit hacky, but it's about to be replaced by this function's output anyways, and if it works, then we don't need special functions for Splits ]]--
local ValueLeft = SplitRunFunction( field.ValueLeftMethod, field.Value, field, vars )
field.Value = ValueRight
local ValueRight = SplitRunFunction( field.ValueRightMethod, field.ValueRight, field, vars )
⚫
return {
return {
ValueLeft,
SplitRunFunction( field.ValueLeftMethod, field, vars, field.ValueLeft ),
ValueRight
SplitRunFunction( field.ValueRightMethod, field, vars, field.ValueRight )
}
}
end
end

--[[ Carbon copy of Infobox.Newline lazily modified to for Split fields --]]
function SplitNewlineHelper( value )
local output = ''
if not HF.isempty(value) then
local ships = HF.explode(';', value)
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
end
end

function InfoBox.SplitNewline( field, vars )
return {
SplitNewlineHelper( field.ValueLeft ),
SplitNewlineHelper( field.ValueRight )
⚫
}
end



return Infobox
return Infobox

Revision as of 03:48, 11 December 2015

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

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

function Infobox.Newline( field, vars )
    local output = ''
    if not HF.isempty(field.Value) then
        local ships = HF.explode(';', field.Value)
        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.PreTitleIcon( field, vars )
    output = field.Value
    if not HF.isempty(field.Grade) then
        if field.Grade == 'Rare' or field.Grade == 'rare' then
            output = '[[File:placeholder.png|35px|link=]] ' .. output
        elseif field.Grade == 'Very common' or field.Grade == 'Very Common' or field.Grade == 'very common' then
            output = '[[File:placeholder.png|35px|link=]] ' .. output
        elseif field.Grade == 'Common' or field.Grade == 'common' then
            output = '[[File:placeholder.png|35px|link=]] ' .. output
        else
            output = output
        end
    end
    return output
end

--[[ Everything after this is stuff you may or may not want to keep --]]
function SplitRunFunction(func_name, field, vars, value)
    if type( func_name ) == "string" then
        if not HF.isempty( func_name ) then
            if type( Infobox[func_name] ) == "function" then
                return Infobox[func_name]( field, vars, value ) --[[ I tried a hack where I modified field.Value to little success, so I resorted to calling it with different arguments --]]
            end
        end
    end
    return value
end

function Infobox.SplitTest( field, vars, value )
    return "abc" + value + "cba"
end

function Infobox.ExampleSplitLabelMethod( field, vars )
    return {
        SplitRunFunction( field.LabelLeftMethod, field, vars, field.LabelLeft ),
        SplitRunFunction( field.LabelRightMethod, field, vars, field.LabelRight )
    }
end
function Infobox.ExampleSplitValueMethod( field, vars )
    return {
        SplitRunFunction( field.ValueLeftMethod, field, vars, field.ValueLeft ),
        SplitRunFunction( field.ValueRightMethod, field, vars, field.ValueRight )
    }
end

--[[ Carbon copy of Infobox.Newline lazily modified to for Split fields --]]
function SplitNewlineHelper( value )
    local output = ''
    if not HF.isempty(value) then
        local ships = HF.explode(';', value)
        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
    end
end

function InfoBox.SplitNewline( field, vars )
    return {
        SplitNewlineHelper( field.ValueLeft ),
        SplitNewlineHelper( field.ValueRight )
    }
end 


return Infobox